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

Drawing xor lines

P: n/a
In my opinion, one of the worst failures of Net (VB2005 Pro) was not
providing an XOR line draw feature, as in VB6.

A major feature of my app is allowing the user to draw Markers (vertical
lines) on a trace so they can measure the time difference between markers.

Once they click on a desired location, on a trace, arrow buttons are
provided so they can move the marker to an exact location. With xor, I just
redraw the current marker to make it disappear then draw a new marker one
pixel away. No sweat in VB6.

I have put a screen shot of a typical trace with markers on my web site
under "Private" then click on "Marker display" "screen shot"
http://home.surewest.net/galen/index.html

I would appreciate any guidance I can get.

The traces are on a bitmap which is contained in a User Control. I thought
of drawing the marker on a copy of the bitmap. To move the marker I would
toss the copy and draw the new marker on a new copy of the original bitmap.
This, of course, would complicate my User Control.

Also there can be up to four markers displayed. If I move one and toss the
bitmap copy, I not only have to draw the new marker but I have to redraw the
other three which didn't move.

As you can see on the screen shot, a marker also shows some text (time
difference between markers). This means I can't just read in a vertical set
of pixels and later restore them as the marker is moved.

I could read a vertical rectangle which would be as wide as the worst case
text size.

Also, as the marker nears the right edge of the screen, the text is placed
to the left of the marker.

H E L P

GalenS
Apr 5 '06 #1
Share this Question
Share on Google+
11 Replies


P: n/a
DrawReversibleFrame()
Apr 5 '06 #2

P: n/a
it's there, just called something different, Galen already stated it, it's
been there since .NET 1.0
"Galen Somerville" <ga***@community.nospam> wrote in message
news:eA**************@TK2MSFTNGP05.phx.gbl...
In my opinion, one of the worst failures of Net (VB2005 Pro) was not
providing an XOR line draw feature, as in VB6.

A major feature of my app is allowing the user to draw Markers (vertical
lines) on a trace so they can measure the time difference between markers.

Once they click on a desired location, on a trace, arrow buttons are
provided so they can move the marker to an exact location. With xor, I
just redraw the current marker to make it disappear then draw a new marker
one pixel away. No sweat in VB6.

I have put a screen shot of a typical trace with markers on my web site
under "Private" then click on "Marker display" "screen shot"
http://home.surewest.net/galen/index.html

I would appreciate any guidance I can get.

The traces are on a bitmap which is contained in a User Control. I thought
of drawing the marker on a copy of the bitmap. To move the marker I would
toss the copy and draw the new marker on a new copy of the original
bitmap. This, of course, would complicate my User Control.

Also there can be up to four markers displayed. If I move one and toss the
bitmap copy, I not only have to draw the new marker but I have to redraw
the other three which didn't move.

As you can see on the screen shot, a marker also shows some text (time
difference between markers). This means I can't just read in a vertical
set of pixels and later restore them as the marker is moved.

I could read a vertical rectangle which would be as wide as the worst case
text size.

Also, as the marker nears the right edge of the screen, the text is placed
to the left of the marker.

H E L P

GalenS

Apr 5 '06 #3

P: n/a

"AMercer" <AM*****@discussions.microsoft.com> wrote in message
news:A8**********************************@microsof t.com...
DrawReversibleFrame()


That would be a real kludge. DrawReversibleLine would do for the actual
marker line.

But what about the text? Also the user now has the ability to use a specific
color for the markers.

GalenS
Apr 5 '06 #4

P: n/a
"Galen Somerville" <ga***@community.nospam> schrieb:
DrawReversibleFrame()


That would be a real kludge. DrawReversibleLine would do for the actual
marker line.

But what about the text? Also the user now has the ability to use a
specific color for the markers.


Unfortunately this is a limitation of GDI+ which 'System.Drawing' is based
on.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Apr 5 '06 #5

P: n/a

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:OF**************@TK2MSFTNGP05.phx.gbl...
"Galen Somerville" <ga***@community.nospam> schrieb:
DrawReversibleFrame()


That would be a real kludge. DrawReversibleLine would do for the actual
marker line.

But what about the text? Also the user now has the ability to use a
specific color for the markers.


Unfortunately this is a limitation of GDI+ which 'System.Drawing' is based
on.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

I was hoping you wouldn't say that.

Looks like I have build up a class to replace a one-liner in VB6

GalenS
Apr 5 '06 #6

P: n/a
how about this. have the fixed trace be one bitmap drawn first and have a
changing overlay bitmap that has a transparent background drawn on top of the
trace.

make a bitmap (bmOverlay) of the same size as the fixed drawing (the trace).
Make this bitmap transparent for black via
bmOverlay.MakeTransparent(Color.Black)
when an update happens, clear the bmOverlay to black, rebuild all its
vertical lines and text as you wish (location, color, etc). When it is time
to paint, paint the fixed bitmap first, then bmOverlay.

Apr 5 '06 #7

P: n/a

"AMercer" <AM*****@discussions.microsoft.com> wrote in message
news:27**********************************@microsof t.com...
how about this. have the fixed trace be one bitmap drawn first and have a
changing overlay bitmap that has a transparent background drawn on top of
the
trace.

make a bitmap (bmOverlay) of the same size as the fixed drawing (the
trace).
Make this bitmap transparent for black via
bmOverlay.MakeTransparent(Color.Black)
when an update happens, clear the bmOverlay to black, rebuild all its
vertical lines and text as you wish (location, color, etc). When it is
time
to paint, paint the fixed bitmap first, then bmOverlay.


That would work. My user control has a "permanent" bitmap (Bmp) which I
believe is continually painted by

Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
MyBase.OnPaint(e)
e.Graphics.DrawImage(Bmp, e.ClipRectangle, e.ClipRectangle,
GraphicsUnit.Pixel)
End Sub

When I want to clear the bitmap I use the BackColor property. The first use
of this property sets up the permanent bitmap and sets a flag. Subsequent
calls see the flag and skip the setup and just clears the bitmap to the
proper color.

The user, of the app, has 12 default colors that can be changed to suit
them. This includes back and fore colors, marker color, trace1/2/3 etc
colors.

Question. To paint the bmOverlay would I just set a flag then have an If
statement in the above OnPaint event?

GalenS
Apr 6 '06 #8

P: n/a
> My user control has a "permanent" bitmap (Bmp) which I
believe is continually painted by

Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
MyBase.OnPaint(e)
e.Graphics.DrawImage(Bmp, e.ClipRectangle, e.ClipRectangle,
GraphicsUnit.Pixel)
End Sub
"Continually" painted? Do you mean that the trace bitmap needs repainting
because it is being updated, maybe moving horizontally as time passes? If
so, don't you want the overlay to move with it? "Continually" kind of throws
me.
When I want to clear the bitmap I use the BackColor property. The first use
of this property sets up the permanent bitmap and sets a flag. Subsequent
calls see the flag and skip the setup and just clears the bitmap to the
proper color.
Still thrown by continually and now permanent above.
Question. To paint the bmOverlay would I just set a flag then have an If
statement in the above OnPaint event?


I ran one test, and painting (via DrawImage) the overlay bitmap after the
trace bitmap works fine. A flag that governs whether the overlay is visible
or not sounds like a good idea to me. Just to be complete, my test program
did not use OnPaint. Instead, when it had an updated bitmap it did
Form1.Invalidate(), and painting took place as follows:

Private Sub Form1_Paint(ByVal sender As Object, ByVal e As PaintEventArgs) _
Handles MyBase.Paint
e.Graphics.DrawImage(bmImage, 0, 0)
e.Graphics.DrawImage(bmOverlay, 0, 0)
End Sub

I don't think this difference is of consequence.
Apr 6 '06 #9

P: n/a

"AMercer" <AM*****@discussions.microsoft.com> wrote in message
news:65**********************************@microsof t.com...
My user control has a "permanent" bitmap (Bmp) which I
believe is continually painted by

Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
MyBase.OnPaint(e)
e.Graphics.DrawImage(Bmp, e.ClipRectangle, e.ClipRectangle,
GraphicsUnit.Pixel)
End Sub


"Continually" painted? Do you mean that the trace bitmap needs repainting
because it is being updated, maybe moving horizontally as time passes? If
so, don't you want the overlay to move with it? "Continually" kind of
throws
me.
When I want to clear the bitmap I use the BackColor property. The first
use
of this property sets up the permanent bitmap and sets a flag. Subsequent
calls see the flag and skip the setup and just clears the bitmap to the
proper color.


Still thrown by continually and now permanent above.
Question. To paint the bmOverlay would I just set a flag then have an If
statement in the above OnPaint event?


I ran one test, and painting (via DrawImage) the overlay bitmap after the
trace bitmap works fine. A flag that governs whether the overlay is
visible
or not sounds like a good idea to me. Just to be complete, my test
program
did not use OnPaint. Instead, when it had an updated bitmap it did
Form1.Invalidate(), and painting took place as follows:

Private Sub Form1_Paint(ByVal sender As Object, ByVal e As
PaintEventArgs) _
Handles MyBase.Paint
e.Graphics.DrawImage(bmImage, 0, 0)
e.Graphics.DrawImage(bmOverlay, 0, 0)
End Sub

I don't think this difference is of consequence.


Yes it is rather confusing. The trace display is Heart sounds and is an
oscilloscope type of display. That is, every few seconds lines are drawn to
connect the next 4 pixels horizontally. Since we show a gap, typically 5 to
10 pixels wide, we have to also have to redraw the existing 4 pixels beyond
the gap to the background color.

Originally I was getting flickering and other display problems. In a stroke
of genious, I added a module to the usercontrol and moved certain
declarations to this module as Public. Specifically g as Graphics, p as Pen,
f as Font and Bmp as bitmap. This is what I meant by "permanent".

Now the display is as solid as a rock. Continually is probably the wrong
wording. I don't make a change an then invalidate. I just make the changes.
As I understand it, invalidate means do a Paint on next vertical sweep. I
further understand that the overides OnPaint means Paint on every vertical
sweep.

GalenS


Apr 6 '06 #10

P: n/a

"Galen Somerville" <ga***@community.nospam> wrote in message
news:%2******************@TK2MSFTNGP02.phx.gbl...

"AMercer" <AM*****@discussions.microsoft.com> wrote in message
news:65**********************************@microsof t.com...
My user control has a "permanent" bitmap (Bmp) which I
believe is continually painted by

Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
MyBase.OnPaint(e)
e.Graphics.DrawImage(Bmp, e.ClipRectangle, e.ClipRectangle,
GraphicsUnit.Pixel)
End Sub


"Continually" painted? Do you mean that the trace bitmap needs
repainting
because it is being updated, maybe moving horizontally as time passes?
If
so, don't you want the overlay to move with it? "Continually" kind of
throws
me.
When I want to clear the bitmap I use the BackColor property. The first
use
of this property sets up the permanent bitmap and sets a flag.
Subsequent
calls see the flag and skip the setup and just clears the bitmap to the
proper color.


Still thrown by continually and now permanent above.
Question. To paint the bmOverlay would I just set a flag then have an If
statement in the above OnPaint event?


I ran one test, and painting (via DrawImage) the overlay bitmap after the
trace bitmap works fine. A flag that governs whether the overlay is
visible
or not sounds like a good idea to me. Just to be complete, my test
program
did not use OnPaint. Instead, when it had an updated bitmap it did
Form1.Invalidate(), and painting took place as follows:

Private Sub Form1_Paint(ByVal sender As Object, ByVal e As
PaintEventArgs) _
Handles MyBase.Paint
e.Graphics.DrawImage(bmImage, 0, 0)
e.Graphics.DrawImage(bmOverlay, 0, 0)
End Sub

I don't think this difference is of consequence.


Yes it is rather confusing. The trace display is Heart sounds and is an
oscilloscope type of display. That is, every few seconds lines are drawn
to connect the next 4 pixels horizontally. Since we show a gap, typically
5 to 10 pixels wide, we have to also have to redraw the existing 4 pixels
beyond the gap to the background color.

Originally I was getting flickering and other display problems. In a
stroke of genious, I added a module to the usercontrol and moved certain
declarations to this module as Public. Specifically g as Graphics, p as
Pen, f as Font and Bmp as bitmap. This is what I meant by "permanent".

Now the display is as solid as a rock. Continually is probably the wrong
wording. I don't make a change an then invalidate. I just make the
changes. As I understand it, invalidate means do a Paint on next vertical
sweep. I further understand that the overides OnPaint means Paint on every
vertical sweep.

GalenS

Oops, I use Me.Invalidate

GalenS
Apr 6 '06 #11

P: n/a
See the ControlPaint class

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"Galen Somerville" <ga***@community.nospam> wrote in message
news:eA**************@TK2MSFTNGP05.phx.gbl...
In my opinion, one of the worst failures of Net (VB2005 Pro) was not
providing an XOR line draw feature, as in VB6.

A major feature of my app is allowing the user to draw Markers (vertical
lines) on a trace so they can measure the time difference between markers.

Once they click on a desired location, on a trace, arrow buttons are
provided so they can move the marker to an exact location. With xor, I
just redraw the current marker to make it disappear then draw a new marker
one pixel away. No sweat in VB6.

I have put a screen shot of a typical trace with markers on my web site
under "Private" then click on "Marker display" "screen shot"
http://home.surewest.net/galen/index.html

I would appreciate any guidance I can get.

The traces are on a bitmap which is contained in a User Control. I thought
of drawing the marker on a copy of the bitmap. To move the marker I would
toss the copy and draw the new marker on a new copy of the original
bitmap. This, of course, would complicate my User Control.

Also there can be up to four markers displayed. If I move one and toss the
bitmap copy, I not only have to draw the new marker but I have to redraw
the other three which didn't move.

As you can see on the screen shot, a marker also shows some text (time
difference between markers). This means I can't just read in a vertical
set of pixels and later restore them as the marker is moved.

I could read a vertical rectangle which would be as wide as the worst case
text size.

Also, as the marker nears the right edge of the screen, the text is placed
to the left of the marker.

H E L P

GalenS

Apr 14 '06 #12

This discussion thread is closed

Replies have been disabled for this discussion.