none
vb.net 2k5 Labels BorderStyle is not a member of system.windows.forms.control RRS feed

  • Question

  •  

    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.BorderStyle = BorderStyle.None in the Form's Code.
    Can anyone help with this?

     

    For Each ctrl As Control In Form.Controls

         ctrl.BorderStyle = BorderStyle.None

    Next

    Wednesday, April 2, 2008 6:02 PM

Answers

  • BorderStyle is not a property of the Control class. The controls that have it do so because they inherit from ScrollableControl I believe. So what you could do is something like this:

     

    For Each ctrl as Control in Form.Controls

    try

    dim sc as ScrollableControl = DirectCast(ctrl, ScrollableControl)

    sc.BorderStyle = BorderStyle.None

    catch

    //Do nothing. Control is not a scrollable control

    end Try

    Next

     

    Not the most elegant, but it works.

    Wednesday, April 2, 2008 6:12 PM

All replies

  • BorderStyle is not a property of the Control class. The controls that have it do so because they inherit from ScrollableControl I believe. So what you could do is something like this:

     

    For Each ctrl as Control in Form.Controls

    try

    dim sc as ScrollableControl = DirectCast(ctrl, ScrollableControl)

    sc.BorderStyle = BorderStyle.None

    catch

    //Do nothing. Control is not a scrollable control

    end Try

    Next

     

    Not the most elegant, but it works.

    Wednesday, April 2, 2008 6:12 PM
  • I get the same error message but now the error is for ScrollableControl.
    So that did not work.
    Wednesday, April 2, 2008 6:22 PM
  • This Worked!

    Try
        Dim sc As System.Windows.Forms.Label = DirectCast(ctrl, System.Windows.Forms.Label)
        sc.BorderStyle = myBorderStyle
        'ctrl.borderstyle = 0
    Catch
        'Do nothing. Control is not a scrollable control
    End Try

    So I will mark yours as answered!

    Thanks
    Wednesday, April 2, 2008 6:43 PM
  • And actually with a little more checking, my orginal idea doesn't work because BorderStyle is not an inherited property anwhere that I can see. It's a specific implementation on each control.

     

    Wednesday, April 2, 2008 6:49 PM