Interface Development (4)-restore the new appearance of the form

Source: Internet
Author: User

The previous article sets region for the form, sets formborderstyle of the form to none, and then modifies the display region of the form. An intact form makes it a blank form without any color, which seems to be a back-to-back line for our interface development. Otherwise, only by removing all the original information on the form can the original appearance of the form be restored and a new appearance be given to the form.

This article develops and designs a new look for the form interface.

As I have already said at the beginning of the interface, interface development is actually to modify the two areas of the form, client area and none client area, such:

Now we have modified the form into a form without any information, such:

What we need to do now is add our own interface to the graph without any help, and draw the client area and none client area of the form to make it look new. However, drawing does require a lot of GDI + knowledge.

The painting of client area is very simple. It is mainly to modify the background color of the form. This is a single sentence for C # developers. You can set the background color of the form. The Code is as follows:

This. _ parentform. backcolor = This. _ engine. skincolor. back;

 

However, painting of the none client area is troublesome. It not only draws colors, but also the title bar, maximize, minimize, close button, form icon, and border of the form, next, draw the form one by one.

The title bar of a form is divided into two parts: the icon of the form and the title of the form. The first step of painting is to set the painting area of the form. Find the painting area and use GDI + for painting. The Code is as follows:

# Region ncpaint
/// <Summary>
/// Ncpaint
/// </Summary>
/// <Param name = "form"> </param>
/// <Returns> </returns>
Private bool ncpaint (skinningform form, skinengine engine)
{
// Declared filed
Bool result = true;
Intptr HDC = (intptr) 0;
Graphics G = NULL;
Region region = NULL;
Intptr hrgn = (intptr) 0;

Try
{
// Get rect
Rect rectscreen = new rect ();
Nativemethod. getwindowrect (_ parentform. Handle, ref rectscreen );
Rectangle rectbounds = rectscreen. torectangle ();
Rectbounds. offset (-rectbounds. X,-rectbounds. y );

// Prepare Clipping
Rectangle rectclip = rectbounds;
Region = new region (rectclip );
Rectclip. Inflate (-engine. skinappearance. borderwidth,-engine. skinappearance. borderwidth );
Rectclip. Y + = engine. skinappearance. captionheight;
Rectclip. Height-= engine. skinappearance. captionheight;

// Create graphics handle
HDC = nativemethod. getdcex (_ parentform. Handle, (intptr) 0,
(Dcxflags. dcx_cache | dcxflags. dcx_clipsiblings | dcxflags. dcx_window ));
G = graphics. fromhdc (HDC );

// Apply Clipping
Region. exclude (rectclip );
Hrgn = region. gethrgn (g );
Nativemethod. selectcliprgn (HDC, hrgn );

If (_ buffergraphics = NULL | _ currentcachesize! = Rectbounds. Size)
{
If (_ buffergraphics! = NULL)
_ Buffergraphics. Dispose ();

_ Buffergraphics = _ buffercontext. Allocate (G, new rectangle (0, 0,
Rectbounds. Width, rectbounds. Height ));
_ Currentcachesize = rectbounds. size;
}

// Get caption Bounds
Rectangle captionbounds = rectbounds;
Captionbounds. Height = This. _ engine. skinappearance. borderwidth + this. _ engine. skinappearance. captionheight;

// Draw Caption
Engine. skinappearance. drawcaptionbackground (G, captionbounds, this. _ formisactive, this. _ engine );
// Draw caption icon
If (this. _ parentform. showicon & this. _ parentform. icon! = NULL)
{
Drawicon (g );
}
// Draw caption text
Drawcaptiontext (G, this. _ parentform. text, this. _ parentform. font );

// Draw caption button
Drawcaptioncontrolbox (g );

// Draw border
Engine. skinappearance. drawborder (G, rectbounds, engine );
}
Catch
{
Result = false;
}

// Cleanup data
If (HDC! = (Intptr) 0)
{
Nativemethod. selectcliprgn (HDC, (intptr) 0 );
Nativemethod. releasedc (_ parentform. Handle, HDC );
}
If (region! = NULL & hrgn! = (Intptr) 0)
Region. releasehrgn (hrgn );

If (region! = NULL)
Region. Dispose ();

If (G! = NULL)
G. Dispose ();
Return result;
}
# Endregion

 

This completely draws the border of the form. The interface effect is as follows:

Code:/files/zhjp11/skin/skinengines20100324.rar

 

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.