Mouse draw Using the mouse and a palette to make a picture.

Slides:



Advertisements
Similar presentations
Lists, Loops, Validation, and More
Advertisements

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 5- 1 STARTING OUT WITH Visual Basic 2008 FOURTH EDITION Tony Gaddis.
Introduction to Macromedia Director 8.5 – Lingo
BTEC 149. Windows Desktop Click on the Start Button.
Using the SmartPLS Software
COMPUTER PROGRAMMING I Objective 8.03 Apply Animation and Graphic Methods in a Windows Form (4%)
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 21 - “Cat and Mouse” Painter Application.
1 VCAM Technical Forum 2006VCAM\10_Oct\Technical Forum001 – 5/13/2015 1:55 AM Common PowerPoint Challenges Date: 04/31/2006.
Making a cartoon or slideshow. Aside VB comments An apostrophe starts a comment to end of line Some of the following slides have code with comments in.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Painter Application Introducing Graphics with Windows Presentation Foundation.
Mouse event handling Mouse events( delegates EventHandler, event arguments EventArgs) MouseEnter: raised if the mouse cursor enters the area of the control.
Control structures Part 2 iteration control To enable repetition of a statement block.
Odds and Ends Component Tray Menu and contextmenu Splash Screen.
An array of controls Not particularly convenient in VB Examples: array of pictureboxes Array of textboxes Notes on Concentration game (a possible final.
Events. Events Single Event Handlers Click Event Mouse Events Key Board Events Create and handle controls in runtime Outline.
ABC’s of PowerPoint (Office 2007) Part 1: Basic Vocabulary Part 2: Cursors Part 3: Insert Your Text Part 4: Insert Your Pictures Part 5: Basic Tools &
Office 2003 Post-Advanced Concepts and Techniques M i c r o s o f t Word Project 8 Working with Macros and Visual Basic for Applications (VBA)
Chapter 7 Creating a Self-Running Presentation Containing Animation
Mr. Potato Head The objective of this tutorial is to cut an image and assemble Mr. Potato Head using various tools in Adobe Photoshop Elements 2.0.
CS0004: Introduction to Programming Events. Review  Event Procedure  A set of instructions to be executed when a certain event happens.  Many event-driven.
Making a Book Report in Alice by Jenna Hayes Under the direction of Professor Susan Rodger Duke University, June 2010.
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
Visual Basic Fundamental Concepts. Integrated Development Enviroment Generates startup form for new project on which to place controls. Features toolbox.
05/09/ Introducing Visual Basic Sequence Programming.
JQuery Page Slider. Our goal is to get to the functionality of the Panic Coda web site.Panic Coda web site.
Microsoft Visual Basic 2012 Using Procedures and Exception Handling CHAPTER SEVEN.
CIS 338: Creating ActiveX Controls Dr. Ralph D. Westfall March, 2003.
Microsoft Visual Basic 2008 CHAPTER 8 Using Procedures and Exception Handling.
InvEasy (Project1) Please use speaker notes for additional information!
© 2006 Lawrenceville Press Slide 1 Chapter 3 Visual Basic Interface.
Chapter 3 Introducing Visual Basic.NET. 3.1 Visual Basic.NET Windows Programming -Used to create Windows, Web, and Console applications -Uses predefined.
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
Multiple Forms, Container Controls, AddHandler This presentation is based on the Forms and ContainerControls VB Projects 1.
ESL PowerPoint Demonstration The Effective Use of Presentation Software in the ESL Classroom By Daniel Craig University of Illinois ESL 401 J.
06/10/ Working with Data. 206/10/2015 Learning Objectives Explain the circumstances when the following might be useful: Disabling buttons and.
3–D Helium Molecule Tutorial Alice Project Duke University Professor Susan H. Rodger Gaetjens Lezin June 2008.
Visual Basic .NET BASICS
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 7 Using Menus, Common Dialogs, Procedures, Functions, and Arrays.
© Paradigm Publishing Inc. MICROSOFT WINDOWS XP MAINTAINING FILES AND CUSTOMIZING WINDOWS Section 2.
Windows Forms. Architecture Wrapper around WIN32API Part of the.NET Framework Code can be in C# or VB Toolbox has forms elements (buttons, etc.) Dragging.
Some graphics. Projects included A slideshow a dark moon moving phases of the moon billiards Your own icons and bitmaps Pie chart.
Working with the VB IDE. Running a Program u Clicking the”start” tool begins the program u The “break” tool pauses a program in mid-execution u The “end”
BIM211 – Visual Programming Interacting with Users Graphics 1.
Microsoft Access 2010 Chapter 8 Advanced Form Techniques.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 21 - “Cat and Mouse” Painter Application.
CSC 230 (Blum)1 Visual Basic 2005 Hello World Fall 2005 T. Blum.
Visual Basic Programming Introduction VB is one of the High level language VB has evolved from the BASIC language. BASIC stands for Beginners All-purpose.
Chapter 3 - VB.NET by Schneider1 Chapter 3 – Fundamentals of Programming in VB.NET Part I VB.NET Controls VB.NET Events.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 4 Working with Variables, Constants, Data Types, and Expressions.
1 PRESENTER NAME TITLE SUBTITLE Date:. MAIN SECTION (Title Slide)
Adding Text and Navigation to the Home Page – Lesson 51 Adding Text and Navigation to the Home Page Lesson 5.
Events Part I Mouse Events. Learning Objectives By the end of this lecture, you should be able to: – Understand what is meant by an ‘event’ – Appreciate.
 2002 Prentice Hall. All rights reserved. 1 Outline Mouse Event Handling Keyboard Event Handling Graphical User Interface Concepts:
Lecture Set 7 Procedures and Event Handlers Part B - The Structure of an Application Event Handlers.
CSC 230 (Blum)1 Visual Basic 2005 Hello World Fall 2005 T. Blum.
CIS 338: Events Dr. Ralph D. Westfall April, 2011.
National Diploma Unit 4 Introduction to Software Development Procedures and Functions.
Chapter 7 Multiple Forms, Modules, and Menus. Section 7.2 MODULES A module contains code—declarations and procedures—that are used by other files in a.
Computer Science Up Down Controls, Decisions and Random Numbers.
Adobe Photoshop CS5.
Multiple Forms and Menus
Computer Programming I
Visual studio 2010 SENG 403, Tutorial 2 SENG Winter 2011.
Using Procedures and Exception Handling
Gimp Guide Mr Hall.
Visual Basic Programming Chapter Four Notes Working with Variables, Constants, Data Types, and Expressions GROUPBOX CONTROL The _____________________________________.
Fonts, TabControl, ListBox
Overview of the IDE Visual Studio .NET is Microsoft’s Integrated Development Environment (IDE) for creating, running and debugging programs (also.
CPT 450 Computer Graphics 3rd Lecture.
Presentation transcript:

Mouse draw Using the mouse and a palette to make a picture

Lab completion is optional, but labs will help you understand the project Lab 1: Mouse draw (put dot on mousedown event) Lab 2: Modification of Lab 1. Now mouse draws two color dots: on mouseup or mousedown, put a dot Lab3: Revise lab two. only draw for mousemove event (preceded by mousedown) Project: Mousedraw with a draw panel, color and size radiobuttons

Lab1: Mouse draw dots

Click form.vb tab to expose form events

Pull down menu under Declarations to select a mouse event

In the code view: Under the menu bar icons and the view tabs there are two pull-down selectors. Select 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 Previous two slides added MouseDown event to the form itself.

MouseDown (on the form)…for example

For a draw dot on mousedown lab We select mousedown event on the form We define a colored circle (with a size)

Field declarations These two lines go in code view, below class declaration, above and not inside a sub: Private Const blobsize As Integer = 8 Private graphicsobj As Graphics = CreateGraphics() Notice that we did several things: 1.Declared constants whose values may not be changed 2.Initialized values at declaration time 3.Blobsize will be how many pixels wide your dot is 4.Graphicsobj is a Graphics thingy defined for your form.

Code View- recall entire statements must go on 1 line Public Class Form1 Private Const blobsize As Integer = 8 Private graphicsobj As Graphics = CreateGraphics() Private Sub Form1_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown graphicsobj.FillEllipse(New SolidBrush(Color.BlueViolet), e.X, e.Y, blobsize, blobsize) End Sub End Class Notice that e.x and e.y (mouseeventargs.x and mouseeventargs.y) return the current mouse position.

Lab1 completed – It is hard to draw a picture with purple dots

Lab2: Add a MouseUp event handler MouseUp event should put a green dot. It is still pretty hard to draw a picture in this environment

MouseUp event handler- Note that I renamed my form MouseDraw 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

Boolean data type A boolean is a variable that is true or false. It could be declared with Dim okay as Boolean We will add a variable to our project so we can decide when to put dots. If mouse is up – no dot, when mouse is moved, put dot(s).

Lab3: Don’t draw for mouseup event only for mousemove: field variables Private Const blobsize As Integer = 8 Private graphicsobj As Graphics = CreateGraphics() Private ShouldPaint As Boolean = False

New MouseUp event handler: whenever mouse is up, stop painting Private Sub frmMouseDraw_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseUp shouldpaint=false End Sub

Lab3: 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

Lab3 completed: Is this art?

Project: a mouse paint palette

Components on your form Put a Panel on the right – It is not a “visible” component but it occupies the entire right side of form. Resize the form to make the panel large. Two Groups of radio buttons for size of brush and color. Individual radio buttons as for VB project 2 Not shown in previous image: You should have a clear button to clear the drawing panel.

About components Be sure to drop your radio buttons on the form before button groups. Be sure to rename all your radio buttons. Put a group around the size buttons and a group around the color buttons. Not shown in my screenshot – put a clear button on the form. Name it btnClear. Panel on the right.

Adding a panel… it is a container in the toolbox

Panel renamed pnlDraw on right side of form

Some notes on mouse painter: Fields If you built the previous lab(s), you will have to modify the Const blobsize variable. Const means “not allowed to change” but we want the size to be changed by the radiobutton selection. Remove the word Const.

Drawing: Fields In our labs we used: Private graphicsobj As Graphics = CreateGraphics() This needs to be modified. Change it to: Private graphics As Graphics

Colors and sizes: Fields Add a color field value. This will be set in the radio buttons that control color. Declare it above your subs with Dim theColor as Color

coloring When you draw in mouseMoved event it will be something like: graphics.FillEllipse(New SolidBrush(theColor), e.X, e.Y, blobsize, blobsize)

More Subs in this application After properly naming your radio buttons, systematically go through double-clicking each radio-button to create a sub event handler for it.

Changing color and size theColor will be changed in the color radiobuttons. Your color radio buttons will have code in theirs subs like: theColor=Color.red In size radio-buttons, set blobsize to 3 or 4 pixels for small, 5 or 6 pixels for medium and 8+ pixels for large “blobs”…for example, for medium: blobSize=7

Form load In your project, the panel, not the form, will have the graphics object. Double-click the form itself. This opens up a form load sub. In the formload sub add the code to create the graphics for the panel (put your panel name where it says pnlName): graphics =pnlName.creategraphics()

More notes on mouse painter subs: mouse events go on the panel! It uses a panel, and you’ll have to use get the correct graphics object instead of creategraphics() from Lab1. Similarly, you’ll have to add the mouseUp, mouseDown and MouseMove events associated with the panel, not the form. See screenshot in next slide.

Be sure to add the mouse events to the panel, not the form

Clear the panel Put a button on the form to clear the image. Use pnlDraw.refresh() to clear the panel. Here, I have named my panel pnlDraw