In general, the form of an application is a regular, rectangular form. Sometimes for a particular purpose, we want to change the shape of the application form, such as being a MP3 player, a small clock, and so on, which requires "customizing" our Application. In addition, specially shaped forms can sometimes attract the attention of users, making them pay special attention to your program.
In VB6, we typically create irregular forms through the following code.
Private Declare Function setwindowrgn Lib "user32" (ByVal hWnd as Long, _ ByVal hrgn as Long, ByVal Bredraw as Boolean) as Long
Private Declare Function createellipticrgn Lib "gdi32" (ByVal X1 as Long, _ ByVal Y1 as Long, ByVal X2 as Long, ByVal Y2 A s long) as long
Private Declare Function deleteobject Lib "gdi32" (ByVal Hobject as long) as long
Private Sub form_activate ()
Dim Hndrgn as Long
Hndrgn = createellipticrgn (0, 0, 175, 175)
Call SetWindowRgn (Me.hwnd, Hndrgn, True)
Call DeleteObject (HNDRGN)
End Sub
First create a rounded area with the Win32 API createellipticrgn, and then set the form area for the user-defined region so that we can get a circular form below
In order to be more beautiful, we can set the form of the BorderStyle to none, and then draw a titilebar ourselves, you can make a more lively application.
Vb. NET inside how to achieve the above effect:
Vb. NET is a Cross-platform language, better use of object-oriented mechanism. Its object-oriented capabilities extend the path of the language itself: everything is an object. This means that you gain more intrinsic functionality than in previous versions of VB, and you will rarely be forced to use Windows APIs. Therefore in vb.net inside we also had to give up VB6 inside use API idea, use vb.net powerful object mechanism to elaborate above topic.
In vb.net, the form has a Reigin property, and we can get irregular forms by creating a custom reigin and then specifying the Reigin of the form. and vb.net inside the Reigin objects powerful, far more than before the limitations of VB, so we can make a lot of beautiful interface.
Regin objects
System.Drawing An object that indicates the interior of a rectangle and a shape that is composed of a path. Because the coordinates of the zone are specified in global coordinates, it can be scaled. However, on the drawing surface, its interior depends on the size and shape of the pixel that represents it. An application can use several areas to stack the output of a drawing operation. The window Manager uses zones to define the drawing area of the window. These areas are called clipping regions. An application can also use an area in a hit-detection operation, such as checking whether a point or rectangle intersects a region. An application can populate an area by using the Brush object.
GraphicsPath represents a series of interconnected lines and curves that the application uses to draw the outline of the shape, fill the interior of the shape, and create clipping regions. The graphics engine maintains the coordinates of the geometric shapes within the path in the global coordinate space. A path can consist of any number of shapes (subpath). Each graphic is made up of a series of interconnected lines and curves or geometric shape primitives. The starting point of the graph is the 1th of a series of interconnected lines and curves. The endpoint is the last point in the sequence. The start and end points of a geometric shape primitive are defined by the primitive specification.
Now let's look at two specific examples
1. Forms in Text format
Add the following code to the form's Load event:
Dim Text_path as GraphicsPath
Dim Text_region as Region
Me.backcolor = color.red
Me.Width = 600
' Create the ' text path.
Text_path = New GraphicsPath (Drawing.Drawing2D.FillMode.Alternate)
Text_path. AddString ("CSDN", New FontFamily ("Times New Roman"), FontStyle.Bold, 200,new Point (10, 10),
Stringformat.genericdefault)
' Create a Region from ' path.
Text_region = New region (text_path)
' Constrain the form to the region.
Me.region = Text_region
Run the form that would get the following shape, remembering to abort the program by SHIFT+F5.
2. Oval-shaped form:
Also add the following code, get the following form
Me.Width = 300
Me.height = 220
Me.backcolor = Color.royalblue
Dim M_path as GraphicsPath
M_path = New GraphicsPath (fillmode.winding)
M_path. AddEllipse (1, 1, 200, 200)
Dim M_region as New region (M_path)
Me.region = M_region
These are just two simple examples, and you'll get more interesting results by leveraging region and GraphicsPath objects.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.