Labels BorderStyle is not a member of system.windows.forms.control

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mgawelek
    New Member
    • Apr 2008
    • 6

    Labels BorderStyle is not a member of system.windows.forms.control

    I am doing this in vb.net 2K5 The code below is in a module trying to edit the main form's label control. The error message is: BorderStyle is not a member of System.Windows. Forms.Control.
    When it is able to be set in the property window and you can do
    Label1.BorderSt yle = BorderStyle.Non e in the Form's Code.
    Can anyone help with this?
    Code:
    For Each ctrl As Control In Form.Controls
     ctrl.BorderStyle = BorderStyle.None
    Next
  • jg007
    Contributor
    • Mar 2008
    • 283

    #2
    [QUOTE=mgawelek]I am doing this in vb.net 2K5 The code below is in a module trying to edit the main form's label control. The error message is: BorderStyle is not a member of System.Windows. Forms.Control.
    When it is able to be set in the property window and you can do
    Label1.BorderSt yle = BorderStyle.Non e in the Form's Code.
    Can anyone help with this?

    took a couple of posts and it is not perfect coding as I had to redo it to only select labels as my first try did not have any other controls so threw an error when I added a button :)

    Code:
    Public Class Form1
    
        Dim ctrl
        Dim controltype As System.Type ' had to filter for only labels 
    
    
    
    
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            For Each ctrl In Me.Controls
    
    ' get type of control
    
                controltype = ctrl.GetType 
    
    ' only change ones that are labels
    
                If controltype.ToString = "System.Windows.Forms.Label" Then
    
                    ctrl.BorderStyle = BorderStyle.Fixed3D
                    ctrl.Text = "hello"
    
                End If
    
            Next
    
        End Sub
    End Class
    Last edited by jg007; Apr 2 '08, 07:11 PM. Reason: had to add text to only select labels

    Comment

    • mgawelek
      New Member
      • Apr 2008
      • 6

      #3
      Here is how I fixed it

      Comment

      • mgawelek
        New Member
        • Apr 2008
        • 6

        #4
        I will give that a try to see it it works and let you know.

        Originally posted by jg007
        This code worked fine fior me, left the hello in as I wanted to confirm it worked :)

        Code:
        Public Class Form1
        
               Dim ctrl As System.Windows.Forms.Label
        
        
        
            Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        
                For Each ctrl In Me.Controls
        
                    ctrl.BorderStyle = BorderStyle.Fixed3D
                    ctrl.text = "hello"
        
                Next
        
        
        
        
            End Sub
        End Class

        Comment

        • mgawelek
          New Member
          • Apr 2008
          • 6

          #5
          jg007 that will not work for me because I have buttons in the form too.

          Comment

          • jg007
            Contributor
            • Mar 2008
            • 283

            #6
            Originally posted by mgawelek
            jg007 that will not work for me because I have buttons in the form too.
            LOL!!!, look at the post again!

            Comment

            • mgawelek
              New Member
              • Apr 2008
              • 6

              #7
              Originally posted by jg007
              LOL!!!, look at the post again!

              I see sorry they are pretty much the same. Thanks jg007!

              Comment

              Working...