Home All Groups Group Topic Archive Search About

drawing a rectangle in a form

Author
6 Sep 2006 8:13 PM
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

Author
6 Sep 2006 8:34 PM
Herfried K. Wagner [MVP]
Show quote Hide quote
"reidarT" <rei***@eivon.no> schrieb:
>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
///

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://dotnet.mvps.org/dotnet/faqs/>
Author
7 Sep 2006 8:26 PM
reidarT
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


Show quoteHide quote
"Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> skrev i melding
news:ek1scPf0GHA.2196@TK2MSFTNGP03.phx.gbl...
> "reidarT" <rei***@eivon.no> schrieb:
>>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
> ///
>
> --
> M S   Herfried K. Wagner
> M V P  <URL:http://dotnet.mvps.org/>
> V B   <URL:http://dotnet.mvps.org/dotnet/faqs/>
Author
7 Sep 2006 10:19 PM
Herfried K. Wagner [MVP]
"reidarT" <rei***@eivon.no> schrieb:
> 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
///

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://dotnet.mvps.org/dotnet/faqs/>