-
October 22nd, 2010, 03:39 AM
#1
GetPoint Method
A common feature of cad programs is a getpoint() function. The getpoint() function prompts the user to pick a point which is the return value of the function. I am trying to implement the very same thing and have failed.
The code below shows how far I have got with it. It behaves correctly except for one crucial point, it doesn't give the picked point as the return value of the calling function. I want to be able to write it as:
Point pt = GetPoint();
Any help would be appreciated.
Code:
public partial class Form1 : Form
{
Point pickPoint;
ManualResetEvent manualEvent;
public Form1()
{
InitializeComponent();
manualEvent = new ManualResetEvent(false);
this.MouseDown += new MouseEventHandler(Form1_MouseDown);
pickPoint = Point.Empty;
}
void Form1_MouseDown(object sender, MouseEventArgs e)
{
pickPoint = e.Location;
manualEvent.Set();
}
private void button1_Click(object sender, EventArgs e)
{
GetPoint();
}
void GetPoint()
{
Console.WriteLine("Pick point: ");
Thread t = new Thread(WaitForResult);
t.Start(manualEvent);
}
void WaitForResult(object obj)
{
ManualResetEvent mre = (ManualResetEvent)obj;
manualEvent.WaitOne();
Console.WriteLine("Point picked: {0}", pickPoint);
manualEvent.Reset();
}
}
-
October 26th, 2010, 08:57 AM
#2
Re: GetPoint Method
Why so komplex solution, why not just to read [code] Cursor.Position property?
- Make it run.
- Make it right.
- Make it fast.
Don't hesitate to rate my post.
-
October 27th, 2010, 03:40 AM
#3
Re: GetPoint Method
Because the getpoint method has to wait for the user to pick a point!
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|