GdPicture.NET.14
GdPicture14 Namespace / GdPicturePDF Class / DrawRectangle Method
The horizontal (X) coordinate of the rectangle's starting point, expressed in the current units specified by the SetMeasurementUnit method with respect to the defined origin, related to the currently selected page.
The vertical (Y) coordinate of the rectangle's starting point, expressed in the current units specified by the SetMeasurementUnit method with respect to the defined origin, related to the currently selected page.
The width of the rectangle, expressed in the current units specified by the SetMeasurementUnit method.
The height of the rectangle, expressed in the current units specified by the SetMeasurementUnit method.
Set this parameter to true, if you want to fill the rectangle using the currently defined fill color, otherwise set it to false. You can set the fill color using the SetFillColor(Byte,Byte,Byte) method.
Set this parameter to true, if you want to stroke the rectangle (draw a boundary line along the rectangle) using the currently defined line color, otherwise set it to false. You can set the line color using the SetLineColor(Byte,Byte,Byte) method.
Example





In This Topic
DrawRectangle Method (GdPicturePDF)
In This Topic
Draws a rectangle on the currently selected page of the loaded PDF document according to what you have specified. The starting point (the upper left corner) of the rectangle and its dimensions need to be set in the current units defined in the PDF document with respect to the currently located origin, related to the actual page. The rectangle is clearly defined by the starting point and its width and height.

You can simply use the GetMeasurementUnit method to determine the currently defined units and you can easily use the SetMeasurementUnit method to reset the units according to your preference.

Syntax
'Declaration
 
Public Function DrawRectangle( _
   ByVal Left As Single, _
   ByVal Top As Single, _
   ByVal Width As Single, _
   ByVal Height As Single, _
   ByVal Fill As Boolean, _
   ByVal Stroke As Boolean _
) As GdPictureStatus
public GdPictureStatus DrawRectangle( 
   float Left,
   float Top,
   float Width,
   float Height,
   bool Fill,
   bool Stroke
)
public function DrawRectangle( 
    Left: Single;
    Top: Single;
    Width: Single;
    Height: Single;
    Fill: Boolean;
    Stroke: Boolean
): GdPictureStatus; 
public function DrawRectangle( 
   Left : float,
   Top : float,
   Width : float,
   Height : float,
   Fill : boolean,
   Stroke : boolean
) : GdPictureStatus;
public: GdPictureStatus DrawRectangle( 
   float Left,
   float Top,
   float Width,
   float Height,
   bool Fill,
   bool Stroke
) 
public:
GdPictureStatus DrawRectangle( 
   float Left,
   float Top,
   float Width,
   float Height,
   bool Fill,
   bool Stroke
) 

Parameters

Left
The horizontal (X) coordinate of the rectangle's starting point, expressed in the current units specified by the SetMeasurementUnit method with respect to the defined origin, related to the currently selected page.
Top
The vertical (Y) coordinate of the rectangle's starting point, expressed in the current units specified by the SetMeasurementUnit method with respect to the defined origin, related to the currently selected page.
Width
The width of the rectangle, expressed in the current units specified by the SetMeasurementUnit method.
Height
The height of the rectangle, expressed in the current units specified by the SetMeasurementUnit method.
Fill
Set this parameter to true, if you want to fill the rectangle using the currently defined fill color, otherwise set it to false. You can set the fill color using the SetFillColor(Byte,Byte,Byte) method.
Stroke
Set this parameter to true, if you want to stroke the rectangle (draw a boundary line along the rectangle) using the currently defined line color, otherwise set it to false. You can set the line color using the SetLineColor(Byte,Byte,Byte) method.

Return Value

A member of the GdPictureStatus enumeration. If the method has been successfully followed, then the return value is GdPictureStatus.OK.

We strongly recommend always checking this status first.

Remarks
This method is only allowed for use with non-encrypted documents.
Example
How to draw stroked and filled rectangles. The example shows you reasonable combinations of the Fill and the Stroke parameters.
Dim caption As String = "Example: DrawRectangle"
Dim gdpicturePDF As New GdPicturePDF()
Dim status As GdPictureStatus = gdpicturePDF.NewPDF()
If status = GdPictureStatus.OK Then
    gdpicturePDF.SetOrigin(PdfOrigin.PdfOriginTopLeft)
    gdpicturePDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitCentimeter)
    If (gdpicturePDF.NewPage(PdfPageSizes.PdfPageSizeA4) = GdPictureStatus.OK) AndAlso
       (gdpicturePDF.SetLineColor(255, 140, 0) = GdPictureStatus.OK) AndAlso 'the color used to stroke the rectangles
       (gdpicturePDF.SetLineWidth(0.2F) = GdPictureStatus.OK) AndAlso 'the line width used to stroke
       (gdpicturePDF.SetFillColor(153, 50, 204) = GdPictureStatus.OK) AndAlso 'the color used to fill the rectangles
       (gdpicturePDF.DrawRectangle(2, 2, 17, 25, False, True) = GdPictureStatus.OK) AndAlso
       (gdpicturePDF.DrawRectangle(4, 4, 12, 20, True, True) = GdPictureStatus.OK) AndAlso
       (gdpicturePDF.SetFillColor(255, 255, 0) = GdPictureStatus.OK) AndAlso
       (gdpicturePDF.DrawRectangle(6, 6, 8, 12, True, False) = GdPictureStatus.OK) Then
        status = gdpicturePDF.SaveToFile("test_DrawRectangle.pdf")
        If status = GdPictureStatus.OK Then
            MessageBox.Show("The example has been followed successfully and the file has been saved.", caption)
        Else
            MessageBox.Show("The example has been followed successfully, but the file can't be saved. Status: " + status.ToString(), caption)
        End If
    Else
        MessageBox.Show("The example has not been followed successfully." + vbCrLf + "The last known status is " + gdpicturePDF.GetStat().ToString(), caption)
    End If
Else
    MessageBox.Show("The NewPDF() method has failed with the status: " + status.ToString(), caption)
End If
gdpicturePDF.Dispose()
string caption = "Example: DrawRectangle";
GdPicturePDF gdpicturePDF = new GdPicturePDF();
GdPictureStatus status = gdpicturePDF.NewPDF();
if (status == GdPictureStatus.OK)
{
    gdpicturePDF.SetOrigin(PdfOrigin.PdfOriginTopLeft);
    gdpicturePDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitCentimeter);
    if ((gdpicturePDF.NewPage(PdfPageSizes.PdfPageSizeA4) == GdPictureStatus.OK) &&
        (gdpicturePDF.SetLineColor(153, 50, 204) == GdPictureStatus.OK) && //the color used to stroke the rectangles
        (gdpicturePDF.SetLineWidth(0.2f) == GdPictureStatus.OK) && //the line width used to stroke
        (gdpicturePDF.SetFillColor(153, 50, 204) == GdPictureStatus.OK) && //the color used to fill the rectangles
        (gdpicturePDF.DrawRectangle(2, 2, 17, 25, false, true) == GdPictureStatus.OK) &&
        (gdpicturePDF.DrawRectangle(4, 4, 12, 20, true, true) == GdPictureStatus.OK) &&
        (gdpicturePDF.SetFillColor(255, 255, 0) == GdPictureStatus.OK) &&
        (gdpicturePDF.DrawRectangle(6, 6, 8, 12, true, false) == GdPictureStatus.OK))
    {
        status = gdpicturePDF.SaveToFile("test_DrawRectangle.pdf");
        if (status == GdPictureStatus.OK)
            MessageBox.Show("The example has been followed successfully and the file has been saved.", caption);
        else
            MessageBox.Show("The example has been followed successfully, but the file can't be saved. Status: " + status.ToString(), caption);
    }
    else
        MessageBox.Show("The example has not been followed successfully.\nThe last known status is " + gdpicturePDF.GetStat().ToString(), caption);
}
else
    MessageBox.Show("The NewPDF() method has failed with the status: " + status.ToString(), caption);
gdpicturePDF.Dispose();
See Also