

' Calculate the endpoint and dimensions for the new rectangle, ' DrawReversibleFrame method, using the same parameters.ĬontrolPaint.DrawReversibleFrame(theRectangle, Me.BackColor, ' Hide the previous rectangle by calling the ' If the mouse is being dragged, undraw and redraw the rectangle TheRectangle = new Rectangle(0, 0, 0, 0) RectangleShape1.BackColor = Color.BurlyWood If (controlRectangle.IntersectsWith(theRectangle)) control's client coordinates to screen coordinates.ĬontrolRectangle = rectangleShape1.RectangleToScreen(rectangleShape1.ClientRectangle) The method uses the RectangleToScreen method to convert the Find out which controls intersect the rectangle, and change If the MouseUp event occurs, the user is not dragging. Private void Form1_MouseUp(object sender, e) Draw the new rectangle by calling DrawReversibleFrame again. TheRectangle = new Rectangle(startPoint.X, startPoint.Y, width, height) Point endPoint = rectangleShape1.PointToScreen(new Point(e.X, e.Y)) Point startPoint = new Point(rectangleShape1.Width, rectangleShape1.Height) again by using the PointToScreen method. Calculate the endpoint and dimensions for the new rectangle, DrawReversibleFrame method, using the same parameters.ĬontrolPaint.DrawReversibleFrame(theRectangle, this.BackColor, FrameStyle.Dashed) Hide the previous rectangle by calling the If the mouse is being dragged, undraw and redraw the rectangle Private void Form1_MouseMove(object sender, e) This example requires that you have a RectangleShape control named RectangleShape1 on a form and that its BackStyle property is set to Opaque.
#Visual basic power pack rectangle drag how to#
The following example demonstrates how to use the PointToScreen and RectangleToScreen methods to change the color of a RectangleShape when a drag operation ends over its client area. The RectangleToClient and RectangleToScreen methods can be used to convert between the two. Some properties and methods express coordinates relative to the upper-left corner of the screen others express them relative to the client form. The screen coordinate Rectangle to convert.Ī Rectangle that represents the converted Rectangle, p, in screen coordinates.

Namespace: Assembly: (in .dll) Syntax public Rectangle RectangleToScreen( Computes the size and location of the specified client rectangle in screen coordinates.
