![]() ' Control's client coordinates to screen coordinates.ĬontrolRectangle = Controls(i).RectangleToScreen _ ' The method uses the RectangleToScreen method to convert the ![]() ' Find out which controls intersect the rectangle and change their color. ' If the MouseUp event occurs, the user is not dragging. Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As _ ' Draw the new rectangle by calling DrawReversibleFrame again. TheRectangle = New Rectangle(startPoint.X, startPoint.Y, _ ' Calculate the endpoint and dimensions for the new rectangle,ĭim endPoint As Point = CType(sender, Control).PointToScreen(New Point(e.X, e.Y))ĭim width As Integer = endPoint.X - startPoint.Xĭim height As Integer = endPoint.Y - startPoint.Y ' Hide the previous rectangle by calling the DrawReversibleFrameĬontrolPaint.DrawReversibleFrame(theRectangle, Me.BackColor, _ ' If the mouse is being dragged, undraw and redraw the rectangle Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As _ StartPoint = control.PointToScreen(New Point(e.X, e.Y)) ' Calculate the startPoint by using the PointToScreen ' by using the PointToScreen method to convert form coordinates toĭim control As Control = CType(sender, Control) ' Set the isDrag variable to true and get the starting point Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As _ ' rectangle intersects a control's client rectangle, theĭim theRectangle As New rectangle(New Point(0, 0), New Size(0, 0)) ' the user to use the mouse to resize the rectangle. ' The following three methods will draw a rectangle and allow TheRectangle = new Rectangle(0, 0, 0, 0) If (controlRectangle.IntersectsWith(theRectangle)) Private void Form1_MouseUp(object sender,ĬontrolRectangle = Controls.RectangleToScreen TheRectangle = new Rectangle(startPoint.X, Point endPoint = ((Control) sender).PointToScreen(new Point(e.X, e.Y)) ![]() DrawReversibleFrame method with the same parameters.ĬontrolPaint.DrawReversibleFrame(theRectangle, Hide the previous rectangle by calling the Private void Form1_MouseMove(object sender, StartPoint = control.PointToScreen(new Point(e.X, e.Y)) Private void Form1_MouseDown(object sender, Rectangle theRectangle = new Rectangle(new Point(0, 0), new Size(0, 0)) If ( controlRectangle.IntersectsWith( theRectangle ) )Ĭontrols->BackColor = Color::BurlyWood method to convert the Control's client coordinatesĬontrolRectangle = Controls->RectangleToScreen( Controls->ClientRectangle ) Find out which controls intersect the rectangle and If the MouseUp event occurs, the user is not dragging. Void Form1_MouseUp( Object^ /*sender*/, System::Windows::Forms::MouseEventArgs^ /*e*/ ) Draw the new rectangle by calling DrawReversibleFrame TheRectangle = Rectangle(startPoint.X,startPoint.Y,width,height) Point endPoint = this->PointToScreen( Point(e->X,e->Y) ) rectangle, again using the PointToScreen method. Calculate the endpoint and dimensions for the new undraw and redraw the rectangle as the mouse moves.ĬontrolPaint::DrawReversibleFrame( theRectangle, this->BackColor, FrameStyle::Dashed ) Void Form1_MouseMove( Object^ /*sender*/, System::Windows::Forms::MouseEventArgs^ e ) StartPoint = control->PointToScreen( Point(e->X,e->Y) ) Calculate the startPoint by using the PointToScreen by using the PointToScreen method to convert form Set the isDrag variable to true and get the starting point Void Form1_MouseDown( Object^ sender, System::Windows::Forms::MouseEventArgs^ e ) rectangle intersects a control's client rectangle, the the user to use the mouse to resize the rectangle. The following three methods will draw a rectangle and allow This example requires that the MouseDown, MouseMove, and MouseUp events are connected to the event handlers defined in the example. To run the example, paste the following code in a form called Form1 containing several controls. The following code example demonstrates how to use the BackColor, RectangleToScreen, PointToScreen, MouseButtons, ControlPaint.DrawReversibleFrame, and Rectangle.IntersectsWith members. A Rectangle that represents the converted Rectangle, p, in screen coordinates.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |