Presentation is loading. Please wait.

Presentation is loading. Please wait.

Mouse event handling Mouse events( delegates EventHandler, event arguments EventArgs) MouseEnter: raised if the mouse cursor enters the area of the control.

Similar presentations


Presentation on theme: "Mouse event handling Mouse events( delegates EventHandler, event arguments EventArgs) MouseEnter: raised if the mouse cursor enters the area of the control."— Presentation transcript:

1 Mouse event handling Mouse events( delegates EventHandler, event arguments EventArgs) MouseEnter: raised if the mouse cursor enters the area of the control MoueLeave: raised if the mouse cursor leaves the area of control

2 Mouse events(delegates MouseEventHandler, event arguments MouseEventArgs) MouseDown:raised if the mouse button is pressed while its cursor is over the area of the control MouseHover:Raised if the mouse cursor hovers over the area of the control MouseMove: Raised if the mouse cursor is moved while in the area of the control MouseUp: Raised if the mouse button is released when the cursor is over the area of the control

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

4 PictureBoxes 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  SizeMode: controls image sizing and positioning

5 SizeMode Normal: (default) puts image in top-left corner of picture box StretchImage:resizes image to fit in picture box CenterImage: puts image in middle AutoSize: resizes picture box to hold image

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

7 MouseEnter, MouseLeave Write proper code so that When mouse enter the first label, the pictureBox will show the first picture When mouse enter the second label, it will show the second picture When mouse enter the third label, it will show the third label

8 Set the image property To set the image property to an image file imagePictureBox->Image = Image::FromFile(String::Concat(Directory::GetCurre ntDirectory(), S”\\image\\myboy.jpeg”) ; Where imagePictureBox is the name of control (The PictureBox) Directory::GetCurrentDirectory() retrieve the current directory name, ie. Where your project is created image is the folder where all image file are stored. myboy.jpeg is an example of image file name

9 MouseEnter to the first Label Assume the first Label has name lb_pic1, picture Box has name pic1 Go to property window, click the list of event, and double click on the event MouseEnter private: System::Void lb_pic1_MouseEnter(System::Object *sender, System::Windows::EventArg *e) { pic1->Image = Image::FromFile(String::Concat(Directory::GetCurre ntDirectory(), S\\image\\Myboy.jpeg);\\image\\Myboy.jpeg }

10 Graphics Create a Graphics class object and use it to draw on the form Graphics *graphic = CreateGraphics(); Methods of Graphics  FillEllipse draws an ellipse  It takes 5 arguments SolidBrush object which determine the color of the shape drawn X coordinator of center position Y coordinator of center position X axis of ellipse Y axis of ellipse graphics->FillEllipse(new SolidBrush(Color::BlueViolet), e->X, e->Y,4,4);

11 More drawing methods FillPie(SolidBrush, int,int,int,int,int,int) FillRectangle(Brush, int,int,int,int); drawEllipse( …) drawCurve(…) drawPolygon(…) drawRetangle(…)


Download ppt "Mouse event handling Mouse events( delegates EventHandler, event arguments EventArgs) MouseEnter: raised if the mouse cursor enters the area of the control."

Similar presentations


Ads by Google