Help for DRAWRECTANGLE

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
 
A

Armin Zingler

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
 
K

Ken Tucker [MVP]

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
 
H

Herfried K. Wagner [MVP]

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(...)
///
 
C

Cristian

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top