473,624 Members | 2,346 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to delete (clear) lines

Hello

How can I delete (clear) lines that were made useing Graphics.DrawLi ne() ?

Thanks in advance! Have a nice day!

Nov 15 '05 #1
2 20913
In VS 6.0 and in OpenGL, this is fairly simple, you just use the XOR
drawing mode, which draws a line normally the first time, and then
"erases" it the second time.

GDI+ doesn't have support for the pen modes anymore, but your task is
not too much more difficult.

There are a couple ways to do this:

1. you could keep a bitmap of what the clear, or erased state looks
like, and whenever you want to erase the line, you would do something like:
//...
private Image savedImage;
//...

// your standard paint method
private void My_Paint(object sender,
System.Windows. Forms.PaintEven tArgs e)
{
if (something_has_ changed_like_th e_form_has_been _resized)
{
Rectangle rect = this.GetDrawing Rectangle();
this.savedImage = new Bitmap(rect.Wid th, rect.Height);
Graphics gx = Graphics.FromIm age(savedImage) ;
gx.Clear(this.B ackColor);

// draw the normal, erased state
// ...
gx.Dispose();
}

Graphics g = e.Graphics;
g.DrawImageUnsc aled(this.saved Image,0,0);

// now draw any of the lines, pictures, etc.
// that you want to be erased.
}
2. The previous method is good if you need to completely redraw every
element of your picture each time, but what if you have a bunch of lines
already drawn, and you only want to erase one of them? Here's where you
can use a TextureBrush as a sort of eraser.

//...
private Image lastImage;
private Brush eraserBrush;
//...

// your standard paint method
private void My_Paint(object sender,
System.Windows. Forms.PaintEven tArgs e)
{
if (something_has_ changed_like_th e_form_has_been _resized)
{
// we may need to redraw everything...
Rectangle rect = this.GetDrawing Rectangle();
this.lastImage = new Bitmap(rect.Wid th, rect.Height);
Graphics gx = Graphics.FromIm age(this.lastIm age);
gx.Clear(this.B ackColor);

// draw the normal, erased state
// ...
// draw all of the elements that should be drawn...
gx.Dispose();
this.eraserBrus h = new TextureBrush(th is.lastImage);
}

// all of our lines, pictures, etc. are already stored
// inside lastImage, so we don't need to do anything here.

// let's say we kept track of some coordinates for a line,
// and also kept track of whether or not we need to do
// some erasing
if (bLineNeedsEras ing)
{
// by drawing to this Graphics object, we're updating the
// bitmap image.
Graphics imageGraphics = Graphics.FromIm age(this.lastIm age);

// assuming the first line was drawn with a width of 1 (float)
Pen p = new Pen(this.eraser Brush, 1F);

// assuming we kept track of a couple System.Drawing. PointF
// points representing the ends of the line
imageGraphics.D rawLine(p, this.linePoint1 , this.linePoint2 );
imageGraphics.D ispose();
}

Graphics g = e.Graphics;
g.DrawImageUnsc aled(this.lastI mage,0,0);
}
This second way is almost always the better way to go.

One last note: you're going to notice the screen flickering if you're
doing any kind of drawing. To alleviate this, look up the SetStyle
method, and use something like:

this.SetStyle(C ontrolStyles.Us erPaint, true);
this.SetStyle(C ontrolStyles.Do ubleBuffer, true);
this.SetStyle(C ontrolStyles.Al lPaintingInWmPa int, true);

in your own initialization code.
Tomomichi Amano wrote:
Hello

How can I delete (clear) lines that were made useing Graphics.DrawLi ne() ?

Thanks in advance! Have a nice day!


Nov 15 '05 #2
Another option is to keep track of everything as you paint it in some sort
of collection, then have an engine that can paint all of those to the
picturebox / form /bitmap whatever. To erase a line, you remove it from the
collection, and repaint everything else. I suppose this could be slow if
there are a lot of lines (and you'll want to use the anti-flicker methods
that Ben listed)

Another option to look at is the ControlPaint class - there is a method
DrawReversibleL ine. I haven't used it before, but you can surely find some
examples.

--
Mike Mayer
http://www.mag37.com/csharp/
mi**@mag37.com
"Ben T." <be*@jbmsystems .com> wrote in message
news:io******** ********@nwrdny 03.gnilink.net. ..
In VS 6.0 and in OpenGL, this is fairly simple, you just use the XOR
drawing mode, which draws a line normally the first time, and then
"erases" it the second time.

GDI+ doesn't have support for the pen modes anymore, but your task is
not too much more difficult.

There are a couple ways to do this:

1. you could keep a bitmap of what the clear, or erased state looks
like, and whenever you want to erase the line, you would do something like:

//...
private Image savedImage;
//...

// your standard paint method
private void My_Paint(object sender,
System.Windows. Forms.PaintEven tArgs e)
{
if (something_has_ changed_like_th e_form_has_been _resized)
{
Rectangle rect = this.GetDrawing Rectangle();
this.savedImage = new Bitmap(rect.Wid th, rect.Height);
Graphics gx = Graphics.FromIm age(savedImage) ;
gx.Clear(this.B ackColor);

// draw the normal, erased state
// ...
gx.Dispose();
}

Graphics g = e.Graphics;
g.DrawImageUnsc aled(this.saved Image,0,0);

// now draw any of the lines, pictures, etc.
// that you want to be erased.
}
2. The previous method is good if you need to completely redraw every
element of your picture each time, but what if you have a bunch of lines
already drawn, and you only want to erase one of them? Here's where you
can use a TextureBrush as a sort of eraser.

//...
private Image lastImage;
private Brush eraserBrush;
//...

// your standard paint method
private void My_Paint(object sender,
System.Windows. Forms.PaintEven tArgs e)
{
if (something_has_ changed_like_th e_form_has_been _resized)
{
// we may need to redraw everything...
Rectangle rect = this.GetDrawing Rectangle();
this.lastImage = new Bitmap(rect.Wid th, rect.Height);
Graphics gx = Graphics.FromIm age(this.lastIm age);
gx.Clear(this.B ackColor);

// draw the normal, erased state
// ...
// draw all of the elements that should be drawn...
gx.Dispose();
this.eraserBrus h = new TextureBrush(th is.lastImage);
}

// all of our lines, pictures, etc. are already stored
// inside lastImage, so we don't need to do anything here.

// let's say we kept track of some coordinates for a line,
// and also kept track of whether or not we need to do
// some erasing
if (bLineNeedsEras ing)
{
// by drawing to this Graphics object, we're updating the
// bitmap image.
Graphics imageGraphics = Graphics.FromIm age(this.lastIm age);

// assuming the first line was drawn with a width of 1 (float)
Pen p = new Pen(this.eraser Brush, 1F);

// assuming we kept track of a couple System.Drawing. PointF
// points representing the ends of the line
imageGraphics.D rawLine(p, this.linePoint1 , this.linePoint2 );
imageGraphics.D ispose();
}

Graphics g = e.Graphics;
g.DrawImageUnsc aled(this.lastI mage,0,0);
}
This second way is almost always the better way to go.

One last note: you're going to notice the screen flickering if you're
doing any kind of drawing. To alleviate this, look up the SetStyle
method, and use something like:

this.SetStyle(C ontrolStyles.Us erPaint, true);
this.SetStyle(C ontrolStyles.Do ubleBuffer, true);
this.SetStyle(C ontrolStyles.Al lPaintingInWmPa int, true);

in your own initialization code.
Tomomichi Amano wrote:
Hello

How can I delete (clear) lines that were made useing Graphics.DrawLi ne() ?
Thanks in advance! Have a nice day!

Nov 15 '05 #3

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

Similar topics

1
8883
by: Andrew DeFaria | last post by:
I created the following .sql file to demonstrate a problem I'm having. According to the manual: If |ON DELETE CASCADE| is specified, and a row in the parent table is deleted, then InnoDB automatically deletes also all those rows in the child table whose foreign key values are equal to the referenced key value in the parent row. However:
6
6694
by: Poppy | last post by:
I use the following code to append a line of text to a text file : Dim myFILENAME As String = Server.MapPath("/ABACUS/cvdocs/" & fileName) Dim objStreamWriter As StreamWriter objStreamWriter = File.AppendText(myFILENAME) objStreamWriter.WriteLine(csvline) objStreamWriter.Close() The code works fine but I need to be a ble to delete the entire contents of the file as well and I cant figure it out.
5
3490
by: Sam777 | last post by:
I was under the impression that creating the app_offline.htm file at the root of the webapp would cause all handles to be closed so that the app could be removed. Unfortunately, this isn't the case. One handle remains open. Debugging shows that it's actually the IIS cache and not ASP.NET that owns this handle. During IIS shutdown, the handle is closed with the following stack trace: ChildEBP RetAddr 0006fbe4 5a403e05...
22
4176
by: Cylix | last post by:
I have a 4row x 1col table, I would like to drop all the content of row three. Since Mac IE5.2 does not suppport deleteRow method, I have also try to set the innerHTML=''; but it does not work. How can I delete the node from DOM in other way? Thanks.
15
9912
by: batman | last post by:
i have a text file that is like: date = OCT0606 asdf sdaf asdfasdgsdgh asdfsdfasdg START-OF-DATA asdfasdfg asdfgdfgsfg
24
7540
by: biganthony via AccessMonster.com | last post by:
Hi, I have the following code to select a folder and then delete it. I keep getting a Path/File error on the line that deletes the actual folder. The line before that line deletes the files in the folder but I get the error message when the procedure attempts to delete the folder selected in the BrowseforFolderbyPath function. How can I get it to delete the folder that the user has selected in the Browse for Folder dialog?
2
19740
by: Francesco Pietra | last post by:
Please, how to adapt the following script (to delete blank lines) to delete lines containing a specific word, or words? f=open("output.pdb", "r") for line in f: line=line.rstrip() if line: print line f.close()
0
2075
by: Francesco Pietra | last post by:
I forgot to add that the lines to strip are in present case of the type of the following block HETATM 7007 O WAT 446 27.622 34.356 55.205 1.00 0.00 O HETATM 7008 H1 WAT 446 27.436 34.037 56.145 1.00 0.00 H HETATM 7009 H2 WAT 446 27.049 33.827 54.563 1.00 0.00 H occurring in a 300MB file. In present case each three-lines block is followed by line renumbering (7007,
19
10740
by: Daniel Pitts | last post by:
I have std::vector<Base *bases; I'd like to do something like: std::for_each(bases.begin(), bases.end(), operator delete); Is it possible without writing an adapter? Is there a better way? Is there an existing adapter? Thanks, Daniel.
0
8170
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8675
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8619
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8474
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7158
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6108
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4078
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2604
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1784
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.