XXChester

Hello; Basically the program I am trying to develop is the same concept as the Paint program shipped with Windows OS. The part I am unable to figure out is how do I make the followwing work the same way Paint does When you click say the toolbrush in paint it goes on the mouse cursor and then you drop it or draw with it on the other section of the interface...say a Panel. I figured out how to send the clicked object to the panel but it just goes to the position inwhich it is programmed to drop to, I cannot figure out how to get it to go on the mouse. Anyways any help would be great, I will be away for a couple days and unable to reply but I will check back as soon as I can to give required information if any is needed.

Thank you in advance for reviewing my thread and trying to help me solve this problem.



Re: Windows Forms General Mouse click event

Yu Guo ¨C MSFT

Hi, XXChester,

A common way to do this is to draw a line while your mouse cursor is moving around.

I wrote a small sample to illustrate it.

Code Snippet

Graphics g;
int x;
int y;
public Form5()
{
InitializeComponent();
panel1.MouseDown += new MouseEventHandler(panel1_MouseDown);
panel1.MouseMove += new MouseEventHandler(panel1_MouseMove);
panel1.MouseUp += new MouseEventHandler(panel1_MouseUp);
}

private void Form5_Load(object sender, EventArgs e)
{


}

void panel1_MouseUp(object sender, MouseEventArgs e)
{
g.DrawEllipse(Pens.Black, e.X, e.Y, 1, 1);
g = null;
}

void panel1_MouseMove(object sender, MouseEventArgs e)
{
if (g != null)
{
g.DrawLine(Pens.Black, x, y, e.X, e.Y);
x = e.X;
y = e.Y;
}

}


void panel1_MouseDown(object sender, MouseEventArgs e)
{
g = panel1.CreateGraphics();
g.DrawEllipse(Pens.Black, e.X, e.Y, 1, 1);
x = e.X;
y = e.Y;
}

And you can check the following URL to learn more on how to write a painter with .Net

http://www.codeproject.com/csharp/drawtools.asp

Hope this helps

Regards






Re: Windows Forms General Mouse click event

XXChester

Thank you, I will have to test out your code. Either way thank you, I have abondand this project for other reasons and we are taking an alternate route to do this but The help is greatly appreciated.