call sub with e

B

Ben

Hi there
I found the following sub in msdn that draws an icon in the first column in
a listview row. The problem is I have no idea how "e" works and I have to
pass it to this sub below:

Public Sub DrawIconRectangle(ByVal e As PaintEventArgs)

Dim newIcon As New Icon("SampIcon.ico")

Dim rect As New Rectangle(0, 0, 16, 16)

e.Graphics.DrawIcon(newIcon, rect)

End Sub

So what do I put as the argument when calling DrawIconRectangle(argument) ?

I am calling DrawIconRectangle from another sub
Thanks
 
M

Michael C

Ben said:
Hi there
I found the following sub in msdn that draws an icon in the first column
in
a listview row. The problem is I have no idea how "e" works and I have to
pass it to this sub below:

Public Sub DrawIconRectangle(ByVal e As PaintEventArgs)

Dim newIcon As New Icon("SampIcon.ico")

Dim rect As New Rectangle(0, 0, 16, 16)

e.Graphics.DrawIcon(newIcon, rect)

End Sub

So what do I put as the argument when calling DrawIconRectangle(argument)
?

I am calling DrawIconRectangle from another sub

You need to call DrawIconRectangle from the paint event. Then you will be
passed an 'e'. If you need another sub to update the icon then have that
other sub call ListView.Invalidate() or ListView.Refresh()

Michael
 
R

rowe_newsgroups

Hi there
I found the following sub in msdn that draws an icon in the first column in
a listview row. The problem is I have no idea how "e" works and I have to
pass it to this sub below:

Public Sub DrawIconRectangle(ByVal e As PaintEventArgs)

Dim newIcon As New Icon("SampIcon.ico")

Dim rect As New Rectangle(0, 0, 16, 16)

e.Graphics.DrawIcon(newIcon, rect)

End Sub

So what do I put as the argument when calling DrawIconRectangle(argument) ?

I am calling DrawIconRectangle from another sub
Thanks

Like Michael has stated, painting needs to be done from the Paint
event whenever possible, that way you can get ahold of the Graphics
object. Another option is to use <Object>.CreateGraphics, but it can
have some major drawbacks, but would allow you to write a method
without worrying about 'e'.

Thanks,

Seth Rowe [MVP]
 
B

Ben

rowe_newsgroups said:
Like Michael has stated, painting needs to be done from the Paint
event whenever possible, that way you can get ahold of the Graphics
object. Another option is to use <Object>.CreateGraphics, but it can
have some major drawbacks, but would allow you to write a method
without worrying about 'e'.

Thanks,

Seth Rowe [MVP]
Ok. I still do not get it.
How do I call the sub from the form's paint event and get it to draw inside
the listview rows?
Since different icon goes in different rows do I pass the icon?
Should the sub reference the listview in some way?
Thanks
 
A

Armin Zingler

Ben said:
Ok. I still do not get it.
How do I call the sub from the form's paint event and get it to draw
inside
the listview rows?
Since different icon goes in different rows do I pass the icon?
Should the sub reference the listview in some way?
Thanks

Do you have a link? The code I found on MSDN didn't refer to painting
the first column of a listview row as you mentioned. For example here
http://msdn2.microsoft.com/en-us/library/d6s01xzx(vs.80).aspx it is
mentioned that the sub can be called from within the Form's paint event.
So, you're problem is how to do user defined painting of a Listview,
right? In this case, you have to handle the Listview's DrawItem event.
The handler has two arguments. The second is called 'e' and points to a
DrawListViewItemEventArgs object. It has a .Graphics property. The sub
DrawIconRectangle as such is not usable with it because it expects a
different object as an argument. You could change it like this (mind the
changed argument type):

Public Sub DrawIconRectangle(ByVal e As DrawListViewItemEventArgs)

Dim newIcon As New Icon("SampIcon.ico")

Dim rect As New Rectangle(0, 0, 16, 16)

e.Graphics.DrawIcon(newIcon, rect)

End Sub

Drawing a Listview's item is different from drawing a Control because
you don't respond to the Paint event where you were able to call the sub
you posted.


Armin
 
R

rowe_newsgroups

Ok. I still do not get it.

No problem, I'll try to help you out.
How do I call the sub from the form's paint event and get it to draw inside
the listview rows?

Public Sub Paint(sender as object, e as PaintEventArgs)
DrawIconRectangle(e)
End Sub
Since different icon goes in different rows do I pass the icon?

I would assume you would have to, unless there is a way to determine
what icon is needed from the method itself.
Should the sub reference the listview in some way?

I would assume it would have to, so that it knows where to draw the
icon.

Thanks,

Seth Rowe [MVP]
 
F

Family Tree Mike

Armin Zingler said:
So, you're problem is how to do user defined painting of a Listview,
right? In this case, you have to handle the Listview's DrawItem event.
The handler has two arguments. The second is called 'e' and points to a
DrawListViewItemEventArgs object. It has a .Graphics property. The sub
DrawIconRectangle as such is not usable with it because it expects a
different object as an argument. You could change it like this (mind the
changed argument type):

Public Sub DrawIconRectangle(ByVal e As DrawListViewItemEventArgs)

Dim newIcon As New Icon("SampIcon.ico")

Dim rect As New Rectangle(0, 0, 16, 16)

e.Graphics.DrawIcon(newIcon, rect)

End Sub

Drawing a Listview's item is different from drawing a Control because
you don't respond to the Paint event where you were able to call the sub
you posted.


Armin

Remember that you will need to change the controls "DrawMode" property, as
the default value (normal) won't raise this event, if I recall correctly. I
have mine changed to "OwnerDrawFixed".
 

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