CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: GetPoint Method

  1. #1
    Join Date
    Oct 2010
    Location
    VS2008 .Net 3.5
    Posts
    10

    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();
    }
    }

  2. #2
    Join Date
    Mar 2004
    Location
    Prague, Czech Republic, EU
    Posts
    1,701

    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.

  3. #3
    Join Date
    Oct 2010
    Location
    VS2008 .Net 3.5
    Posts
    10

    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
  •  





Click Here to Expand Forum to Full Width

Featured