Mouse event handling Mouse events delegates Event Handler

  • Slides: 11
Download presentation
Mouse event handling Mouse events( delegates Event. Handler, event arguments Event. Args) l Mouse.

Mouse event handling Mouse events( delegates Event. Handler, event arguments Event. Args) l Mouse. Enter: raised if the mouse cursor enters the area of the control l Moue. Leave: raised if the mouse cursor leaves the area of control l

Mouse events(delegates Mouse. Event. Handler, event arguments Mouse. Event. Args) Mouse. Down: raised if

Mouse events(delegates Mouse. Event. Handler, event arguments Mouse. Event. Args) Mouse. Down: raised if the mouse button is pressed while its cursor is over the area of the control l Mouse. Hover: Raised if the mouse cursor hovers over the area of the control l Mouse. Move: Raised if the mouse cursor is moved while in the area of the control l Mouse. Up: Raised if the mouse button is released when the cursor is over the area of the control l

Mouse. Event. Args properties Button: Mouse button that was pressed(left, right, middle or none)

Mouse. Event. Args properties Button: Mouse button that was pressed(left, right, middle or none) l Clicks: the number of times the mouse button (either mouse button) was clicked l X: the x-coordinate of the event, relative to the control l Y: the y-coordinate of the event, relative to control l

Picture. Boxes l l l A picture box displays an image. You can find

Picture. Boxes l l l A picture box displays an image. You can find it in toolbox, drag it in the form Images can be. bmp, . gif, . jpg, jpeg GIF and JPEG files are widely used image file format Properties ¡ ¡ Image: image to display in the picture box Size. Mode: controls image sizing and positioning

Size. Mode l Normal: (default) puts image in top-left corner of picture box l

Size. Mode l Normal: (default) puts image in top-left corner of picture box l Stretch. Image: resizes image to fit in picture box l Center. Image: puts image in middle l Auto. Size: resizes picture box to hold image

Design GUI that contains one Picture. Box and three labels( labels show name of

Design GUI that contains one Picture. Box and three labels( labels show name of the images, set the anchor property of the Picture. Box so that it resize when the form resize

Mouse. Enter, Mouse. Leave l Write proper code so that l When mouse enter

Mouse. Enter, Mouse. Leave l Write proper code so that l When mouse enter the first label, the picture. Box will show the first picture l When mouse enter the second label, it will show the second picture l When mouse enter the third label, it will show the third label

Set the image property l To set the image property to an image file

Set the image property l To set the image property to an image file image. Picture. Box->Image = Image: : From. File(String: : Concat(Directory: : Get. Curre nt. Directory(), S”\image\myboy. jpeg”) ; Where image. Picture. Box is the name of control (The Picture. Box) l Directory: : Get. Current. Directory() retrieve the current directory name, ie. Where your project is created l image is the folder where all image file are stored. l myboy. jpeg is an example of image file name l

Mouse. Enter to the first Label Assume the first Label has name lb_pic 1,

Mouse. Enter to the first Label Assume the first Label has name lb_pic 1, picture Box has name pic 1 l Go to property window, click the list of event, and double click on the event Mouse. Enter l private: System: : Void lb_pic 1_Mouse. Enter(System: : Object *sender, System: : Windows: : Event. Arg *e) { pic 1 ->Image = Image: : From. File(String: : Concat(Directory: : Get. Curre nt. Directory(), S\image\Myboy. jpeg); }

Graphics Create a Graphics class object and use it to draw on the form

Graphics Create a Graphics class object and use it to draw on the form Graphics *graphic = Create. Graphics(); l Methods of Graphics ¡ Fill. Ellipse draws an ellipse ¡ It takes 5 arguments l Solid. Brush object which determine the color of the shape drawn l X coordinator of center position l Y coordinator of center position l X axis of ellipse l Y axis of ellipse graphics->Fill. Ellipse(new Solid. Brush(Color: : Blue. Violet), e->X, e->Y, 4, 4); l

More drawing methods l Fill. Pie(Solid. Brush, int, int, int) l Fill. Rectangle(Brush, int,

More drawing methods l Fill. Pie(Solid. Brush, int, int, int) l Fill. Rectangle(Brush, int, int); l draw. Ellipse( …) l draw. Curve(…) l draw. Polygon(…) l draw. Retangle(…)