博文

GDI+: Solid Brushes(2006-06-19 20:22:00)

摘要: Introduction The simplest type of brush is referred to as solid. This type of brush is simply equipped with a color and it is used to fill a shape with it. To get a solid brush, you use the SolidBrush class defined in the System.Drawing namespace. It has only one constructor declared with the following syntax: Public Sub New(ByVal color As Color ) The color passed as argument must be a valid definition of a Color. Here is an example: Private Sub Form1_Paint(ByVal sender As Object, _ ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint Dim brushBlue As New SolidBrush(Color.Blue) e.Graphics.FillRectangle(brushBlue, 20, 20, 200, 160) End Sub If you plan to use different colors to fill different shapes, you don't have to create a new brush for each shape. At any time, before re-using the same brush previously defined, you can simply change its Color. For this reason, the SolidBrush class is equipped with the Color property. H......

阅读全文(2738) | 评论:0

Introduction to GDI+(2006-06-19 20:21:00)

摘要: Device Contexts   Introduction to GDI To draw something, you need a platform on which to draw and one or a few tools to draw with. The most common platform on which to draw is probably a piece of paper. Besides such a platform, you may need a pen or a brush that would show the evolution of the drawing work on the platform. Since a pen can have or use only one color, depending on your goal, one pen may not be sufficient, in which case you would end up with quite a few of them. A device context is an ensemble of the platform you draw on and the tools you need to draw with. It also includes the dimensioning of the platform, the orientation and other variations of your drawing, the colors, and various other accessories that can complete your imagination. When using a computer, you certainly cannot position tools on the table or desktop for use as needed. To help with drawing on the Windows operating system, Microsoft created the Graphical Device Int......

阅读全文(2161) | 评论:0

Introduction to GDI+(2006-06-19 20:02:00)

摘要: Device Contexts   Introduction to GDI To draw something, you need a platform on which to draw and one or a few tools to draw with. The most common platform on which to draw is probably a piece of paper. Besides such a platform, you may need a pen or a brush that would show the evolution of the drawing work on the platform. Since a pen can have or use only one color, depending on your goal, one pen may not be sufficient, in which case you would end up with quite a few of them. A device context is an ensemble of the platform you draw on and the tools you need to draw with. It also includes the dimensioning of the platform, the orientation and other variations of your drawing, the colors, and various other accessories that can complete your imagination. When using a computer, you certainly cannot position tools on the table or desktop for use as needed. To help with drawing on the Windows operating system, Microsoft created the Graphical Device Int......

阅读全文(2040) | 评论:0

GDI+: Introduction to Brushes(2006-06-19 20:00:00)

摘要: Introduction Line-based and closed shapes figure require a pen to show their shape. The particularity with closed shapes is that they can be filled, with a color, a picture, or a pattern. A brush is an object that holds a color, a picture, or a drawing pattern and that is used to fill the interior of a closed shape. This definition also means that there are various types of brushes with different goals. To meet these goals, the .NET Framework provides support for brushes in various namespaces with different classes. The parent of all brushes is the Brush class defined in the System.Drawing namespace. Using a Brush Because the main job of a brush is to fill a closed shape, the Graphics class provides a method that corresponds to each of the closed shapes we reviewed to draw in the previous lesson in order to fill it. The methods are: FillRectangle: Used to fill the interior of a rectangle or a square FillRectangle: Used to fill the interior of a serie......

阅读全文(2333) | 评论:0

GDI+ Objects: Icons(2006-06-19 19:59:00)

摘要: Icons   Introduction Like a bitmap, an icon is used to display graphics on window objects. While a bitmap can have any dimension the window needs, the size of an icon is limited. This is because icons assume different roles on an application. Icons are used to represent folders in Windows Explorer and My Computer:   Creating Icons   To create an icon, once again, you can use any application that has the capability. Normally, you can use Visual Studio .NET to create or design an icon. To do this, on the main menu of Visual Studio, you can click Project -> Add Resource… Then, in the Add Resource dialog box, you can select Icon and click New. When you start designing an icon, you would be presented with a drawing area whose dimensions are 32 x 32 pixels. This is the size of the icon that displays as Large Icon. Here is an example from the New File dialog box Visual Studio .NET in the Templates list: In some cases, you......

阅读全文(2923) | 评论:4

GDI+: Hatch Brushes(2006-06-19 19:58:00)

摘要:GDI+: Hatch Brushes Introduction A hatch brush relies on a drawn or designed pattern to set its filling type. To support hatch brushes, the .NET Framework provides the patterns you can use as part of the brush. These pre-designed patterns are referred to as hatch styles. This means that when you use a hatch brush, you must specify the type of pattern you want to use, through one of the available hatch styles. To make the filled area more interesting, you also specify the color to use when drawing the pattern. To get a hatch brush, you use the HatchBrush class. One of its constructors has the following syntaxes:Public Sub HatchBrush(ByVal style As HatchStyle, ByVal foreColor As Color) The foreColor argument is the color that will be used to draw the pattern. The style argument is the hatch style you want to apply. Some of the available styles are: Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) _ Handles MyBase......

阅读全文(3519) | 评论:0

GDI+: Gradient Brushes(2006-06-19 19:57:00)

摘要: Gradient Brushes A gradient brush resembles a solid brush in that it is color-based. Unlike a solid brush, a gradient brush uses two colors. Its main characteristic is that, when used, one color is applied on one side and the other color is applied to the other side. In between, both colors merge to create a transition or fading effect. There are two types of gradient brushes: linear and path. Linear Gradient Brushes A linear gradient is used to apply two colors in a closed shape but from one side of the shape, such as the left, to the other opposite side of the shape, such as the right. To support linear gradient brushes, the .NET Framework provides the LinearGradientBrush class defined in the System.Drawing.Drawing2D namespace. To specify the starting and the end points inside of the shape that you want to fill, you can use one of the following constructors:Public Sub LinearGradientBrush(ByVal point1 As Point, ByVal point2 As Point, _ ByVal color1 A......

阅读全文(2085) | 评论:0

GDI+: Curve-Based Shapes(2006-06-19 19:57:00)

摘要: Curves   Introduction to Curves A curve is a line that joins two or more points. If only two points are involved, the line would join them but the line is not straight. If there are three points A, B, and C, the line would start on the first point A, cross the second point B, and stop at the last point. If more than three points are involved, the line would start on the first, cross the second, cross the third and each line before stopping on the last. The points of a curve don't have to be aligned. In fact, the whole idea of drawing a curve is to have a non-straight line that joins different non-aligned points. This can be illustrated with the following three curves labeled C1, C2, and C3: The first curve, C1, includes only two points. The second, C2 includes three points. The third, C3, includes four points. The section between two points is called a segment. This also means that a curve can be distinguished by the number of segments it has.......

阅读全文(2589) | 评论:0

GDI+ Objects: Bitmaps(2006-06-19 19:56:00)

摘要: Bitmaps   Introduction A bitmap is a graphic object used for displaying pictures on windows. It is the primary type of graphic used for various occasions. For example, a bitmap can be used as a background for a window. That is the case for the Pinball game that ships with some versions of Microsoft Windows: A bitmap can also be used for an aesthetic purpose to decorate a dialog box. That’s how it is used on some of the installation wizard boxes such as the graphic on the left section of the WordPerfect 2002 installer: Probably the most regular use of bitmaps is as small graphics on toolbars:   Creating a Bitmap To create a bitmap, you can use any graphics application, including the Paint program that is installed with Microsoft Windows. In Visual Studio .NET, to create a bitmap, on the main menu, you would click Project -> Add New Item... In the Add New Item dialog box, click Bitmap File, accept the suggested name of ......

阅读全文(3122) | 评论:0

GDI+: Line-Based Shapes(2006-06-19 19:51:00)

摘要: Rectangles and Squares A rectangle is a geometric figure made of four sides that compose four right angles. To draw a rectangle, you can either specify the Rectangle value that encloses it, or you can define its location and its dimensions. To draw a rectangle that is enclosed in a Rectangle value, you can use the following version of the Graphics.DrawRectangle() method:Overloads Public Sub DrawRectangle(ByVal pen As Pen, ByVal rect As Rectangle) Remember that such a rectangle object can be illustrated as follows: After defining a Rectangle variable, you can pass it to the method. Here is an example:Private Sub Form1_Paint(ByVal sender As Object, _ ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint Dim penCurrent As New Pen(Color.Red) Dim rect As New Rectangle(20, 20, 248, 162) e.Graphics.DrawRectangle(penCurrent, Rect) End Sub Remember that you can also define a Pen and/or a Rectangle objects in the pa......

阅读全文(2264) | 评论:0