|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
VB2005 pro GraphicsThe 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 Galen Somerville wrote:
Show quoteHide quote > Going from VB6 (RAD) to VB2005 (SAD) The reason to do it in the paint method is that event gets called each > > 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 > > 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
Show quote
Hide quote
"Chris" <no@spam.com> wrote in message ouch. The current program displays Heart sounds in real time. That is it news:OgFT8neJGHA.3492@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 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) "Galen Somerville" <galen@SPAM.surewest.net> wrote in message I haven't even attempted drawing anything in .Net but..... can't you create news:%23JoJW0eJGHA.2704@TK2MSFTNGP15.phx.gbl... > > > This was easy in VB6 but I just can't get it into my mind as to > accomplishing this in VB2005. 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..
Show quote
Hide quote
"Ken Halter" <Ken_Halter@Use_Sparingly_Hotmail.com> wrote in message Last things first. In nosing around the net groups I saw a Galen and I think news:e2B%23eCfJGHA.1424@TK2MSFTNGP12.phx.gbl... > "Galen Somerville" <galen@SPAM.surewest.net> wrote in message > news:%23JoJW0eJGHA.2704@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.. > 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 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. Show quoteHide quote "Galen Somerville" <galen@SPAM.surewest.net> wrote in message news:OguTFqgJGHA.3732@TK2MSFTNGP10.phx.gbl... > > "Ken Halter" <Ken_Halter@Use_Sparingly_Hotmail.com> wrote in message > news:e2B%23eCfJGHA.1424@TK2MSFTNGP12.phx.gbl... >> "Galen Somerville" <galen@SPAM.surewest.net> wrote in message >> news:%23JoJW0eJGHA.2704@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 > > > > 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?) Show quoteHide quote "CMM" <cmm@nospam.com> wrote in message news:e48CRPjJGHA.1848@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" <galen@SPAM.surewest.net> wrote in message > news:OguTFqgJGHA.3732@TK2MSFTNGP10.phx.gbl... >> >> "Ken Halter" <Ken_Halter@Use_Sparingly_Hotmail.com> wrote in message >> news:e2B%23eCfJGHA.1424@TK2MSFTNGP12.phx.gbl... >>> "Galen Somerville" <galen@SPAM.surewest.net> wrote in message >>> news:%23JoJW0eJGHA.2704@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 >> >> >> >> > > James Parsly wrote:
Show quoteHide quote > I've also been reluctant to jump into vb.net graphics, precisely because its This is exactly what I was going to suggest, after reading the original> 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. post. > The "refresh" that you did in vb classic is replaced with something that Yes, and we can even be clever and only invalidate that part of the> forces a paint event > (invalidate?) picture that has just changed - check the various overloads of Control.Invalidate. -- Larry Lard Replies to group please
Show quote
Hide quote
"Larry Lard" <larryl***@hotmail.com> wrote in message Thanks, will look into that. Things are looking up and I'm almost ready to news:1138721910.021766.194680@g44g2000cwa.googlegroups.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 > fly. GalenS 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 Show quoteHide quote "CMM" <cmm@nospam.com> wrote in message news:e48CRPjJGHA.1848@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" <galen@SPAM.surewest.net> wrote in message > news:OguTFqgJGHA.3732@TK2MSFTNGP10.phx.gbl... >> >> "Ken Halter" <Ken_Halter@Use_Sparingly_Hotmail.com> wrote in message >> news:e2B%23eCfJGHA.1424@TK2MSFTNGP12.phx.gbl... >>> "Galen Somerville" <galen@SPAM.surewest.net> wrote in message >>> news:%23JoJW0eJGHA.2704@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 >> >> >> >> > > Ah I see.... yeah ... you'll have to implement your own CurrentX/CurrentY
scheme.
IsDate("ISomeTimesHateProgrammingMarch2005") = True
Query Builder Better way to go from ArrayList to Object() Convert from C# to VB.Net Dataset requery Simple (I hope) SteamReader DirectoryInfo question Assigning ListBox Current Selection to TextBox FileSystemObject filter? File Info Question extracting part of a graphic in a PictureBox to the clipboard |
|||||||||||||||||||||||