Shape.PointToScreen, méthode
Calcule l'emplacement du point client spécifié en coordonnées d'écran.
Espace de noms : Microsoft.VisualBasic.PowerPacks
Assembly : Microsoft.VisualBasic.PowerPacks.Vs (dans Microsoft.VisualBasic.PowerPacks.Vs.dll)
Syntaxe
'Déclaration
Public Function PointToScreen ( _
position As Point _
) As Point
public Point PointToScreen(
Point position
)
public:
Point PointToScreen(
Point position
)
member PointToScreen :
position:Point -> Point
public function PointToScreen(
position : Point
) : Point
Paramètres
- position
Type : System.Drawing.Point
Valeur de retour
Type : System.Drawing.Point
Point qui représente le Point converti, p, en coordonnées d'écran.
Exemples
L'exemple suivant montre comment utiliser les méthodes d'PointToScreen et d'RectangleToScreen pour modifier la couleur d'RectangleShape lorsqu'une opération glisser se termine sur sa zone client.Cet exemple requiert que vous avez un contrôle d'RectangleShape nommé RectangleShape1 sur un formulaire et que sa propriété d'BackStyle soit définie à Opaque.
Public isDrag As Boolean = True
Public theRectangle As System.Drawing.Rectangle
Private Sub Form1_MouseMove(
ByVal sender As Object,
ByVal e As System.Windows.Forms.MouseEventArgs
) Handles RectangleShape1.MouseMove
' If the mouse is being dragged, undraw and redraw the rectangle
' while the mouse moves.
If (isDrag) Then
' Hide the previous rectangle by calling the
' DrawReversibleFrame method, using the same parameters.
ControlPaint.DrawReversibleFrame(theRectangle, Me.BackColor,
FrameStyle.Dashed)
' Calculate the endpoint and dimensions for the new rectangle,
' again by using the PointToScreen method.
Dim startPoint As Point = New Point(RectangleShape1.Width,
RectangleShape1.Height)
Dim endPoint As Point = RectangleShape1.PointToScreen(New Point(e.X, e.Y))
Dim width As Integer = endPoint.X - startPoint.X
Dim height As Integer = endPoint.Y - startPoint.Y
theRectangle = New Rectangle(startPoint.X, startPoint.Y,
width, height)
' Draw the new rectangle by calling DrawReversibleFrame again.
ControlPaint.DrawReversibleFrame(theRectangle, Me.BackColor,
FrameStyle.Dashed)
End If
End Sub
Private Sub Form1_MouseUp() Handles RectangleShape1.MouseUp
' If the MouseUp event occurs, the user is not dragging.
isDrag = False
' Draw the rectangle to be evaluated. Set a dashed frame style
' by using the FrameStyle enumeration.
ControlPaint.DrawReversibleFrame(theRectangle, Me.BackColor,
FrameStyle.Dashed)
' Find out which controls intersect the rectangle, and change
' their colors.
' The method uses the RectangleToScreen method to convert the
' control's client coordinates to screen coordinates.
Dim controlRectangle As Rectangle
controlRectangle = RectangleShape1.RectangleToScreen(
RectangleShape1.ClientRectangle)
If controlRectangle.IntersectsWith(theRectangle) Then
RectangleShape1.BackColor = Color.BurlyWood
End If
' Reset the rectangle.
theRectangle = New Rectangle(0, 0, 0, 0)
End Sub
public bool isDrag = true;
public System.Drawing.Rectangle theRectangle;
private void Form1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
// If the mouse is being dragged, undraw and redraw the rectangle
// while the mouse moves.
if (isDrag)
// Hide the previous rectangle by calling the
// DrawReversibleFrame method, using the same parameters.
{
ControlPaint.DrawReversibleFrame(theRectangle, this.BackColor, FrameStyle.Dashed);
// Calculate the endpoint and dimensions for the new rectangle,
// again by using the PointToScreen method.
Point startPoint = new Point(rectangleShape1.Width, rectangleShape1.Height);
Point endPoint = rectangleShape1.PointToScreen(new Point(e.X, e.Y));
int width = endPoint.X - startPoint.X;
int height = endPoint.Y - startPoint.Y;
theRectangle = new Rectangle(startPoint.X, startPoint.Y, width, height);
// Draw the new rectangle by calling DrawReversibleFrame again.
ControlPaint.DrawReversibleFrame(theRectangle, this.BackColor, FrameStyle.Dashed);
}
}
private void Form1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
// If the MouseUp event occurs, the user is not dragging.
isDrag = false;
// Draw the rectangle to be evaluated. Set a dashed frame style
// by using the FrameStyle enumeration.
ControlPaint.DrawReversibleFrame(theRectangle, this.BackColor, FrameStyle.Dashed);
// Find out which controls intersect the rectangle, and change
// their colors.
// The method uses the RectangleToScreen method to convert the
// control's client coordinates to screen coordinates.
Rectangle controlRectangle;
controlRectangle = rectangleShape1.RectangleToScreen(rectangleShape1.ClientRectangle);
if (controlRectangle.IntersectsWith(theRectangle))
{
rectangleShape1.BackColor = Color.BurlyWood;
}
// Reset the rectangle.
theRectangle = new Rectangle(0, 0, 0, 0);
}
Sécurité .NET Framework
- Confiance totale accordée à l'appelant immédiat. Ce membre ne peut pas être utilisé par du code d'un niveau de confiance partiel. Pour plus d'informations, consultez Utilisation de bibliothèques à partir de code d'un niveau de confiance partiel.
Voir aussi
Référence
Microsoft.VisualBasic.PowerPacks, espace de noms
Autres ressources
Comment : dessiner des lignes avec le contrôle LineShape (Visual Studio)
Comment : dessiner des formes avec les contrôles OvalShape et RectangleShape (Visual Studio)