Technology Microsoft Software & solutions

GDI+ Graphics in Visual Basic 2005 .NET

< Continued from page 1

The complete code for our program is shown below. To code it yourself, Add a Panel control named PaintTrig and three Button controls: SineButton, CosineButton, and TangentButton. Then copy and paste the code into your VB.NET code window.

Imports System.Drawing.Drawing2D
Imports System.Math
Public Class TrigGraphs
   Dim TrigPoints(359) As PointF
   Dim Counter As Integer
   Dim TrigBoxInterval As Double
   Dim TrigBoxMidPoint As Double
   Dim P As Pen = New Pen(Color.DarkSalmon, 3)
   Private Sub SineButton_Click( _
      ByVal sender As System.Object, _
      ByVal e As System.EventArgs) _
      Handles SineButton.Click
      For Counter = 0 To 359
         TrigPoints(Counter) = _
            New Point(Round( _
            Counter * TrigBoxInterval), _
            TrigBoxMidPoint - TrigBoxMidPoint _
            * Sin(PI * Counter / 180))
      Next
      PaintTrig.Refresh()
   End Sub
   Private Sub CosineButton_Click( _
      ByVal sender As System.Object, _
      ByVal e As System.EventArgs) _
      Handles CosineButton.Click
      For Counter = 0 To 359
         TrigPoints(Counter) = _
            New Point(Round( _
            Counter * TrigBoxInterval), _
            TrigBoxMidPoint - TrigBoxMidPoint _
            * Cos(PI * Counter / 180))
      Next
      PaintTrig.Refresh()
   End Sub
   Private Sub TangentButton_Click( _
      ByVal sender As System.Object, _
      ByVal e As System.EventArgs) _
      Handles TangentButton.Click
      Dim myTan As Double
      For Counter = 0 To 359
         Try
            myTan = Tan(PI * Counter / 180) * 4
            TrigPoints(Counter) = _
               New Point(Round( _
               Counter * TrigBoxInterval), _
               TrigBoxMidPoint - myTan)
         Catch
            If Tan(PI * Counter / 180) * 4 > _
               TrigBoxMidPoint Then
               TrigPoints(Counter) = _
                  New Point( _
                  Round(Counter * TrigBoxInterval), _
                  PaintTrig.Height)
            Else
               TrigPoints(Counter) = _
                  New Point( _
                  Round(Counter * TrigBoxInterval), 0)
            End If
         End Try
      Next
      PaintTrig.Refresh()
   End Sub
   Private Sub TrigGraphs_Load( _
      ByVal sender As System.Object, _
      ByVal e As System.EventArgs) _
      Handles MyBase.Load
      TrigBoxInterval = PaintTrig.Width / 360
      TrigBoxMidPoint = CInt(PaintTrig.Height / 2 - 1)
   End Sub
   Private Sub PaintTrig_Paint( _
      ByVal sender As System.Object, _
      ByVal e As System.Windows.Forms.PaintEventArgs) _
      Handles PaintTrig.Paint
      e.Graphics.DrawCurve(P, TrigPoints)
      MyBase.OnPaint(e)
   End Sub
End Class

SHARE
RELATED POSTS on "Technology"
How to Configure Oracle 10G for XP Home
How to Configure Oracle 10G for XP Home
How to Use Glass Bottles to Make Windows
How to Use Glass Bottles to Make Windows
What Is Windows Sharepoint Services 3.0?
What Is Windows Sharepoint Services 3.0?
How to Uninstall the Computer Associates eTrust Agent
How to Uninstall the Computer Associates eTrust Agent
How to Boot to Safe Mode on an HP Pavilion dv6000
How to Boot to Safe Mode on an HP Pavilion dv6000
How to Unzip Files in Windows 98
How to Unzip Files in Windows 98
How to Remove Spy.Goldun
How to Remove Spy.Goldun
How to Get Rid of the Trial Period for Adobe Lightroom
How to Get Rid of the Trial Period for Adobe Lightroom
Kindle for PC Installation Problems
Kindle for PC Installation Problems
How to Clean Spyware From the Registry
How to Clean Spyware From the Registry
How to Add Windows XP to Your Laptop
How to Add Windows XP to Your Laptop
How to Uninstall a Paper Port
How to Uninstall a Paper Port
What is Active Sync for X50?
What is Active Sync for X50?
How to Upgrade Windows SharePoint Services
How to Upgrade Windows SharePoint Services
How to Get Windows to Start in an Administrator Account
How to Get Windows to Start in an Administrator Account
How do I Create Restore Diskette for XP?
How do I Create Restore Diskette for XP?
How to Avoid a Cyclic Redundancy Check
How to Avoid a Cyclic Redundancy Check
What Are the Keystrokes for Pasting?
What Are the Keystrokes for Pasting?
How to Make Windows Vista Stop Looking for New Wireless Networks
How to Make Windows Vista Stop Looking for New Wireless Networks
Recommended Hardware Requirements for Running Vista Home
Recommended Hardware Requirements for Running Vista Home

Leave Your Reply

*