472,364 Members | 2,070 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,364 software developers and data experts.

VB2005 pro Graphics

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
10 1823
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

"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
"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

"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
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
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
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

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

"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
CMM
Ah I see.... yeah ... you'll have to implement your own CurrentX/CurrentY
scheme.
Jan 31 '06 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: thomasp | last post by:
I found the following code on MSDN to draw a line in VB2005. Public Sub DrawLinePoint(ByVal e As PaintEventArgs) ' Create pen. Dim blackPen As New Pen(Color.Black, 3) ' Create points that...
0
by: pete | last post by:
When saving a gif file in VB 2005 with a custom brush color the background if the image is dithered. When I save the image as any other type but gif the background is not dithered. What can I do to...
4
by: Galen Somerville | last post by:
I have a real timing problem. This involves getting data from a USB device via an ActiveX dll and drawing trace lines on the screen via a UserControl. The USB device sends six sets of pixel info...
1
by: Hector M Banda | last post by:
Hi all, Need i simple example on how print/preview data from a database. I already have some code but I am lost because the preview does not create multiple pages and only shows the first page and...
7
by: TAVOSOFT | last post by:
Hi friends, I am begginer , I wanna to learn VB2005 ,Which are good book for to learn VB2005 of level -begginer-intermediate. Thanks you friends.
4
by: Galen Somerville | last post by:
My VB2005 app gets real time Heart sounds and an ECG from a USB device. I'm looking for a way to speed up the drawing of the traces on the screen. In the following code the routine GetSounds...
1
by: erickwan88 | last post by:
I am doing a final year project for my school and is going to provide for an organization, so I am asking for some help on here. Indeed, I have no idea on how to get the input from my pen driver...
7
by: Galen Somerville | last post by:
I have been converting a VB6 project to VB2005 for lo these many months. Most of my problems have been solved thanks to people like WanYuan Wang and Mattias Sjogren. But now the Graphics aspect is...
15
by: Aalaan | last post by:
I am presently a user of classic vb6 and hang out on those newsgroups. Some of you may be aware that there is a very anti MS and vb2005 feeling there. I have tried to get them to tell me which...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.