Mouse drag and draw : Mouse Draw « 2D Graphics « VB.Net Tutorial

Home
VB.Net Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statements
5.Date Time
6.Class Module
7.Development
8.Collections
9.Generics
10.Attributes
11.Event
12.LINQ
13.Stream File
14.GUI
15.GUI Applications
16.Windows Presentation Foundation
17.2D Graphics
18.I18N Internationlization
19.Reflection
20.Regular Expressions
21.Security
22.Socket Network
23.Thread
24.Windows
25.XML
26.Database ADO.net
27.Design Patterns
VB.Net
VB.Net by API
VB.Net Tutorial » 2D Graphics » Mouse Draw 
17.25.1.Mouse drag and draw
Mouse drag and draw
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms

public class MouseDrawLine
   public Shared Sub Main
        Application.Run(New Form1)
   End Sub
End class

Public Class Form1
    Inherits System.Windows.Forms.Form

    Public Sub New()
        MyBase.New()

        InitializeComponent()
    End Sub

    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is NothingThen
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    Private components As System.ComponentModel.IContainer

    <System.Diagnostics.DebuggerStepThrough()Private Sub InitializeComponent()
        Me.AutoScaleBaseSize = New System.Drawing.Size(513)
        Me.ClientSize = New System.Drawing.Size(292266)
    End Sub

    Dim As System.Drawing.Graphics
    Dim x1, y1, x2, y2 As Integer
    Dim pen1 As New System.Drawing.Pen(Color.Black)
    Dim mouseDown As Integer = 0


    Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgsHandles MyBase.MouseDown
        mouseDown = 1
        x1 = e.X
        y1 = e.Y
    End Sub

    Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgsHandles MyBase.MouseUp
        mouseDown = 0
    End Sub

    Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgsHandles MyBase.MouseMove
        If mouseDown = Then
            Exit Sub
        Else
            x2 = e.X
            y2 = e.Y
            g = Me.CreateGraphics
            g.DrawLine(pen1, x1, y1, x2, y2)
            x1 = x2
            y1 = y2
        End If
    End Sub
End Class
17.25.Mouse Draw
17.25.1.Mouse drag and drawMouse drag and draw
17.25.2.Using the mouse to draw on a formUsing the mouse to draw on a form
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.