7 Replies - 261 Views - Last Post: 16 February 2013 - 07:20 PM Rate Topic: -----

#1 Jondeate  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 56
  • Joined: 03-February 13

Painting on Form from Class

Posted 16 February 2013 - 04:38 PM

I am trying to use the paint event on my game.
Basically, i want to use the paint event of any given form to paint anything at any time.
I tried adding a handler to the form like:

Addhandler FormName.Paint, AddressOf Paintsub




But it wont work properly.

This post has been edited by Jondeate: 16 February 2013 - 04:39 PM

Is This A Good Question/Topic? 0
  • +

Replies To: Painting on Form from Class

#2 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1030
  • View blog
  • Posts: 4,008
  • Joined: 02-July 08

Re: Painting on Form from Class

Posted 16 February 2013 - 04:44 PM

Can you show us the Paintsub routine? Where are you adding this handler?
Was This Post Helpful? 0
  • +
  • -

#3 Jondeate  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 56
  • Joined: 03-February 13

Re: Painting on Form from Class

Posted 16 February 2013 - 05:05 PM

Paintsub would contain the code that would be in form1 paint event.
That would be

   Dim imgBmp As New Bitmap(Imagehere.)
        imgBmp.MakeTransparent(Color.white)
        e.Graphics.DrawImage(New Bitmap(imgBmp), 15, 20)



im adding the handler inside of a class function.

This post has been edited by Jondeate: 16 February 2013 - 05:05 PM

Was This Post Helpful? 0
  • +
  • -

#4 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1030
  • View blog
  • Posts: 4,008
  • Joined: 02-July 08

Re: Painting on Form from Class

Posted 16 February 2013 - 05:24 PM

What class function? Are you sure this Addhandler is getting called? I am still confused, what is not working?
Was This Post Helpful? 0
  • +
  • -

#5 Jondeate  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 56
  • Joined: 03-February 13

Re: Painting on Form from Class

Posted 16 February 2013 - 05:29 PM

Here i made an example.
Public Class Class1
    Sub Image(ByVal formname As Form)
        AddHandler formname.Paint, AddressOf paintsub
    End Sub

    Sub paintsub()
        Dim imgBmp As New Bitmap(My.Resources.bandera)
        imgBmp.MakeTransparent(Color.White)
        e.Graphics.DrawImage(New Bitmap(imgBmp), 15, 20)
    End Sub
End Class


Error says e is not declared. i thought adding a handler would perform any actions as if it was done in the form paint event.
Was This Post Helpful? 0
  • +
  • -

#6 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1030
  • View blog
  • Posts: 4,008
  • Joined: 02-July 08

Re: Painting on Form from Class

Posted 16 February 2013 - 06:49 PM

The paint event has a signature (sender As Object, e As PaintEventArgs). This just seems like a strange way to do this.
Was This Post Helpful? 1
  • +
  • -

#7 Jondeate  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 56
  • Joined: 03-February 13

Re: Painting on Form from Class

Posted 16 February 2013 - 07:12 PM

So i should put that into the sub?
Public Class Class1
    Sub Image(ByVal formname As Form)
        AddHandler formname.Paint, AddressOf paintsub
    End Sub

    Sub paintsub(sender As Object, e As PaintEventArgs)
        Dim imgBmp As New Bitmap(My.Resources.bandera)
        imgBmp.MakeTransparent(Color.White)
        e.Graphics.DrawImage(New Bitmap(imgBmp), 15, 20)
    End Sub
End Class


Was This Post Helpful? 0
  • +
  • -

#8 Jondeate  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 56
  • Joined: 03-February 13

Re: Painting on Form from Class

Posted 16 February 2013 - 07:20 PM

Well that just solved my problem.
I trully love you man.
/jk

Regards.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1