Making custom borders

mariano_donati

Active member
Joined
Nov 30, 2005
Messages
41
Programming Experience
Beginner
Hi everybody in this forum, i'm making my own controls's custom borders, but i'm in trouble right now. When i paint custom borders, the text of the controls just dissappears, and if i highlight control, text appears again, but with an arbitrary font type and no borders anymore. So, i'd like to know why happens that, and a solution for this. I know about DrawString method of graphics object, but if i use that method to show a string, there a lot of things more that i need to handle i.e. text alignment. And i just want to make my own custom borders, that means that if there's a way that allows me to avoid doing a task that is not related to the main task (to make the borders), then i'd really like to know it.
I hope you can understand me what i meant.
Regards!.
 
VB.NET:
[SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Protected[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Overrides[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] OnPaint([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Windows.Forms.PaintEventArgs)[/SIZE]
[SIZE=2]SetProperties()
[/SIZE][SIZE=2][COLOR=#0000ff]Select[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Case[/COLOR][/SIZE][SIZE=2] _BorderStyle
[/SIZE][SIZE=2][COLOR=#0000ff]Case[/COLOR][/SIZE][SIZE=2] Border.All
PaintTopBorder(e.Graphics)
PaintBottomBorder(e.Graphics)
PaintLeftBorder(e.Graphics)
PaintRightBorder(e.Graphics)
[/SIZE][SIZE=2][COLOR=#0000ff]Case[/COLOR][/SIZE][SIZE=2] Border.BottomOnly
PaintBottomBorder(e.Graphics)
[/SIZE][SIZE=2][COLOR=#0000ff]Case[/COLOR][/SIZE][SIZE=2] Border.VSides
PaintLeftBorder(e.Graphics)
PaintRightBorder(e.Graphics)
[/SIZE][SIZE=2][COLOR=#0000ff]Case[/COLOR][/SIZE][SIZE=2] Border.LeftBottomCorner
PaintLeftBorder(e.Graphics)
PaintBottomBorder(e.Graphics)
[/SIZE][SIZE=2][COLOR=#0000ff]Case[/COLOR][/SIZE][SIZE=2] Border.LeftOnly
PaintLeftBorder(e.Graphics)
[/SIZE][SIZE=2][COLOR=#0000ff]Case[/COLOR][/SIZE][SIZE=2] Border.LeftTopCorner
PaintLeftBorder(e.Graphics)
PaintTopBorder(e.Graphics)
[/SIZE][SIZE=2][COLOR=#0000ff]Case[/COLOR][/SIZE][SIZE=2] Border.RightBottomCorner
PaintRightBorder(e.Graphics)
PaintBottomBorder(e.Graphics)
[/SIZE][SIZE=2][COLOR=#0000ff]Case[/COLOR][/SIZE][SIZE=2] Border.RightOnly
PaintRightBorder(e.Graphics)
[/SIZE][SIZE=2][COLOR=#0000ff]Case[/COLOR][/SIZE][SIZE=2] Border.RightTopCorner
PaintRightBorder(e.Graphics)
PaintTopBorder(e.Graphics)
[/SIZE][SIZE=2][COLOR=#0000ff]Case[/COLOR][/SIZE][SIZE=2] Border.TopOnly
PaintTopBorder(e.Graphics)
[/SIZE][SIZE=2][COLOR=#0000ff]Case[/COLOR][/SIZE][SIZE=2] Border.HSides
PaintTopBorder(e.Graphics)
PaintBottomBorder(e.Graphics)
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Select
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]
[/COLOR][/SIZE]

I made a class wich inherits from textbox. What i do is to replace OnPaint method and use graphics object from PaintEventArgs. PaintXXXBorder they all are subs for drawing border's line. SetProperties sub, allows me to set width, height, and other vars to draw borders.

 
mariano_donati:
VB.NET:
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
   MyBase.OnPaint(e)
 
   'then add you custom paints   
End Sub
 
probably doing something in your other methods causing it..
 
This what i do:

Private Sub PaintBottomBorder(ByVal g As Graphics)
g.DrawLine(_Pen, _x - 1, _y + _height - 1, _x + _width - 1, _y + _height - 1)
End Sub

Other subs are similar to it.
 
Back
Top