Change winform skin (bottom)-completely GDI + draw replace winform skin (top)-use existing skin

Source: Internet
Author: User

This is the previous blog post: replacing winform skin (on)-using existing skin later.

It mainly draws its own winform interface and searches for related resources on the Internet. Implements a login page. The effect is as follows:

Next, let's see how I implement it.

First, add some material files to the winform project demo and add them to the resource. debuglzq uses vs2012, which can be dragged directly.

2. Set the formborderstyle of the form to none.

3. Change the backend Cs of the form.CodeAs follows:

 Using  System;  Using  System. Collections. Generic;  Using  System. componentmodel;  Using  System. Data;  Using System. drawing;  Using  System. LINQ;  Using  System. text;  Using  System. Threading. tasks;  Using  System. Windows. forms;  Using  Skinmyself. properties;  ///  Custom form skin demo  ///  By debuglzq  /// Http://  ///  Namespace  Skinmyself {  Public   Partial   Class  Form1: FORM {  Public  Form1 () {initializecomponent ();  //  This. setstyle (controlstyles. resizeredraw, true );  } Image imgtop = (Image) resources. Top;//  Form top image Image imgbottom = (image) resources. bottom; //  Bottom image of the form  //  Draw form          Protected   Override   Void  Onpaint (painteventargs e ){  Base  . Onpaint (E );  //  This. backcolor = color. Violet;              This . Backcolor = color. fromargb ( 255 , 60 , 60  );  //  Draw skin Graphics G = E. graphics;  //  Draw the image at the top left corner of the form G. drawimage (imgtop, 0 , 0  , Imgtop. Width, imgtop. Height );  // Draw an image in the lower left corner of the form G. drawimage (imgbottom, 0 , E. cliprectangle. Height- Imgbottom. Height, imgbottom. Width, imgbottom. Height );}  //  Drag a form          Private Point mouseoffset; //  Record the coordinates of the mouse pointer          Private   Bool Ismousedown = False ; //  Record whether the mouse button is pressed         Private   Void Form1_mousedown ( Object  Sender, mouseeventargs e ){  If (E. Button = Mousebuttons. Left) {mouseoffset = New Point (-E. X ,- E. Y); ismousedown = True  ;}}  Private   Void Form1_mouseup (Object  Sender, mouseeventargs e ){  If (E. Button = Mousebuttons. Left) {ismousedown = False  ;}}  Private   Void Form1_mousemove ( Object  Sender, mouseeventargs e ){  If  (Ismousedown) {point mousepos =Control. mouseposition; mousepos. offset (mouseoffset. X, mouseoffset. Y); Location = Mousepos ;}}}} 

This is how winform skin is defined by yourself. You can use it freely!
After the customization is complete, you can drag the control into and edit it like a normal form without affecting normal use.

ProgramThe running effect is as follows:


Is it easy? Previously, debuglzq had a blog post: using the WPF control (with source code) in winform can also provide you with an idea.


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: 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.