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://www.cnblogs.com/DebugLZQ /// 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.