none
How to change border style in panel RRS feed

  • Question

  • Hi, is anybody knows how to change border color on panel. There is no option in propertis, and Idon't know how to write a code.

    I am using VB 2010. 

    Sunday, April 10, 2011 8:30 PM

Answers

  • Deleted
    • Marked as answer by uvisruke Monday, April 11, 2011 5:09 PM
    Monday, April 11, 2011 1:02 PM
  • Thank you and sorry for late reply. I will try something with that although this border doesn't look so fine like border on textbox. I really don't know why Microsoft didn't give option in properties... Well apparently you can't get everything for free :-) 

    Hi again uvisruke,

     

    How about this for FREE ? >>

    I guess you want a Panel with options for BorderColor and BorderWidth in properties?

    If so proceed as follows please.

     

    1) From the PROJECT menu select ADD CLASS...

    2) Type in the NAME box MyPanel.Vb and then click on ADD

    3) PASTE all of the following code in.>>

     

     

    Public Class MyPanel
      Inherits System.Windows.Forms.Panel
    
      Public Sub New()
        Me.BorderStyle = Windows.Forms.BorderStyle.None
      End Sub
    
      Private bWidth As Integer
      Public Property BorderWidth() As Integer
        Get
          Return Me.bWidth
        End Get
        Set(ByVal value As Integer)
          Me.bWidth = Math.Abs(value)
          Me.Refresh()
        End Set
      End Property
    
      Private bColor As Color
      Public Property BorderColor() As Color
        Get
          Return Me.bColor
        End Get
        Set(ByVal value As Color)
          Me.bColor = value
          Me.Refresh()
        End Set
      End Property
    
      Public Overridable Sub MyPanel_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
    
        e.Graphics.DrawRectangle(New Pen(Me.bColor, Me.bWidth), Me.ClientRectangle)
    
      End Sub
    End Class
    

     

     

    4) Select the first item in the BUILD menu.

    5) You should now see MyPanel

    in your ToolBox. Add one to your Form and you can now set the BorderColor and BorderWidth

    in the PROPERTIES window.

     

    Enjoy!!

     



    Regards,

    John

    Click this link to see how to insert a picture into a forum post.

    Installing VB6 on Windows 7
    • Marked as answer by uvisruke Tuesday, April 12, 2011 8:25 AM
    Monday, April 11, 2011 11:11 PM

All replies

  • Hi,

    Try the follwing with 1 Panel on a Form please.

    The number 12 in this code is the width of the pen in pixels, use a smaller number if you want a narrower border.

    Public Class Form1
    
      Private Sub Panel1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint
    
        Panel1.BorderStyle = BorderStyle.FixedSingle
        e.Graphics.DrawRectangle(New Pen(Color.Blue, 12), Panel1.ClientRectangle)
    
      End Sub
    End Class
    

     



    Regards,

    John

    Click this link to see how to insert a picture into a forum post.

    Installing VB6 on Windows 7
    • Proposed as answer by Cor Ligthert Monday, April 11, 2011 6:22 AM
    Monday, April 11, 2011 12:23 AM
  • Thank you Cor and John :-). Cor, I doesn't look nice with groupbox, when I eneter a color in it, it goes out of a border, and to tell you the truth I don't see wher can I change the color of border :-(

    For John: Why can I remove the black border, or how can I change the color of black border in panle1?

    Monday, April 11, 2011 8:28 AM
  • Hi UvisRuke,

    Sorry, I thought that border was a property of control but it is not, as addition to John his answer try to change this one in John his answer 

     

     e.Graphics.DrawRectangle(New Pen(Color.Blue, 12), Panel1.ClientRectangle, Panel1.Size)
    

     


    Success
    Cor
    Monday, April 11, 2011 9:19 AM
  • Deleted
    • Marked as answer by uvisruke Monday, April 11, 2011 5:09 PM
    Monday, April 11, 2011 1:02 PM
  • Hi UvisRuke,

    Sorry, I thought that border was a property of control but it is not, as addition to John his answer try to change this one in John his answer 

     

     e.Graphics.DrawRectangle(New Pen(Color.Blue, 12), Panel1.ClientRectangle, Panel1.Size)
    

     


    Success
    Cor

    Hi Cor,

    That line of code will NOT work in the Paint event.

    I tried this:>>


    e.Graphics.DrawRectangle(New Pen(Color.Blue, 12), New Rectangle(0, 0, Panel1.Width, Panel1.Height))

     

    But the result looks better with:>>

    e.Graphics.DrawRectangle(New Pen(Color.Blue, 12), Panel1.ClientRectangle)



    Regards,

    John

    Click this link to see how to insert a picture into a forum post.

    Installing VB6 on Windows 7

    Monday, April 11, 2011 3:42 PM
  • Thank you and sorry for late reply. I will try something with that although this border doesn't look so fine like border on textbox. I really don't know why Microsoft didn't give option in properties... Well apparently you can't get everything for free :-) 
    Monday, April 11, 2011 5:09 PM
  • Thank you and sorry for late reply. I will try something with that although this border doesn't look so fine like border on textbox. I really don't know why Microsoft didn't give option in properties... Well apparently you can't get everything for free :-) 

    Hi again uvisruke,

     

    How about this for FREE ? >>

    I guess you want a Panel with options for BorderColor and BorderWidth in properties?

    If so proceed as follows please.

     

    1) From the PROJECT menu select ADD CLASS...

    2) Type in the NAME box MyPanel.Vb and then click on ADD

    3) PASTE all of the following code in.>>

     

     

    Public Class MyPanel
      Inherits System.Windows.Forms.Panel
    
      Public Sub New()
        Me.BorderStyle = Windows.Forms.BorderStyle.None
      End Sub
    
      Private bWidth As Integer
      Public Property BorderWidth() As Integer
        Get
          Return Me.bWidth
        End Get
        Set(ByVal value As Integer)
          Me.bWidth = Math.Abs(value)
          Me.Refresh()
        End Set
      End Property
    
      Private bColor As Color
      Public Property BorderColor() As Color
        Get
          Return Me.bColor
        End Get
        Set(ByVal value As Color)
          Me.bColor = value
          Me.Refresh()
        End Set
      End Property
    
      Public Overridable Sub MyPanel_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
    
        e.Graphics.DrawRectangle(New Pen(Me.bColor, Me.bWidth), Me.ClientRectangle)
    
      End Sub
    End Class
    

     

     

    4) Select the first item in the BUILD menu.

    5) You should now see MyPanel

    in your ToolBox. Add one to your Form and you can now set the BorderColor and BorderWidth

    in the PROPERTIES window.

     

    Enjoy!!

     



    Regards,

    John

    Click this link to see how to insert a picture into a forum post.

    Installing VB6 on Windows 7
    • Marked as answer by uvisruke Tuesday, April 12, 2011 8:25 AM
    Monday, April 11, 2011 11:11 PM
  • John, you are top class :-) no doubt... Excellent job... If you write a book on simple English like you are planing to do, it will be a bestseller. :-)

    Tuesday, April 12, 2011 8:25 AM
  • John, you are top class :-) no doubt... Excellent job... If you write a book on simple English like you are planing to do, it will be a bestseller. :-)

    Hi again uvisruke,

    Your welcome and thanks for the encouragement.    :-)    ;-)    :-D

    I have also been considering doing a VB.Net online book and provide it for FREE or for a very small-reasonable price.

    The online version would also include videos.

     

    I am considering summarising all of the VB.Net tips and tricks that I know first, that is, if I ever write a book.

     



    Regards,

    John

    Click this link to see how to insert a picture into a forum post.

    Installing VB6 on Windows 7



    Thursday, April 14, 2011 9:44 PM