C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Articles » .NET Framework »

How to make Form as draw Image with color


Posted Date: 01 Jun 2005    Resource Type: Articles    Category: .NET Framework
Author: Ami DesaiMember Level: Silver    
Rating: 1 out of 5Points: 10



Graphical Repersentation



  • First you have add controls to the form i.e.
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents ComboBox1 As System.Windows.Forms.ComboBox
    Friend WithEvents Button1 As System.Windows.Forms.Button
  • then modify properties of that controls
    i.e. Me.Label1.Text = "Select Color";
    Me.ComboBox1.Items.AddRange(New Object() {"RED", "YELLOW", "GREEN", "BLUE", "BLACK"});
    Me.Button1.Text = "Clear";
  • then add code below in code view





       
    Public p, q As Integer
    Dim r As Integer

    Private Sub Form1_MouseDown(ByVal sender As System.Object, ByVal e As MouseEventArgs) Handles MyBase.MouseDown
    Me.p = Me.Cursor.Position.X
    Me.q = Me.Cursor.Position.Y
    r = -1
    End Sub

    Private Sub Form1_MouseMove(ByVal sender As System.Object, ByVal e As MouseEventArgs) Handles MyBase.MouseMove

    If Me.MouseButtons = MouseButtons.Left Then
    Dim g As Graphics = Me.CreateGraphics
    Dim myColor() As Color = {Color.FromArgb(255, 0, 0), Color.FromArgb(255, 255, 0), Color.FromArgb(0, 205, 80), Color.FromArgb(0, 0, 255), Color.FromArgb(0, 0, 0)}
    Dim myPen As System.Drawing.Pen

    Select Case Me.ComboBox1.SelectedIndex
    Case 0
    myPen = New System.Drawing.Pen(myColor(0), 2)
    Case 1
    myPen = New System.Drawing.Pen(myColor(1), 2)
    Case 2
    myPen = New System.Drawing.Pen(myColor(2), 2)
    Case 3
    myPen = New System.Drawing.Pen(myColor(3), 2)
    Case 4
    myPen = New System.Drawing.Pen(myColor(4), 2)
    End Select

    If r = -1 Then
    g.DrawLine(myPen, Me.p, Me.q, Cursor.Position.X, Cursor.Position.Y)
    Me.p = Cursor.Position.X
    Me.q = Cursor.Position.Y
    End If
    End If
    End Sub

    Private Sub Form1_MouseUp(ByVal sender As System.Object, ByVal e As MouseEventArgs) Handles MyBase.MouseUp
    r = 0
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim g As Graphics = Me.CreateGraphics
    g.Clear(Form1.DefaultBackColor)
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Me.ComboBox1.Text = Me.ComboBox1.DisplayMember
    End Sub

    End Class







    Summary






  • Responses


    No responses found. Be the first to respond and make money from revenue sharing program.

    Feedbacks      
    Popular Tags   What are tags ?   Search Tags  
    Sign In to add tags.
    (No tags found.)

    Post Feedback


    This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
    You must Sign In to post a response.
    Next Resource: COM+ and .NET (Part 3) – Creating UI that uses COM+ transaction
    Previous Resource: Conversion of Decimal number to any Base and vice-versa
    Return to Discussion Resource Index
    Post New Resource
    Category: .NET Framework


    Post resources and earn money!
     
    More Resources



    dotNet Slackers

    About Us    Contact Us    Privacy Policy    Terms Of Use