Windows Develop Bookmark and Share   
 index > Windows Forms Designer > Painting Problem , That's is Wierd !!!!!!!!
 

Painting Problem , That's is Wierd !!!!!!!!

Hi. I have weird problem . I have a windows Form with no border( FormBorderStyle = None ; ) .

Then i draw Form border in Paint method as following : -

Code Block

Private Sub PaintBorder(ByVal sender As Object, ByVal e As PaintEventArgs)

Dim l_LeftTitle As Rectangle = New Rectangle(0, 0, (Me.Width / 2), 22)

Dim l_RightTitle As Rectangle = New Rectangle((Me.Width / 2), 0, (Me.Width / 2), 22)

Dim frmLGBL As LinearGradientBrush = New LinearGradientBrush(l_LeftTitle, Color.FromArgb(87, 148, 160), Color.FromArgb(209, 230, 243), LinearGradientMode.Horizontal)

Dim frmLGBR As LinearGradientBrush = New LinearGradientBrush(l_RightTitle, Color.FromArgb(209, 230, 243), Color.FromArgb(87, 148, 160), LinearGradientMode.Horizontal)

e.Graphics.FillRectangle(frmLGBR, l_RightTitle)

e.Graphics.FillRectangle(frmLGBL, l_LeftTitle)

End Sub

and it works will . But Problem is arises as following : -

the border rectangle has dark blue line between the two rectangles of the border when the Form has spacific width values such as Me.Width = 687, 354 .....

i don't know why this line drawn . I traced the code many times but all things are ok .

if any one know why this problem occures replay me please .

Pr.Wael  Monday, October 15, 2007 10:48 AM

Becuase you are using int values, you get the space in some cases (687 / 2 = 343 rather than 343.5).

Just change the types to RectangleF (work with floats):

float width = (float)(this.Width / 2.0);

RectangleF l_leftTitle = new RectangleF(0,0, width, 22);

RectangleF l_rightTitle = new RectangleF(width,0,width, 22);

Eli Gazit  Monday, October 15, 2007 4:29 PM

Hi . Thank you for your help sir , but problem still exist if the width of the form is Even Number (Me.Width = 354 ) ,

but after debuggingifound thatthe rightside rectangle draws this line as if it was a "border" and the color of the line is the (87, 148, 160) color

I have no suggestion for this .But i solved this problem by Add one and Subtract one from the rightside rectangle width

Code Block

Dim l_RightTitle As RectangleF = New RectangleF((l_RectangleWidth - 1), 0, (l_RectangleWidth + 1), 22)

thanks very much Sir .
Pr.Wael  Tuesday, October 16, 2007 2:18 PM

Becuase you are using int values, you get the space in some cases (687 / 2 = 343 rather than 343.5).

Just change the types to RectangleF (work with floats):

float width = (float)(this.Width / 2.0);

RectangleF l_leftTitle = new RectangleF(0,0, width, 22);

RectangleF l_rightTitle = new RectangleF(width,0,width, 22);

Eli Gazit  Monday, October 15, 2007 4:29 PM

Hi . Thank you for your help sir , but problem still exist if the width of the form is Even Number (Me.Width = 354 ) ,

but after debuggingifound thatthe rightside rectangle draws this line as if it was a "border" and the color of the line is the (87, 148, 160) color

I have no suggestion for this .But i solved this problem by Add one and Subtract one from the rightside rectangle width

Code Block

Dim l_RightTitle As RectangleF = New RectangleF((l_RectangleWidth - 1), 0, (l_RectangleWidth + 1), 22)

thanks very much Sir .
Pr.Wael  Tuesday, October 16, 2007 2:18 PM

You can use google to search for other answers

Custom Search

More Threads

• UndoEngine in standalone Designer
• Create property Datasource,DisplayMember,ValueMember same Combobox Control
• Forms crashing on open? Guard your timers.
• Password in PropertyGrid
• Custom user controls will not show up automatically on toolbox
• TYPE_E_LIBNOTREGISTERED
• Naming undo/redo action created by the well known GetPropertyByName
• Switching between parent and child forms
• OCR Component
• Use of Custom Editor at run time