Help for DRAWRECTANGLE

  • Thread starter Thread starter Cristian
  • Start date Start date
C

Cristian

Hi.
I've made so:

Imports System.Drawing
Imports System.Drawing.Drawing2D

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim GR As Graphics = Me.CreateGraphics

GR.DrawRectangle(Pens.Red, 100, 30, 150, 190)

End Sub

End Class

But when the program was executed I saw only the form!!
Please Help Me
Bye
Cris
 
Cristian said:
Hi.
I've made so:

Imports System.Drawing
Imports System.Drawing.Drawing2D

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles MyBase.Load

Dim GR As Graphics = Me.CreateGraphics

GR.DrawRectangle(Pens.Red, 100, 30, 150, 190)

End Sub

End Class

But when the program was executed I saw only the form!!


In Form_Load, the form is not visible yet. Painting on an invisible Form
does not makes sense. On the other side, you don't paint if it is visible.
To do this, handle the Paint event.

Background and basics:
http://msdn.microsoft.com/library/en-us/gdi/pantdraw_8alz.asp

http://msdn.microsoft.com/library/en-us/gdi/pantdraw_4k6d.asp

http://msdn.microsoft.com/library/en-us/gdi/pantdraw_1xd1.asp

(The Paint event is raised whenever the Form receives a WM_PAINT Message).


Armin
 
Hi,

Never draw in the forms load event it will be erased when the form
paints itself. Use the paint event instead.

Private Sub Form1_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles Me.Paint

Dim g As Graphics = e.Graphics

g.DrawRectangle(Pens.Red, 100, 30, 150, 190)

End Sub



Ken
 
Cristian said:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim GR As Graphics = Me.CreateGraphics

GR.DrawRectangle(Pens.Red, 100, 30, 150, 190)

End Sub

End Class

But when the program was executed I saw only the form!!

Add the code to your form's 'Paint' event handler:

\\\
e.Graphics.DrawRectangle(...)
///
 
NO!
OK! I've result.
It's WRONG that is not possible write on invisible form!!!
In ON_LOAD the form is already existent!!
Soo Thank.
Bye
 
Back
Top