VB6 gives you the flexibility and power to make graphical applications in easy steps. It is rich in graphics related features. The built-in methods, properties and events allow you to use these features most effectively. In this tutorial, you will learn about various graphic methods, properties and techniques. The graphic methods and properties let you perform some graphical operations. More specifically, they allow you to draw points, lines, circles, rectangles, ellipses and other shapes.
You will also learn how to display text and images. Finally, this tutorial introduces you to the Paint event. This tutorial is for the beginner learners. So the concepts are presented in the simplest way possible. Code examples have been used wherever they became necessary. Graphic methods The graphic methods allow you to draw on the form and the PictureBox control.
In Visual Basic 6, graphic methods are only supported by the form object and the PictureBox control. However, the later versions of Visual Basic allow you to use them with other objects and controls. First of all, the graphic methods in this section are discussed only to give you a basic idea about them.
Later in this tutorial, I will show you how to use them in your code to perform certain operations like printing text, drawing shapes etc. The common graphic methods are explained below. Print: Print is the simplest graphic method in Visual Basic 6. This method has been used throughout the earlier versions of the language.
It prints some text on the form or on the PictureBox control.Graphics forms a very important part of visual basic programming because an attractive user interface will be appealing to the users.
In the old BASIC, drawing and designing graphics are considered difficult jobs, as they have to be programmed line by line in a text-based environment. However, in Visual Basic 6, these jobs have been made easy. There are four basic controls in VB6 that you can use to draw graphics on your form: the line control, the shape control, the image box and the picture box.
To draw a straight line, just click on the line control and then use your mouse to draw the line on the form. After drawing the line, you can then change its color, width and style using the BorderColor, BorderWidth and BorderStyle properties.
Similarly, to draw a shape, just click on the shape control and draw the shape on the form. The default shape is a rectangle, with the default shape property set at 0.
In addition, you can change its background color using the BackColor property, its border style using the BorderStyle property, its border color using the BorderColor property as well its border width using the BorderWidth property.
The program in this example allows the user to change the shape by selecting a particular shape from a list of options from a list box, as well as changing its color through a common dialog box. The objects to be inserted in the form are a list box, a command button, a shape control and a common dialog box. After that, the Microsoft Common Dialog Control 6.
The list of items can be added to the list box through the AddItem method. The procedure for the common dialog box to present the standard colors is as follows:. The last line will change the background color of the shape by clicking on a particular color on the common dialog box as shown in the Figure Using the line and shape controls to draw graphics will only enable you to create a simple design. In order to improve the look of the interface, you need to put in images and pictures of your own.
Subscribe to RSS
Fortunately, there are two very powerful graphics tools you can use in Visual Basic 6 which are the image box and the picture box.
To load a picture or image into an image box or a picture box, you can click on the picture property in the properties window to launch a dialog box that will prompt you to select a certain picture file. You can also load a picture at runtime by using the LoadPictrure method. The syntax is. This program uses the Rnd function to generate random integers and then uses the LoadPicture method to load different pictures into the image boxes using the If…Then…Statements based on the random numbers generated.
Other than using the line and shape controls to draw graphics on the form, you can also use the Pset, Line and Circle methods to draw graphics on the form.Vs in Microsoft.CYCLOID WITH NORMAL and TANGENT
Single value indicating the horizontal coordinate for the center point of the circle, ellipse, or arc. The ScaleMode property determines the units of measurement used. Single value indicating the vertical coordinate for the center point of the circle, ellipse, or arc. Single value indicating the radius of the circle or ellipse. Integer value indicating the RGB red-green-blue color of the circle's outline. If this parameter is omitted, the value of Black is used.
Single -precision value. When an arc or a partial circle or ellipse is printed, startAngle and endAngle specify in radians the start and end positions of the arc. Single -precision value indicating the aspect ratio of the circle or ellipse. The default value is 1. Only a closed figure can be filled. Closed figures include circles, ellipses, or pie slices arcs with radius lines drawn at both ends. When printing a partial circle or ellipse, if StartAngle is negative, Circle prints a radius to StartAngle and treats the angle as positive.
The Circle method always draws in a counter-clockwise positive direction. The width, or thickness, of the line used to print the circle, ellipse, or arc depends on the setting of the DrawWidth property. The manner in which the circle is printed on the background depends on the setting of the DrawStyle property.
When printing pie slices, to print a radius to angle 0 creating a horizontal line segment to the rightspecify a very small negative value for StartAngle instead of zero. You can omit an argument in the middle of the syntax, but you must include the argument's comma before you include the next argument. If you omit an optional argument, omit the comma following the previous specified argument. When Circle runs, the CurrentX and CurrentY properties are set to the center point specified by the arguments.
Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. I think this happens due to the rounding of the cos and sin functions, so my question is, is there some algorithm I can apply to fix the rounding? Or is there a better way to render such controls, perhaps? The problem, as pointed by Hrqls was that I was using degrees instead of radians For the moment, at least :.
Learn more. Drawing a circle with radial lines Ask Question. Asked 5 years, 10 months ago.
PictureBox and Image Controls in Visual Basic 6
Active 5 years, 10 months ago. Viewed 1k times. Add "vb. Well, the types of the variables are Variant, but I was completely in the wrong track I was on the wrong track as well, until i printed the numbers at the end of the lines. Active Oldest Votes. Hrqls Hrqls 2, 4 4 gold badges 27 27 silver badges 52 52 bronze badges.
I whish VB6 intellisense was clearer I would ensure that you keep the greatest accuracy by using proper fractions of 2PI. Mark Bertenshaw Mark Bertenshaw 5, 2 2 gold badges 23 23 silver badges 37 37 bronze badges. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name.
You seem to have trouble with writing event handlers though. There is the code to help you get started with drawing. Picture1 is PictureBox control. Blue line will be drawn when you move your mouse over the picture box holding left mouse button down. Learn more. How to draw in a picturebox in vb6 Ask Question. Asked 7 years ago. Active 7 years ago.
Viewed 18k times. Inc Swynco. Inc 23 1 1 gold badge 1 1 silver badge 4 4 bronze badges. Active Oldest Votes. PictureBox Draws lines and rectangles on an object.
Ilya Kurnosov Ilya Kurnosov 2, 3 3 gold badges 19 19 silver badges 34 34 bronze badges. It doesn't draw a line, rather a point, and is pretty much analogous to Picture1. PSet X, Y with added control over point color. Inc was going in the direction of drawing lines - or at least connected points, as you can see from the MouseMove handler.
Try this code while moving the mouse quickly and you will see that it is drawing points, not lines. Sign up or log in Sign up using Google.As well as the shape control, there are three Methods that can be used for producing graphics in Visual Basic. The three methods are 1. PSet2. Line and 3. These methods can be used on a Form, PictureBox, or Printer object. PenColour sets the line colour. If omitted, the ForeColor property will be used instead. B will produce a rectangle. F will cause a rectangle to be filled.
The MouseDown event and the MouseMove event are useful for freehand drawing. If no start position is provided for the Line method, it draws from CurrentX and CurrentY which are two system variables that maintain the x and y coordinates for each of the graphics objects.
Initially when MouseDown is raised, we draw a dot with the PSet method. This updates both CurrentX and CurrentY.
The mouse position is passed to both the MouseDown and the MouseMove events. We check the Button status in MouseMove to ensure the button is pressed, otherwise it would draw whenever the mouse is moved. To try this examplecopy the code and paste it into a new project. Run the program, and use the mouse to draw on the form. Radius the radius of the circle. Colour sets the arc colour. Aspect ratio relative to the height and width of the bounding rectangle of the circle.
The default value is 1, a prefect circle. A value less than 1 results in a short fat circle, and a value greater than 1 results in a tall thin circle. This example draws a short fat circle in the centre of the form with a radius of twips. Notice that when optional values are omitted, the comma is still used as a placeholder.
The next example draws a series of circles and arcs to further illustrate the use of the Circle method. The resulting image is shown below the example. This example illustrates how to use a "rubberband" effect using the Circle method and the DrawMode property. To try it, copy and paste it into a new project. The ScaleMode Property is used to determine the units used for drawing.
The DrawMode Property is used to determine how the graphical methods will be drawn over the background of the Graphic Object. The following changes the DrawMode of the form to the inverse of the background. The DrawWidth property determines the width for output with the graphic methods.
The width setting is in pixels regardless of the ScaleMode unit. The following example sets the drawing mode to Invert, the style to dotted, and the width to 5 pixels on a form. The RGB function allows colours to be defined using ranges between 0 and for red, green and blue. The values are passed to the function in the order red, green, blue - hence the function name RGB.Both PictureBox and Image controls let you display an image, so let's compare them and see when it makes sense to choose one or the other.
PictureBox controls are among the most powerful and complex items in the Visual Basic Toolbox window. In a sense, these controls are more similar to forms than to other controls. In other words, all the techniques that I described for forms can also be used for PictureBox controls and therefore won't be covered again in this section.
Once you place a PictureBox on a form, you might want to load an image in it, which you do by setting the Picture property in the Properties window. You can decide whether a control should display a border, resetting the BorderStyle to 0-None if necessary. Another property that comes handy in this phase is AutoSize: Set it to True and let the control automatically resize itself to fit the assigned image.
You might want to set the Align property of a PictureBox control to something other than the 0-None value. By doing that, you attach the control to one of the four form borders and have Visual Basic automatically move and resize the PictureBox control when the form is resized. PictureBox controls expose a Resize event, so you can trap it if you need to move and resize its child controls too. You can do more interesting things at run time.
To begin with, you can programmatically load any image in the control using the LoadPicture function:. The LoadPicture function has been extended in Visual Basic 6 to support icon files containing multiple icons. The new syntax is the following:. If filename is an icon file, you can select a particular icon using the size or colordepth arguments. You can copy an image from one PictureBox control to another by assigning the target control's Picture property:.
PictureBox controls are equipped with a very powerful method that enables the programmer to perform a wide variety of graphic effects, including zooming, scrolling, panning, tiling, flipping, and many fading effects: This is the PaintPicture method.
This method is also exposed by form objects, but it's most often used with PictureBox controls. In a nutshell, this method performs a pixel-by-pixel copy from a source control to a destination control. The complete syntax of this method is complex and rather confusing:. PaintPicture SrcPictBox.
Printer.Circle Method (Single, Single, Single, Int32, Single, Single, Single)
The only required arguments are the source PictureBox control's Picture property and the coordinates inside the destination control where the image must be copied.
For example, if the source PictureBox control contains a bitmap twips wide and twips tall, you can center this image on the destination control with this command:. PaintPicture picSource. Picture, picDest. In general, Visual Basic doesn't provide a way to determine the size of a bitmap loaded into a PictureBox control.
But you can derive this information if you set the control's AutoSize property to True and then read the control's ScaleWidth and ScaleHeight properties. If you don't want to resize a visible control just to learn the dimensions of a bitmap, you can load it into an invisible control, or you can use this trick, based on the fact that the Picture property returns an StdPicture object, which in turn exposes the Height and Width properties:. By the way, in all subsequent code examples I assume that the source PictureBox control's ScaleWidth and ScaleHeight properties match the actual bitmap's size.
By default, the PaintPicture method copies the entire source bitmap. But you can copy just a portion of it, passing a value for srcWidth and srcHeight:. If you're copying just a portion of the source image, you probably want to pass a specific value for the srcX and srcY values as well, which correspond to the coordinates of the top-left corner of the area that will be copied from the source control:.
Picture, wi, he, wi, he, wi, he. You can use this method to tile a target PictureBox control or form with multiple copies of an image stored in another control:. ScaleHeight picDest. ScaleWidth Loop. Another great feature of the PaintPicture method lets you resize the image while you transfer it, and you can even specify different zoom-in and zoom-out factors for the x- and y-axes independently.
You just have to pass a value to the destWidth and destHeight arguments: If these values are greater than the source image's corresponding dimensions, you achieve a zoom-in effect, and if they are less you get a zoom-out effect.