Visualbasic7
Download
1 / 24

graphics - PowerPoint PPT Presentation


  • 322 Views
  • Updated 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 'graphics' - paul


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 l.jpg

VisualBasic7

Mouse and key events

Some graphics


Index of projects l.jpg
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 l.jpg
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 l.jpg
For a draw dot on mousedown project

  • We select mousedown event on the form

  • We define a colored circle (size)



Field declarations l.jpg
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 l.jpg
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 l.jpg
MouseUp event handler one line

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 l.jpg
Should mouse draw? one line

Private Const blobsize As Integer = 8

Private graphicsobj As Graphics = CreateGraphics()

Private ShouldPaint As Boolean = False


New mouseup event handler l.jpg
New MouseUp event handler one line

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 l.jpg
Add mouse move event handler and adjust your other events one line

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 l.jpg
Distinguishing mouse buttons inside your event handler one line

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 l.jpg
Clear the panel one line

  • Put a button on the form to clear the image

  • Use panel.refresh() to clear the panel


Some notes on mouse painter l.jpg
Some notes on mouse painter one line

  • 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.



Keyprocessing l.jpg
Keyprocessing one line



Keypress l.jpg
Keypress one line

  • 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.


ad