how to draw Text on Mouse Move in VB.NET Windows Forms

Posted by Rojasamala under VB.NET on 8/20/2013 | Points: 10 | Views : 2040 | Status : [Member] | Replies : 1
how to draw Text on Mouse Move in VB.NET Windows Forms

Thanks
S Roja
http://aspdotnet-roja.blogspot.com



Responses

Posted by: Satyapriyanayak on: 8/20/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
Public Class Form1

Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents ToolBar1 As System.Windows.Forms.ToolBar
Friend WithEvents ToolBarButton4 As System.Windows.Forms.ToolBarButton
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.ToolBar1 = New System.Windows.Forms.ToolBar
Me.ToolBarButton4 = New System.Windows.Forms.ToolBarButton
Me.SuspendLayout()
'
'ToolBar1
'
Me.ToolBar1.Buttons.AddRange(New System.Windows.Forms.ToolBarButton() {Me.ToolBarButton4})
Me.ToolBar1.DropDownArrows = True
Me.ToolBar1.Location = New System.Drawing.Point(0, 0)
Me.ToolBar1.Name = "ToolBar1"
Me.ToolBar1.ShowToolTips = True
Me.ToolBar1.Size = New System.Drawing.Size(292, 42)
Me.ToolBar1.TabIndex = 0
'
'ToolBarButton4
'
Me.ToolBarButton4.Name = "ToolBarButton4"
Me.ToolBarButton4.Text = "Draw"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.BackColor = System.Drawing.SystemColors.ActiveCaptionText
Me.ClientSize = New System.Drawing.Size(292, 266)
Me.Controls.Add(Me.ToolBar1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
Me.PerformLayout()

End Sub

#End Region
Dim g As Graphics
Dim Tool As Tools
Dim Points() As Point
Dim NumberPoints As Integer = 0
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
g = Me.CreateGraphics()
End Sub

Private Sub ToolBar1_ButtonClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolBarButtonClickEventArgs) Handles ToolBar1.ButtonClick
If (ToolBar1.Buttons(0) Is e.Button) Then
Tool = Tools.Draw
End If
End Sub

Private Sub Form1_MouseMove(ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove
If Tool = Tools.Draw And e.Button = MouseButtons.Left Then
Dim p As New Point(e.X, e.Y)

ReDim Preserve Points(NumberPoints)

Points(NumberPoints) = p
NumberPoints += 1

If NumberPoints >= 2 Then
g.DrawLines(Pens.BlueViolet, Points)
End If
End If
End Sub

Private Sub Form1_Paint(ByVal sender As Object, _
ByVal e As System.Windows.Forms.PaintEventArgs) _
Handles MyBase.Paint
Select Case Tool
Case Tools.Draw
If NumberPoints >= 2 Then
g.DrawLines(Pens.BlueViolet, Points)
End If
End Select
End Sub

End Class
Enum Tools
Draw
End Enum


If this post helps you mark it as answer
Thanks

Rojasamala, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response