Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi all
i need to draw a line from the center of the screen(Winform) to the point where the mouse is moved.

i have used this logic to change the cursor arrow image. this is for the 4 directions. how can i do it for 8 directions(NorthEast,Northwest,SouthEast,SouthWest)

C#
if (System.Math.Abs(x_axis - p.X) > System.Math.Abs(y_axis - p.Y))
{
    // change in x is greater, now find left or right
    if ((x_axis - p.X) < 0)
    {
        //Right
        //Cursor.DrawStretched;
        Cursor.Current = Cursors.PanEast;
    }
    else
    {
        //return "left";
        Cursor.Current = Cursors.PanWest;
        //Cursors.p
    }
}
else
{
    // change in y is greater, now find up or down
    if ((y_axis - p.Y) < 0)
    {
        //return "up";
        Cursor.Current = Cursors.PanSouth;
    }
    else
    {
        //return "down";
        Cursor.Current = Cursors.PanNorth;
    }
}


[edit]Code block added, "Treat my content as plain text..." option disabled - OriginalGriff[/edit]
Posted
Updated 31-Jan-12 20:25pm
v2
Comments
Sergey Alexandrovich Kryukov 1-Feb-12 1:48am    
Why? How can it help drawing the lines?
--SA

1 solution

Have a look at this: Octants in Cartesian plane[^]

It's not quite what you need, but it illustrates the principle pretty well.
 
Share this answer
 
Comments
valiant123 1-Feb-12 6:29am    
Thanks a lot friend :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900