How To Draw Rectangle In Dev C%2b%2b
DEV Community is a community. Draws the outline of a rectangle while SDLRenderFillRect draws a rectangle filled. Before we draw any. (and with C, too) 2.
In the previous lesson, we have learned how to create Graphics and the Pen objects to draw straight lines in Visual Basic 2017. Now we shall learn how to draw rectangles.
27.1 Drawing A Rectangle
Method 1
- The method of the Graphics object to draw the rectangle is DrawRectangle.The syntax is: myGrapphics.DrawRectangle (myPen, X, Y, width, height).myGraphics is the variable name of the Graphics object and myPen is the variable name of the Pen object created by you. You can use any valid and meaningful variable names.
- C tutorial - draw basic shapes Draw basic shapes In the previous page, you leant how to install freeglut library with Dev-Cpp and write a simple program to display a teapot, and understand commands frequently used in drawing objects, on the window.
The first is to draw a rectangle directly using the DrawRectangle method by specifying its upper-left corner’s coordinate and its width and height. The method of the Graphics object to draw the rectangle is DrawRectangle.The syntax is:
*myGraphics is the variable name of the Graphics object and myPen is the variable name of the Pen object created by you. You can use any valid and meaningful variable names. X, Y is the coordinate of the upper left corner of the rectangle while width and height are the width and height of the rectangle.
The code is as follows:
Method 2
How To Draw Rectangle In Dev C++ Codes
The second method is to create a rectangle object first and then draw this rectangle using the DrawRectangle method. The syntax is as shown below:
where myRectangle is the rectangle object created by you, the user.
The code to create a rectangle object is as shown below:
You can also create a rectangle object using a one-line code as follows:
and the code to draw the above rectangle is
27.2 Customizing Line Style of the Pen Object
The shape we draw so far is drawn with a solid line. However, we can customize the line style of the Pen object so that we can draw a dotted line, a line consisting of dashes and more. For example, the syntax to draw the dotted line is shown below:
Where the last argument Dot specifies a particular line DashStyle value, a line that makes up of dots here. Other DashStyles values are Dash, DashDot, DashDotDot and Solid.The following code draws a rectangle with a blue dotted line.
The output image is as shown in Figure 27.1
If you change the DashStyle value to DashDotDot, you will get the following rectangle:
-->The example in this section illustrates how to use the rectangle functions. It consists of the main window procedure from an application that enables the user to move and size a bitmap.
When the application starts, it draws a 32-pixel by 32-pixel bitmap in the upper left corner of the screen. Microsoft remote desktop mac os 10.6.8. The user can move the bitmap by dragging it. To size the bitmap, the user creates a target rectangle by dragging the mouse, then drags the bitmap and 'drops' it on the target rectangle. The application responds by copying the bitmap into the target rectangle.
How To Draw Rectangle In Dev C++ Download
The window procedure that allows the user to move and size the bitmap is given in the following example.