Click here to Skip to main content
15,898,222 members
Home / Discussions / C#
   

C#

 
QuestionHelp With XML Reading Pin
That Asian Guy21-May-08 14:58
That Asian Guy21-May-08 14:58 
QuestionDrop-List Pin
nelsonpaixao21-May-08 14:51
nelsonpaixao21-May-08 14:51 
AnswerRe: Drop-List Pin
Judah Gabriel Himango21-May-08 17:15
sponsorJudah Gabriel Himango21-May-08 17:15 
AnswerRe: Drop-List Pin
DaveyM6922-May-08 10:43
professionalDaveyM6922-May-08 10:43 
QuestionException Handling Pin
MarkB77721-May-08 13:57
MarkB77721-May-08 13:57 
AnswerRe: Exception Handling Pin
Christian Graus21-May-08 14:04
protectorChristian Graus21-May-08 14:04 
AnswerRe: Exception Handling Pin
Ennis Ray Lynch, Jr.21-May-08 17:43
Ennis Ray Lynch, Jr.21-May-08 17:43 
QuestionProblem with Form_Paint and using Trig Pin
RedHotFunk21-May-08 13:40
RedHotFunk21-May-08 13:40 
I've been slowly fiddling with C# these last couple days, and something bothersome came up. I want to draw a line from a point (150,300) on a form that's (300,300). When I move my mouse, using trig, I want to draw from the point mentioned before to a spot towards the mouse. However, when I start to move further to the side, my accuracy become a bit off. If I did a bad job of explaining (and I probably did!), the link below is a screen shot of what I mean Laugh | :laugh: .

Screenshot Here[^]

Now, before it's suggested, I do not want to simply draw the line from the point to whatever mouse position (using e.X and e.Y) because afterwards, I want to use this technique for something else. Here's the snippet of my code:

private void Form1_MouseMove(object sender, MouseEventArgs e)
        {

            if (e.X<=300 && e.X>=0 && e.Y>=0 && e.Y<=300)
            {
              
                DistancePoints = (float)Math.Sqrt(Math.Pow(e.X - 150, 2) + Math.Pow(288 - e.Y, 2));

                angle = (float)Math.Acos((e.X - 150) / DistancePoints) * (float)(180 / Math.PI);
                double radians = angle * (Math.PI / 180);

                movey = (float)Math.Sin(radians%360) * 200;
                movex = (float)Math.Cos(radians%360) * 200;
            }
        }

private void Form1_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            SolidBrush LineC = new SolidBrush(Color.Red);
            if (method1)
            {
                Pen Thing = new Pen(Color.Red, 3);

                g.DrawLine(Thing, 150, 300, 150+movex, 300-movey);
                
            }


        }


I realize that the error most likely occurs because I'm drawing in fractions of a pixel when doing my calculations, and as such, perhaps C# cannot draw it. Or perhaps I'm wrong. If anyone knows what I may do to alter my code, or what I need to add in order for the accuracy to be spot on, it would be much appreciated! I'm in quite a pickle to be honest! Thanks in advance Big Grin | :-D
AnswerRe: Problem with Form_Paint and using Trig Pin
Judah Gabriel Himango21-May-08 17:14
sponsorJudah Gabriel Himango21-May-08 17:14 
QuestionHow to call a form if you know the form name only as a string variable &gt; Pin
unitecsoft21-May-08 13:27
unitecsoft21-May-08 13:27 
AnswerRe: How to call a form if you know the form name only as a string variable &gt; Pin
Judah Gabriel Himango21-May-08 13:51
sponsorJudah Gabriel Himango21-May-08 13:51 
GeneralRe: How to call a form if you know the form name only as a string variable &gt; Pin
unitecsoft21-May-08 14:46
unitecsoft21-May-08 14:46 
GeneralRe: How to call a form if you know the form name only as a string variable &gt; Pin
Judah Gabriel Himango21-May-08 17:12
sponsorJudah Gabriel Himango21-May-08 17:12 
AnswerRe: How to call a form if you know the form name only as a string variable &gt; Pin
Gareth H21-May-08 14:29
Gareth H21-May-08 14:29 
QuestionVisual Studio Add-In: remove tool icon when done Pin
DeepToot21-May-08 11:26
DeepToot21-May-08 11:26 
AnswerRe: Visual Studio Add-In: remove tool icon when done Pin
Judah Gabriel Himango21-May-08 11:35
sponsorJudah Gabriel Himango21-May-08 11:35 
GeneralRe: Visual Studio Add-In: remove tool icon when done Pin
DeepToot21-May-08 17:03
DeepToot21-May-08 17:03 
AnswerRe: Visual Studio Add-In: remove tool icon when done Pin
DeepToot21-May-08 17:30
DeepToot21-May-08 17:30 
QuestionControl.Remove vs control.dispose(); Pin
netJP12L21-May-08 11:07
netJP12L21-May-08 11:07 
AnswerRe: Control.Remove vs control.dispose(); Pin
Judah Gabriel Himango21-May-08 11:11
sponsorJudah Gabriel Himango21-May-08 11:11 
AnswerRe: Control.Remove vs control.dispose(); Pin
Spacix One21-May-08 11:16
Spacix One21-May-08 11:16 
GeneralMVP and Validation of User Input Pin
mr_lasseter21-May-08 10:53
mr_lasseter21-May-08 10:53 
GeneralRe: MVP and Validation of User Input Pin
Judah Gabriel Himango21-May-08 11:05
sponsorJudah Gabriel Himango21-May-08 11:05 
Questioncreate file when after installation Pin
Knowledgestudent21-May-08 10:09
Knowledgestudent21-May-08 10:09 
AnswerRe: create file when after installation Pin
Jimmanuel21-May-08 11:06
Jimmanuel21-May-08 11:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.