Create a high-tech form with Visual Basic
By Dale E. Lehman
That is not a form!
Sometimes you will occasionally encounter a Windows application, it is not like a normal Windows application. Do you know what I mean. The Windows application is a rectangular user interface. exactly. But sometimes you will see an application with a circular corner, and even a form of a near-crazy singular shape, it is not like a Windows application. Take Net2Phone 10.6.2 as an example, the two top forms look beautiful. But in fact, they are just two "L" shape forms (shown in Figure 1). If you agree with my point of view, whenever you encounter a similar to you, you don't know how to create such a jade form for yourself, you definitely think not to use VB, isn't it?
Ok, there are some good news below: In fact, you can create any eyes that you see, brain imagination with VB form. You can even create a form of a hole in the middle or create a form consisting of a region that is separated from each other.
Not good, you can't create just created with VB. The features needed depend on the Windows graphical user interface, these
VB does not have. For these, you need a Windows API call.
Figure 1: Example of a custom form style
Basic principle of Region
Creating a high-tech form is a technology called Region. A Region is a region of the computer monitor. The Windows application uses Region to draw output and execute click the test (the location of the cursor) on the screen. Simply, a Region is a certain area that can occur on the display. GDI
Three available region: rectangles, ellipses, and polygons. The API call is used to create and manipulate the Region.
So what do you need to do in the VB form? Very simple, each form is drawn in the Region. In fact, each window is drawn in the Region. You may know that the Windows operating system defines a window as a zone that receives the input of the application and the output is displayed. It sounds very similar to defining a region. In fact, the window is much more complicated than Region. Windows can present a variety of appearance: form, buttons, text boxes, etc. However, in general, the window is drawn in a region. So we can say that each window has a Region, so the VB form has a Region.
Typically, a form is drawn in a rectangular region. In fact, it is basically not talking about Region inside the VB help. The operating system automatically assigns a rectangular region for each form. VB does not prompt you to change these. Therefore, in the design mode, you must often work in a rectangular form. But with the help of a little simple API, you can change the region of a form when running.
Running
Let's take a look at the easiest part of the region, an ellipse. The Windows operating system provides a function cretellipticRGN that provides a rectangular left corner and lower right corner coordinates. This function records an ellipse inside this rectangle to create the required Region. Once you get this Region handle, you have to assign it into your form. To do this, use the CreatellipTicRGN function, which provides the handle to the window and region, but also provides a Boolean declaration to determine if the window is re-painted after the assignment of the REGON. Usually, you want to set the last statement to true, below is these code: public declare function cretellipticRGN _ lib "gdi32" (Byval Y1 as long, _ byval x2 as long, _ byval y2 AS Long) As Long Public Declare Function SetWindowRgn _ Lib "user32" (ByVal hWnd As Long, _ ByVal hRgn As Long, _ ByVal bRedraw As Boolean) As Long Public Sub CreateEllipseFromWindow (ByRef oWindow As Object) Dim lRight As Long Dim lBottom As Long Dim hRgn As Long With oWindow lRight = .Width / Screen.TwipsPerPixelX lBottom = .Height / Screen.TwipsPerPixelY hRgn = CreateEllipticRgn (0, 0, lRight, lBottom) SetWindowRgn .hWnd, hRgn, True End WithEnd Sub Private Sub Form_Load () CreateEllipseFromWindow Meend Sub should notice that in these code, the coordinates of the upper left corner and the lower right corner are used as the basis of the ellipse. When the project starts, the form initially has a size given when designing, so the ellipse is based on those data. At the same time, it should be noted that in order to get the correct size, we need to convert the height and width from the 缇. In the default, VB uses the size as the screen. When used in Region, you need to be pixels. The Screen.TwipsPixelx and Screen.TwipsPerpixely functions make this conversion easy. When you run these code, you will find that the form does appear in an ellipse, but it is a very ugly ellipse. (Figure 2) The problem is based on the VB's form based on the rectangular Region. However, the form is not allowed to draw outside of the ellipse Region. Therefore, the result is that the corner of the rectangle is strictly cut off! You definitely don't want to be a form like this! Figure 2: The original appearance of the custom ellipse form is the second obvious problem to change the size of the form.
to be continued……