Results 1 to 4 of 4

Thread: Drawing Right Angled Triangles

  1. #1
    alexsoyoye is offline VB.NET Forum Newbie
    .NET Framework
    .NET 4.5
    Join Date
    Dec 2015
    Posts
    2
    Reputation
    0

    Drawing Right Angled Triangles

    I am basically looking for a way to animate a right angle triangle.
    The right angle triangle would be placed within a panel in a windows forum. The base angle would be changed to a degree entered by the user in a textbox(so it would be less than 90 degrees), the base length however should not change. please view the diagram below
    Diagram.png
    i would thinking a good way change the drawing would be to run a timer with a interval of 5 milliseconds uf the angle has number entered in the textbox has changed a new one would be redrawn.
    i am open to any suggestions tho

  2. #2
    jmcilhinney's Avatar
    jmcilhinney is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    13,798
    Reputation
    1704
    There's no need to use a Timer. You would either require the user to click a Button to redraw the triangle or else simply handle the TextChanged event of the TextBox. That said, it would be more appropriate to use a NumericUpDown than a TextBox. That will ensure only numbers can be entered and it also allows you to specify a valid range. Do you know how to do the drawing using GDI+? I'd recommend a PictureBox as the canvas rather than a Panel. A Panel will work but a PictureBox is already optimised for graphics.

  3. #3
    alexsoyoye is offline VB.NET Forum Newbie
    .NET Framework
    .NET 4.5
    Join Date
    Dec 2015
    Posts
    2
    Reputation
    0
    Quote Originally Posted by jmcilhinney View Post
    There's no need to use a Timer. You would either require the user to click a Button to redraw the triangle or else simply handle the TextChanged event of the TextBox. That said, it would be more appropriate to use a NumericUpDown than a TextBox. That will ensure only numbers can be entered and it also allows you to specify a valid range. Do you know how to do the drawing using GDI+? I'd recommend a PictureBox as the canvas rather than a Panel. A Panel will work but a PictureBox is already optimised for graphics.
    Thanks for the idea! however im still not certain how to go about coding the drawing of the right angle triangle

  4. #4
    jmcilhinney's Avatar
    jmcilhinney is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    13,798
    Reputation
    1704
    You already know the two end points of the horizontal and you know the angle to the left. Some simple trigonometry gives you the other apex. Three calls to DrawLine using those three Points and you're done. Note that trig functions reside in the Math class.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •