Condividi tramite


Metodo Shape.RectangleToScreen

Calcola le dimensioni e la posizione del rettangolo client specificato nelle coordinate dello schermo.

Spazio dei nomi:  Microsoft.VisualBasic.PowerPacks
Assembly:  Microsoft.VisualBasic.PowerPacks.Vs (in Microsoft.VisualBasic.PowerPacks.Vs.dll)

Sintassi

'Dichiarazione
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

Parametri

  • rect
    Tipo: Rectangle

    Oggetto Rectangle delle coordinate dello schermo da convertire.

Valore restituito

Tipo: Rectangle
Oggetto Rectangle che rappresenta l'oggetto Rectangle convertito, p, nelle coordinate dello schermo.

Note

Alcune proprietà e metodi express coordinate rispetto all'angolo superiore sinistro dello schermo. altri esprimerle rispetto al modulo client. Il RectangleToClient e RectangleToScreen metodi possono essere utilizzati per la conversione tra i due.

Esempi

Nell'esempio seguente viene illustrato come utilizzare il PointToScreen e RectangleToScreen metodi per modificare il colore di un RectangleShape quando un'operazione di trascinamento termina sulla relativa area client. Si suppone di disporre di un RectangleShape controllo denominato RectangleShape1 in un form e che il BackStyle è impostata su 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);
}

Sicurezza di .NET Framework

Vedere anche

Riferimenti

Shape Classe

Spazio dei nomi Microsoft.VisualBasic.PowerPacks

Altre risorse

Procedura: disegnare linee con il controllo LineShape (Visual Studio)

Procedura: disegnare forme con i controlli OvalShape e RectangleShape (Visual Studio)

Introduzione ai controlli Line e Shape (Visual Studio)