|
i have made a line and i update its end points in a loop ...basically to make a circle ... now what a wants is that when a line is made the previously created line should be deleted ?
need help plzz ?
i have tried dipose ??
|
|
|
|
|
previously created line must be draw again using background color.
|
|
|
|
|
First of all, wrong forum... but never the less
How are you trying to draw?
The right way to do it is firstly create a DoubleBufferedPannel . To do that create a new cs file in your solution and add the following code in there.
namespace DoubleBufferPanelNameSpace
{
public class DoubleBufferPanel : Panel
{
public DoubleBufferPanel()
{
this.SetStyle(ControlStyles.AllPaintingInWmPaint |
ControlStyles.UserPaint |
ControlStyles.DoubleBuffer |
ControlStyles.ResizeRedraw,
true);
this.UpdateStyles();
}
}
}
compile your project and the you'll see the DoubleBufferPanel in your toolbox. Drop that on the form you want to draw on.
Then to do your GDI code all you have to do is use the panels paint handler like so
private void doubleBufferPanel1_Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawLine(new Pen(Brushes.Black), 0, 0, 10, 10);
}
If you want the image to be redrawn cause some of the variables that affect the drawing has changed you can call doubleBufferPanel1.Invalidate(); which forces the control to be redrawn.
Using this aproach there is no need to worry about disposing graphics objects as its done for you.
Hope this helps
Harvey Saayman - South Africa
Software Developer
.Net, C#, SQL
you.suck = (you.Occupation == jobTitles.Programmer && you.Passion != Programming)
1000100 1101111 1100101 1110011 100000 1110100 1101000 1101001 1110011 100000 1101101 1100101 1100001 1101110 100000 1101001 1101101 100000 1100001 100000 1100111 1100101 1100101 1101011 111111
|
|
|
|
|
hEY THANKS
I really cant understand why u made a new class ? i directly pasted a PANEL on the forum .
My main issue was not disposing ... my main issue was to erase previously created graphics .. ?
|
|
|
|
|
Two reasons. Every time a control needs to be redrawn by the OS it's OnPain't gets called. Creating your own class derrived from the control in question (Panel) gives you access to this method so you can guarantee your code is going to get called every time it is needed.
Doing it this way, you get a Graphics object for free. No need to use more resources and no need to remember to dispose of it.
A proposal for a slight improvement to Harvey's code:
public class DoubleBufferPanel : Panel
{
public DoubleBufferPanel()
{
this.SetStyle(
ControlStyles.AllPaintingInWmPaint |
ControlStyles.UserPaint |
ControlStyles.DoubleBuffer |
ControlStyles.ResizeRedraw, true);
this.UpdateStyles();
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
using (Pen pen = new Pen(Color.Black))
{
e.Graphics.DrawLine(pen, 0, 0, 10, 10);
}
}
}
|
|
|
|
|
If your drawing changes it will flicker and that's no fun... The extra class basically enables double buffering on the panel control and that eliminates the flickering.
Lets have a look at your OnPaint event handler code and see what we can come up with. And how would you like to erase these previously created graphics? What exactly are you trying to write?
The more info you give the better we can understand your problem
Harvey Saayman - South Africa
Software Developer
.Net, C#, SQL
you.suck = (you.Occupation == jobTitles.Programmer && you.Passion != Programming)
1000100 1101111 1100101 1110011 100000 1110100 1101000 1101001 1110011 100000 1101101 1100101 1100001 1101110 100000 1101001 1101101 100000 1100001 100000 1100111 1100101 1100101 1101011 111111
|
|
|
|
|
hi...
am developing an c# windows application in which i need to control the form controls from another form, i tried it but its not, so any one plz help me out in solving this..
thnks n rgrds
ageesh
|
|
|
|
|
You can do this by creating your own events.
Have a look at my article Delegates, Events, Event Arguments, and How They Fit Together[^]
Harvey Saayman - South Africa
Software Developer
.Net, C#, SQL
you.suck = (you.Occupation == jobTitles.Programmer && you.Passion != Programming)
1000100 1101111 1100101 1110011 100000 1110100 1101000 1101001 1110011 100000 1101101 1100101 1100001 1101110 100000 1101001 1101101 100000 1100001 100000 1100111 1100101 1100101 1101011 111111
|
|
|
|
|
Hi,
Can you please tell me if there is a way to find if a file is already open or not?
|
|
|
|
|
We can use some tricky code fot this.
Open the file in Write mode so that you'll get an exception.Catch that exception.
If any good method is there let me know.
|
|
|
|
|
Actually i am getting the exception but i am not able to handle it..so in order to handle it i want to check if the file is already open or not
|
|
|
|
|
Can u post your code snippet so that we can help you.
|
|
|
|
|
Swetha Srinivasan wrote: i want to check if the file is already open or not
Do you know which process opened the file?
Have u got error when you open the file first time from your code?
Have u handled the stream properly?
I think its opened by CLR itself.isn't it?
|
|
|
|
|
I have solved the problem.I put the code in Try..Catch...
|
|
|
|
|
Hi All,
If I have a form with several buttons and the click event handler for all the buttons points to the same handler, how can I determine in handler which button was clicked?
this.button1.Click += new System.EventHandler(this.button_ClickHandler);
this.button2.Click += new System.EventHandler(this.button_ClickHandler);
this.button3.Click += new System.EventHandler(this.button_ClickHandler);
private void button_ClickHandler(object sender, EventArgs e)
{
MessageBox.Show("Who raised this event?");
}
|
|
|
|
|
you have object sender.
|
|
|
|
|
OF COURSE...I'm only annoyed because I didn't figure that out for myself. -Thanks
MessageBox.Show(((Button)sender).Name + " Who raised this event?");
|
|
|
|
|
A better way to do this is:
Button b = sender as Button;
if (b != null)
{
MessageBox.Show(b.Name + " Who raised this event?");
} Just casting the sender to a Button is a bad practice as it will throw an exception if the sender is not a button.
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
Hi, I tend to use:
if (sender is Button)
{
Button button = sender as Button;
} for no particular reason. Is there any advantage to using as , then null checking over is , then as in your opinion?
|
|
|
|
|
I don't think there is any advantage either way; it's a stylistic thing. I just like my null checks to be explicit and visible!
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
Hi,
i need to send a user request form to approver in c# application.i am sending it as a form in body it is working fine in outlook 2003, but in outlook 2007 its not working because microsoft changes html contol in outlook mail. is there any procedure to send this form as an image attchment to user.
thanks in advance.
|
|
|
|
|
Dear All,
I have developed a winform app which runs at startup. i have done this using registry key.
the question which bothers me is, does this application runs prior logging to my computer?
what I want is that when the logon screan appears this application should run at background whether i login or not.
any ideas or suggestions?
Abdul Rahaman Hamidy
Database Developer
Kabul, Afghanistan
|
|
|
|
|
I believe you need a windows service.
|
|
|
|
|
Abdul Rahman Hamidy wrote: does this application runs prior logging to my computer?
No.
Abdul Rahman Hamidy wrote: what I want is that when the logon screan appears this application should run at background whether i login or not.
any ideas or suggestions?
I'm not sure this is possible. I don't think anything runs prior to login, except the gina.dll that handles login.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Christian Graus wrote: I don't think anything runs prior to login, except the gina.dll that handles login.
I believe windows services does.
|
|
|
|