Question about Drawing

  • Thread starter Thread starter MenuChen
  • Start date Start date
M

MenuChen

This Code doesn't work
************************
Protected Overrides Sub WndProc(ByRef m As Message)
MyBase.WndProc(m)
Dim myLine As Graphics =
System.Drawing.Graphics.FromHwnd(Me.Handle)
myLine.DrawLine(System.Drawing.Pens.Red, Me.Left,
(Me.Top + Me.Height) \ 2, Me.Left + Me.Width, (Me.Top +
Me.Height) \ 2)

End Sub
************************
I put it in my Controls who inherits .NET's TextBox
controls,I want it to Draw a Red Line on the Rewrited
TextBox.
Who can help me ?thanks a lot...
Best Regards
 
MenuChen said:
This Code doesn't work
************************
Protected Overrides Sub WndProc(ByRef m As Message)
MyBase.WndProc(m)
Dim myLine As Graphics =
System.Drawing.Graphics.FromHwnd(Me.Handle)
myLine.DrawLine(System.Drawing.Pens.Red, Me.Left,
(Me.Top + Me.Height) \ 2, Me.Left + Me.Width, (Me.Top +
Me.Height) \ 2)

End Sub
************************
I put it in my Controls who inherits .NET's TextBox
controls,I want it to Draw a Red Line on the Rewrited
TextBox.
Who can help me ?thanks a lot...
Best Regards

WndProc is rather low-level, I guess... Why not overide the OnPaint
procedure? Apart from this, outside OnPaint, you'd better create the
graphics object by calling the CreateGraphics function of the control
(me.CreateGraphics). Inside OnPaint, you get the graphics object passed in
e.graphics. In addition, you should call the Graphics objects' Dispose
method after drawing has been done (do _not_ call it in OnPaint). Further
more, the values passed to drawline must be in "control space" (what is it
called in the 2D world?), i.e. the top/left corner is (0/0), not
(me.left,me.top).
 
* "MenuChen said:
This Code doesn't work
************************
Protected Overrides Sub WndProc(ByRef m As Message)
MyBase.WndProc(m)
Dim myLine As Graphics =
System.Drawing.Graphics.FromHwnd(Me.Handle)
myLine.DrawLine(System.Drawing.Pens.Red, Me.Left,
(Me.Top + Me.Height) \ 2, Me.Left + Me.Width, (Me.Top +
Me.Height) \ 2)
\\\
myLine.Dispose()
///

End Sub
************************
I put it in my Controls who inherits .NET's TextBox
controls,I want it to Draw a Red Line on the Rewrited
TextBox.

The code doesn't make sense. You may want to draw the text only if
specific messages occur.
 
Back
Top