By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,110 Members | 990 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,110 IT Pros & Developers. It's quick & easy.

VB2005 pro Graphics

P: n/a
Going from VB6 (RAD) to VB2005 (SAD)

The documentation always shows graphics drawing in a paint event like

Private Sub Pictcolor_Paint(ByVal sender As Object, ByVal e _
As System.Windows.Forms.PaintEventArgs) Handles PictColor.Paint

End Sub

But my VB6 program draws to the picturebox PictColor from many different
subs.
Can I draw to PictColor directly from subs as follows:
Here I am drawing pixels

Dim h As Graphics, g As Graphics, p As New Pen(Color.Black)
'Draws the color squares
g = Me.PictColor.CreateGraphics
h = Me.picBW.CreateGraphics
For intNumber0 = 0 To 255
For intNumber1 = 0 To 255
p.Color = Color.FromArgb(intNumber0, 255 - intNumber1, 255 -
intNumber0)
g.DrawEllipse(p, intNumber1, intNumber0, 1, 1)
p.Color = Color.FromArgb(intNumber0, intNumber0, intNumber0)
h.DrawEllipse(p, intNumber1, intNumber0, 1, 1)
Next
Next

Here I am drawing lines

Dim Incr, Index As Short, g As Graphics, p As New Pen(Color.Black), c As
Color
g = Me.PictColor.CreateGraphics
c = Color.FromArgb(mlColors(0))
p.Color = c
Incr = 200 / 5
For Index = 0 To 5 Step 1
g.DrawLine(p, X1, Y1, X2, Y2)
X1 = X1 + Incr
If Index = 4 Then X1 = X1 - 1
X2 = X1
Next Index

Or do I have to make a cajillion different Paint events for PictColor ??

If I can do it outside of Paint events, can I declare the CreateGraphics
once after Form load ??
GalenS
Jan 30 '06 #1
Share this Question
Share on Google+
10 Replies


P: n/a
Galen Somerville wrote:
Going from VB6 (RAD) to VB2005 (SAD)

The documentation always shows graphics drawing in a paint event like

Private Sub Pictcolor_Paint(ByVal sender As Object, ByVal e _
As System.Windows.Forms.PaintEventArgs) Handles PictColor.Paint

End Sub

But my VB6 program draws to the picturebox PictColor from many different
subs.
Can I draw to PictColor directly from subs as follows:
Here I am drawing pixels

Dim h As Graphics, g As Graphics, p As New Pen(Color.Black)
'Draws the color squares
g = Me.PictColor.CreateGraphics
h = Me.picBW.CreateGraphics
For intNumber0 = 0 To 255
For intNumber1 = 0 To 255
p.Color = Color.FromArgb(intNumber0, 255 - intNumber1, 255 -
intNumber0)
g.DrawEllipse(p, intNumber1, intNumber0, 1, 1)
p.Color = Color.FromArgb(intNumber0, intNumber0, intNumber0)
h.DrawEllipse(p, intNumber1, intNumber0, 1, 1)
Next
Next

Here I am drawing lines

Dim Incr, Index As Short, g As Graphics, p As New Pen(Color.Black), c As
Color
g = Me.PictColor.CreateGraphics
c = Color.FromArgb(mlColors(0))
p.Color = c
Incr = 200 / 5
For Index = 0 To 5 Step 1
g.DrawLine(p, X1, Y1, X2, Y2)
X1 = X1 + Incr
If Index = 4 Then X1 = X1 - 1
X2 = X1
Next Index

Or do I have to make a cajillion different Paint events for PictColor ??

If I can do it outside of Paint events, can I declare the CreateGraphics
once after Form load ??
GalenS


The reason to do it in the paint method is that event gets called each
time the object needs to refresh. So if a window goes across your form
and it now needs to be repainted. How will you know when to repaint if
you don't capture the PictureBox.Paint event?

You can call a sub from inside the paint event and pass in the graphics
object.

Hope this helps
Chris
Jan 30 '06 #2

P: n/a

"Chris" <no@spam.com> wrote in message
news:Og**************@TK2MSFTNGP09.phx.gbl...
Galen Somerville wrote:
Going from VB6 (RAD) to VB2005 (SAD)

The documentation always shows graphics drawing in a paint event like

Private Sub Pictcolor_Paint(ByVal sender As Object, ByVal e _
As System.Windows.Forms.PaintEventArgs) Handles PictColor.Paint

End Sub

But my VB6 program draws to the picturebox PictColor from many different
subs.
Can I draw to PictColor directly from subs as follows:
Here I am drawing pixels

Dim h As Graphics, g As Graphics, p As New Pen(Color.Black)
'Draws the color squares
g = Me.PictColor.CreateGraphics
h = Me.picBW.CreateGraphics
For intNumber0 = 0 To 255
For intNumber1 = 0 To 255
p.Color = Color.FromArgb(intNumber0, 255 - intNumber1, 255 -
intNumber0)
g.DrawEllipse(p, intNumber1, intNumber0, 1, 1)
p.Color = Color.FromArgb(intNumber0, intNumber0, intNumber0)
h.DrawEllipse(p, intNumber1, intNumber0, 1, 1)
Next
Next

Here I am drawing lines

Dim Incr, Index As Short, g As Graphics, p As New Pen(Color.Black), c As
Color
g = Me.PictColor.CreateGraphics
c = Color.FromArgb(mlColors(0))
p.Color = c
Incr = 200 / 5
For Index = 0 To 5 Step 1
g.DrawLine(p, X1, Y1, X2, Y2)
X1 = X1 + Incr
If Index = 4 Then X1 = X1 - 1
X2 = X1
Next Index

Or do I have to make a cajillion different Paint events for PictColor ??

If I can do it outside of Paint events, can I declare the CreateGraphics
once after Form load ??
GalenS


The reason to do it in the paint method is that event gets called each
time the object needs to refresh. So if a window goes across your form
and it now needs to be repainted. How will you know when to repaint if
you don't capture the PictureBox.Paint event?

You can call a sub from inside the paint event and pass in the graphics
object.

Hope this helps
Chris


ouch. The current program displays Heart sounds in real time. That is it
sweeps across the screen like an oscilloscope with the new data replacing
the old data (with a 5 to 10 pixel gap)

They can freeze the screen to look at the current display. No other program
is allowed to usurp the screen.

Say they want to place a Marker (small vertical line) with the Latency in
milliseconds. The Mouse down, Mouse up and Mouse move displays the Marker
and latency and moves it across the waveform until they are happy with
placement.

Now they can add other Markers (up to six).

This was easy in VB6 but I just can't get it into my mind as to
accomplishing this in VB2005.

GalenS (if I were the other Galen, I would know)


Jan 30 '06 #3

P: n/a
"Galen Somerville" <ga***@SPAM.surewest.net> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...


This was easy in VB6 but I just can't get it into my mind as to
accomplishing this in VB2005.
I haven't even attempted drawing anything in .Net but..... can't you create
a sub that does the drawing and call that from "anywhere" plus the paint
event? Sounds like "the VB6 way" I know <g>
GalenS (if I were the other Galen, I would know)


Maybe you *are* the other Galen and no one told you? <g>

--
Ken Halter - MS-MVP-VB (visiting from VB6 world) - http://www.vbsight.com
Please keep all discussions in the groups..
Jan 30 '06 #4

P: n/a

"Ken Halter" <Ken_Halter@Use_Sparingly_Hotmail.com> wrote in message
news:e2****************@TK2MSFTNGP12.phx.gbl...
"Galen Somerville" <ga***@SPAM.surewest.net> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...


This was easy in VB6 but I just can't get it into my mind as to
accomplishing this in VB2005.


I haven't even attempted drawing anything in .Net but..... can't you
create a sub that does the drawing and call that from "anywhere" plus the
paint event? Sounds like "the VB6 way" I know <g>
GalenS (if I were the other Galen, I would know)


Maybe you *are* the other Galen and no one told you? <g>

--
Ken Halter - MS-MVP-VB (visiting from VB6 world) - http://www.vbsight.com
Please keep all discussions in the groups..

Last things first. In nosing around the net groups I saw a Galen and I think
he (she ?) was an MVP

In "the VB6 way" all of my drawing is in subs. Each sub ends by storing the
points and colors of what it just did.

Then, in those cases where I pop a listbox on top of the drawing, I take the
stored info and repaint (actually redraw) what I messed up.

That's why my question included, "can I do this drawing outside of the
picturebox paint event" and gave examples of what I proposed to do. No
answer yet.

I can't run the VB2005 version until I clear 102 errors and a whole slew of
warnings.

Galen S


Jan 31 '06 #5

P: n/a
CMM
First, I have oodles of experience drawing in VB.Classic and quite a bit in
..NET....NET drawing is great... though the x2/y2 pixel offsetting is
confusing sometimes (to me).

Let me guess.... you have AutoRedraw on your VB.Classic picture box set? If
not, what's the problem?
I don't really see it.... What's the problem with doing your drawing inside
the paint event?
Sub ... Paint(...)
DrawLines(g)
DrawSomethingElse(g)
End Sub

If you wanted to update the canvas (based on some changes in your numbers or
whatever that you'd maintain on the module class level) you'd simply call
..Refresh on the form or control in question.

Drawing in .NET is extremely extraordinarily fast (at least compared to
VB.Classic). Even if your Paint event is called a 30 times in a second you
would never really notice. If flashing becomes a problem turn on
DoubleBuffering.

Am I misunderstanding your intent somehow? If so, explain further and I'll
try to help.

"Galen Somerville" <ga***@SPAM.surewest.net> wrote in message
news:Og**************@TK2MSFTNGP10.phx.gbl...

"Ken Halter" <Ken_Halter@Use_Sparingly_Hotmail.com> wrote in message
news:e2****************@TK2MSFTNGP12.phx.gbl...
"Galen Somerville" <ga***@SPAM.surewest.net> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...


This was easy in VB6 but I just can't get it into my mind as to
accomplishing this in VB2005.


I haven't even attempted drawing anything in .Net but..... can't you
create a sub that does the drawing and call that from "anywhere" plus the
paint event? Sounds like "the VB6 way" I know <g>
GalenS (if I were the other Galen, I would know)


Maybe you *are* the other Galen and no one told you? <g>

--
Ken Halter - MS-MVP-VB (visiting from VB6 world) - http://www.vbsight.com
Please keep all discussions in the groups..

Last things first. In nosing around the net groups I saw a Galen and I
think he (she ?) was an MVP

In "the VB6 way" all of my drawing is in subs. Each sub ends by storing
the points and colors of what it just did.

Then, in those cases where I pop a listbox on top of the drawing, I take
the stored info and repaint (actually redraw) what I messed up.

That's why my question included, "can I do this drawing outside of the
picturebox paint event" and gave examples of what I proposed to do. No
answer yet.

I can't run the VB2005 version until I clear 102 errors and a whole slew
of warnings.

Galen S

Jan 31 '06 #6

P: n/a
I've also been reluctant to jump into vb.net graphics, precisely because its
behavior is substantially different from vb classic.

However, getting a similar behavior to the vb classic autoredraw shouldn't
be
all that hard. What you need to do is to do explicitly in vb.net what vb
classic
was doing for you behind the scenes. With autoredraw turned on, drawing
operations
in vb classic were actually being written to an off-screen picture. The
on-screen image
would automatically be repaired as needed from the off-screen picture.

So what you need to do, I think, is to create a global bitmap and do all
your drawing operations
to it. That way you can do your drawing from your subroutines just like you
are used to.
In the paint event, the only thing you have to do is copy the bitmap onto
the screen.
The "refresh" that you did in vb classic is replaced with something that
forces a paint event
(invalidate?)



"CMM" <cm*@nospam.com> wrote in message
news:e4**************@TK2MSFTNGP12.phx.gbl...
First, I have oodles of experience drawing in VB.Classic and quite a bit
in .NET....NET drawing is great... though the x2/y2 pixel offsetting is
confusing sometimes (to me).

Let me guess.... you have AutoRedraw on your VB.Classic picture box set?
If not, what's the problem?
I don't really see it.... What's the problem with doing your drawing
inside the paint event?
Sub ... Paint(...)
DrawLines(g)
DrawSomethingElse(g)
End Sub

If you wanted to update the canvas (based on some changes in your numbers
or whatever that you'd maintain on the module class level) you'd simply
call .Refresh on the form or control in question.

Drawing in .NET is extremely extraordinarily fast (at least compared to
VB.Classic). Even if your Paint event is called a 30 times in a second you
would never really notice. If flashing becomes a problem turn on
DoubleBuffering.

Am I misunderstanding your intent somehow? If so, explain further and I'll
try to help.

"Galen Somerville" <ga***@SPAM.surewest.net> wrote in message
news:Og**************@TK2MSFTNGP10.phx.gbl...

"Ken Halter" <Ken_Halter@Use_Sparingly_Hotmail.com> wrote in message
news:e2****************@TK2MSFTNGP12.phx.gbl...
"Galen Somerville" <ga***@SPAM.surewest.net> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
This was easy in VB6 but I just can't get it into my mind as to
accomplishing this in VB2005.

I haven't even attempted drawing anything in .Net but..... can't you
create a sub that does the drawing and call that from "anywhere" plus
the paint event? Sounds like "the VB6 way" I know <g>

GalenS (if I were the other Galen, I would know)

Maybe you *are* the other Galen and no one told you? <g>

--
Ken Halter - MS-MVP-VB (visiting from VB6 world) -
http://www.vbsight.com
Please keep all discussions in the groups..

Last things first. In nosing around the net groups I saw a Galen and I
think he (she ?) was an MVP

In "the VB6 way" all of my drawing is in subs. Each sub ends by storing
the points and colors of what it just did.

Then, in those cases where I pop a listbox on top of the drawing, I take
the stored info and repaint (actually redraw) what I messed up.

That's why my question included, "can I do this drawing outside of the
picturebox paint event" and gave examples of what I proposed to do. No
answer yet.

I can't run the VB2005 version until I clear 102 errors and a whole slew
of warnings.

Galen S


Jan 31 '06 #7

P: n/a
The reply by James Parsly sounds like what I need.

I draw to the picture box different things at different times and I coudn't
see how I could accomplish that if I put it all in a Paint event. I would
have case or if statements galore trying to separate it all out.

For instance the sweep is drawing a line from the last pixel position to the
next pixel position with X being incremented by 1. Whereas the vertical
lines (and text) are xored so the mouse movement draws it a second time to
erase it then draws the vertical line at the next position. Etc.

Comments?

GalenS
"CMM" <cm*@nospam.com> wrote in message
news:e4**************@TK2MSFTNGP12.phx.gbl...
First, I have oodles of experience drawing in VB.Classic and quite a bit
in .NET....NET drawing is great... though the x2/y2 pixel offsetting is
confusing sometimes (to me).

Let me guess.... you have AutoRedraw on your VB.Classic picture box set?
If not, what's the problem?
I don't really see it.... What's the problem with doing your drawing
inside the paint event?
Sub ... Paint(...)
DrawLines(g)
DrawSomethingElse(g)
End Sub

If you wanted to update the canvas (based on some changes in your numbers
or whatever that you'd maintain on the module class level) you'd simply
call .Refresh on the form or control in question.

Drawing in .NET is extremely extraordinarily fast (at least compared to
VB.Classic). Even if your Paint event is called a 30 times in a second you
would never really notice. If flashing becomes a problem turn on
DoubleBuffering.

Am I misunderstanding your intent somehow? If so, explain further and I'll
try to help.

"Galen Somerville" <ga***@SPAM.surewest.net> wrote in message
news:Og**************@TK2MSFTNGP10.phx.gbl...

"Ken Halter" <Ken_Halter@Use_Sparingly_Hotmail.com> wrote in message
news:e2****************@TK2MSFTNGP12.phx.gbl...
"Galen Somerville" <ga***@SPAM.surewest.net> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
This was easy in VB6 but I just can't get it into my mind as to
accomplishing this in VB2005.

I haven't even attempted drawing anything in .Net but..... can't you
create a sub that does the drawing and call that from "anywhere" plus
the paint event? Sounds like "the VB6 way" I know <g>

GalenS (if I were the other Galen, I would know)

Maybe you *are* the other Galen and no one told you? <g>

--
Ken Halter - MS-MVP-VB (visiting from VB6 world) -
http://www.vbsight.com
Please keep all discussions in the groups..

Last things first. In nosing around the net groups I saw a Galen and I
think he (she ?) was an MVP

In "the VB6 way" all of my drawing is in subs. Each sub ends by storing
the points and colors of what it just did.

Then, in those cases where I pop a listbox on top of the drawing, I take
the stored info and repaint (actually redraw) what I messed up.

That's why my question included, "can I do this drawing outside of the
picturebox paint event" and gave examples of what I proposed to do. No
answer yet.

I can't run the VB2005 version until I clear 102 errors and a whole slew
of warnings.

Galen S


Jan 31 '06 #8

P: n/a

James Parsly wrote:
I've also been reluctant to jump into vb.net graphics, precisely because its
behavior is substantially different from vb classic.

However, getting a similar behavior to the vb classic autoredraw shouldn't
be
all that hard. What you need to do is to do explicitly in vb.net what vb
classic
was doing for you behind the scenes. With autoredraw turned on, drawing
operations
in vb classic were actually being written to an off-screen picture. The
on-screen image
would automatically be repaired as needed from the off-screen picture.

So what you need to do, I think, is to create a global bitmap and do all
your drawing operations
to it. That way you can do your drawing from your subroutines just like you
are used to.
In the paint event, the only thing you have to do is copy the bitmap onto
the screen.
This is exactly what I was going to suggest, after reading the original
post.
The "refresh" that you did in vb classic is replaced with something that
forces a paint event
(invalidate?)


Yes, and we can even be clever and only invalidate that part of the
picture that has just changed - check the various overloads of
Control.Invalidate.

--
Larry Lard
Replies to group please

Jan 31 '06 #9

P: n/a

"Larry Lard" <la*******@hotmail.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...

James Parsly wrote:
I've also been reluctant to jump into vb.net graphics, precisely because
its
behavior is substantially different from vb classic.

However, getting a similar behavior to the vb classic autoredraw
shouldn't
be
all that hard. What you need to do is to do explicitly in vb.net what vb
classic
was doing for you behind the scenes. With autoredraw turned on, drawing
operations
in vb classic were actually being written to an off-screen picture. The
on-screen image
would automatically be repaired as needed from the off-screen picture.

So what you need to do, I think, is to create a global bitmap and do all
your drawing operations
to it. That way you can do your drawing from your subroutines just like
you
are used to.
In the paint event, the only thing you have to do is copy the bitmap onto
the screen.


This is exactly what I was going to suggest, after reading the original
post.
The "refresh" that you did in vb classic is replaced with something that
forces a paint event
(invalidate?)


Yes, and we can even be clever and only invalidate that part of the
picture that has just changed - check the various overloads of
Control.Invalidate.

--
Larry Lard
Replies to group please

Thanks, will look into that. Things are looking up and I'm almost ready to
fly.

GalenS
Jan 31 '06 #10

P: n/a
CMM
Ah I see.... yeah ... you'll have to implement your own CurrentX/CurrentY
scheme.
Jan 31 '06 #11

This discussion thread is closed

Replies have been disabled for this discussion.