Compartir a través de


Shape.RectangleToScreen (Método)

Calcula el tamaño y la ubicación del rectángulo de cliente especificado, en coordenadas de pantalla.

Espacio de nombres:  Microsoft.VisualBasic.PowerPacks
Ensamblado:  Microsoft.VisualBasic.PowerPacks.Vs (en Microsoft.VisualBasic.PowerPacks.Vs.dll)

Sintaxis

'Declaración
Public Function RectangleToScreen ( _
    rect As Rectangle _
) As Rectangle
public Rectangle RectangleToScreen(
    Rectangle rect
)
public:
Rectangle RectangleToScreen(
    Rectangle rect
)
member RectangleToScreen : 
        rect:Rectangle -> Rectangle 
public function RectangleToScreen(
    rect : Rectangle
) : Rectangle

Parámetros

Valor devuelto

Tipo: System.Drawing.Rectangle
Rectangle que representa el objeto Rectangle convertido, p, en coordenadas de pantalla.

Comentarios

Algunas propiedades y métodos expresan coordenadas relativas a la esquina superior izquierda de la pantalla; otros se expresan en relación con el formulario del cliente.los métodos de RectangleToClient y de RectangleToScreen se pueden utilizar para convertir entre los dos.

Ejemplos

El ejemplo siguiente se muestra cómo utilizar los métodos de PointToScreen y de RectangleToScreen para cambiar el color de RectangleShape cuando finaliza una operación de arrastre en el área cliente.Este ejemplo requiere tener un control de RectangleShape denominado RectangleShape1 en un formulario y que la propiedad de BackStyle está establecida en 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);
}

Seguridad de .NET Framework

Vea también

Referencia

Shape Clase

Microsoft.VisualBasic.PowerPacks (Espacio de nombres)

Otros recursos

Cómo: Dibujar líneas con el control LineShape (Visual Studio)

Cómo: Dibujar formas con los controles OvalShape y RectangleShape (Visual Studio)

Introducción a los controles de líneas y formas (Visual Studio)