drawing a rectangle in a form

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • reidarT

    drawing a rectangle in a form

    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(bi tmap)

    Dim texturedPen As New Pen(tBrush, 30)

    e.Graphics.Draw Image(bitmap, 0, 0, bitmap.Width, bitmap.Height)

    e.Graphics.Draw Ellipse(texture dPen, 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


  • Herfried K. Wagner [MVP]

    #2
    Re: drawing a rectangle in a form

    "reidarT" <reidar@eivon.n oschrieb:
    >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(bi tmap)
    >
    Dim texturedPen As New Pen(tBrush, 30)
    >
    e.Graphics.Draw Image(bitmap, 0, 0, bitmap.Width, bitmap.Height)
    >
    e.Graphics.Draw Ellipse(texture dPen, 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_Button1Clicke d As Boolean

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

    Private Sub Form_Paint(...) Handles MyBase.Paint
    If m_Button1Clicke d Then
    ...
    e.Graphics.Draw Image(...)
    ...
    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/>

    Comment

    • reidarT

      #3
      Re: drawing a rectangle in a form

      I have tried to do like you suggested with this code

      Private m_Button1Clicke d As Boolean

      Private Sub Button1_Click() Handles Button1.Click

      m_Button1Clicke d = True

      Me.Invalidate()

      End Sub

      Private Sub Form_Paint() Handles MyBase.Paint

      If m_Button1Clicke d Then

      e.Graphics.Draw Image("1.jpg")

      End If

      End Sub

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

      reidarT


      "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.atskre v i melding
      news:ek1scPf0GH A.2196@TK2MSFTN GP03.phx.gbl...
      "reidarT" <reidar@eivon.n oschrieb:
      >>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(bi tmap)
      >>
      >Dim texturedPen As New Pen(tBrush, 30)
      >>
      >e.Graphics.Dra wImage(bitmap, 0, 0, bitmap.Width, bitmap.Height)
      >>
      >e.Graphics.Dra wEllipse(textur edPen, 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_Button1Clicke d As Boolean
      >
      Private Sub Button1_Click(. ..) Handles Button1.Click
      m_Button1Clicke d = True
      Me.Invalidate(. ..)
      End Sub
      >
      Private Sub Form_Paint(...) Handles MyBase.Paint
      If m_Button1Clicke d Then
      ...
      e.Graphics.Draw Image(...)
      ...
      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/>

      Comment

      • Herfried K. Wagner [MVP]

        #4
        Re: drawing a rectangle in a form

        "reidarT" <reidar@eivon.n oschrieb:
        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.Draw Image("1.jpg")
        \\\
        Private m_Image As Image = Image.FromFile( "1.jpg")
        ....
        Private Sub Form_Paint(...) Handles MyBase.Paint
        e.Graphics.Draw Image(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/>

        Comment

        Working...