drawing a rectangle in a form

  • Thread starter Thread starter reidarT
  • Start date Start date
R

reidarT

I try to draw a rectangle in a form on a buttons click event, The code is
Dim bitmap As New Bitmap("lysblaa.jpg")

Dim tBrush As New TextureBrush(bitmap)

Dim texturedPen As New Pen(tBrush, 30)

e.Graphics.DrawImage(bitmap, 0, 0, bitmap.Width, bitmap.Height)

e.Graphics.DrawEllipse(texturedPen, 100, 20, 200, 100)

I get an error on e.Graphics...

I have trie to set Imports System.Drawing.Design but it doesn't help

reidarT
 
reidarT said:
I try to draw a rectangle in a form on a buttons click event, The code is
Dim bitmap As New Bitmap("lysblaa.jpg")

Dim tBrush As New TextureBrush(bitmap)

Dim texturedPen As New Pen(tBrush, 30)

e.Graphics.DrawImage(bitmap, 0, 0, bitmap.Width, bitmap.Height)

e.Graphics.DrawEllipse(texturedPen, 100, 20, 200, 100)

I get an error on e.Graphics...

I have trie to set Imports System.Drawing.Design but it doesn't help


\\\
Private m_Button1Clicked As Boolean

Private Sub Button1_Click(...) Handles Button1.Click
m_Button1Clicked = True
Me.Invalidate(...)
End Sub

Private Sub Form_Paint(...) Handles MyBase.Paint
If m_Button1Clicked Then
...
e.Graphics.DrawImage(...)
...
End If
End Sub
///
 
I have tried to do like you suggested with this code

Private m_Button1Clicked As Boolean

Private Sub Button1_Click() Handles Button1.Click

m_Button1Clicked = True

Me.Invalidate()

End Sub

Private Sub Form_Paint() Handles MyBase.Paint

If m_Button1Clicked Then

e.Graphics.DrawImage("1.jpg")

End If

End Sub

but I get n error on Button1.click and e.graphics

reidarT
 
reidarT said:
Private Sub Button1_Click() Handles Button1.Click
[...]
Private Sub Form_Paint() Handles MyBase.Paint

The methods's signatures are wrong. I didn't include the complete parameter
list because I didn't test the code in the IDE. Instead I just used
ellipsis instead to simplify typing the post. I suggest to create handlers
for the button's 'Click' event and the form's 'Paint' event using the IDE by
selecing the object in the left dropdown list on top of the code editor and
then selecting the event in the combobox on the right hand side.
e.Graphics.DrawImage("1.jpg")

\\\
Private m_Image As Image = Image.FromFile("1.jpg")
....
Private Sub Form_Paint(...) Handles MyBase.Paint
e.Graphics.DrawImage(m_Image)
End Sub
///
 
Back
Top