visualbasic7 l.
Download
Skip this Video
Download Presentation
VisualBasic7

Loading in 2 Seconds...

play fullscreen
1 / 24

VisualBasic7 - PowerPoint PPT Presentation


  • 323 Views
  • Uploaded on

VisualBasic7 Mouse and key events Some graphics Index of projects Mouse draw (dots) Mouse draw: two color dots Mousedraw with a draw panel, color and size radiobuttons KeyEvents Mouse draw In the code view: In the code view:

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'VisualBasic7' - paul


Download Now An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
visualbasic7

VisualBasic7

Mouse and key events

Some graphics

index of projects
Index of projects
  • Mouse draw (dots)
  • Mouse draw: two color dots
  • Mousedraw with a draw panel, color and size radiobuttons
  • KeyEvents
in the code view5
In the code view:
  • Under the menu bar icons and the view tabs there are two pull-down selectors.
  • Select events for the component you want to add an event to in the left pull-down menu
  • Select the event you want in the right pull-down menu.
  • This will paste in a sub template
for a draw dot on mousedown project
For a draw dot on mousedown project
  • We select mousedown event on the form
  • We define a colored circle (size)
field declarations
Field declarations

Private Const blobsize As Integer = 8

Private graphicsobj As Graphics = CreateGraphics()

Notice that we did several things:

  • Declared constants whose values may not be changed
  • Initialized values at declaration time
mousedown event code remember about putting statements on one line
Mousedown event code- remember about putting statements on one line

Private Sub frmMouseDraw_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown

graphicsobj.FillEllipse(New SolidBrush(Color.BlueViolet), e.X, e.Y, blobsize, blobsize)

End Sub

Notice that e.x and e.y (mouseeventargs.x and mouseeventargs.y) return the current mouse position.

mouseup event handler
MouseUp event handler

Private Sub frmMouseDraw_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseUp

graphicsobj.FillEllipse(New SolidBrush(Color.Green), e.X, e.Y, blobsize, blobsize)

End Sub

should mouse draw
Should mouse draw?

Private Const blobsize As Integer = 8

Private graphicsobj As Graphics = CreateGraphics()

Private ShouldPaint As Boolean = False

new mouseup event handler
New MouseUp event handler

Private Sub frmMouseDraw_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseUp

shouldpaint=false

End Sub

add mouse move event handler and adjust your other events
Add mouse move event handler and adjust your other events

Private Sub frmMouseDraw_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown

ShouldPaint = True ‘paint when mouse down

End Sub

Private Sub frmMouseDraw_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseUp

ShouldPaint = False ‘don’t paint for mouse up

End Sub

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

If ShouldPaint Then

graphicsobj.FillEllipse(New SolidBrush(Color.BlueViolet), e.X, e.Y, blobsize, blobsize)

End If

End Sub

distinguishing mouse buttons inside your event handler
Distinguishing mouse buttons inside your event handler

Suppose the mouseeventarg is called e (the default name VB gives it):

If e.button=mousebuttons.left then

‘handle left button stuff

Else if e.button =mousebuttons.right then

‘handle right button

End if

clear the panel
Clear the panel
  • Put a button on the form to clear the image
  • Use panel.refresh() to clear the panel
some notes on mouse painter
Some notes on mouse painter
  • It uses a panel, and you’ll have to use panelname.creategraphics() to get the correct graphics object.
  • Similarly, you’ll have to define the mouseUp, mouseDown and MouseMove events associated with the panel, not the form.
keypress
Keypress
  • Keypress, keyup and keydown can be added to your form’s events
  • Event.KeyChar returns the keypress value.
  • In this example, it is simply appended to a String and displayed.
  • The clear button sets the string to empty and gives the textbox the focus.
  • The keypress event appends a char to message and displays it in the textbox.