This was an age of individuality. I also played with personality and made a few personalized controls to play around. Today I have nothing to do. I have done a few things, that is, I changed the controls and changed my face. Let's take a look at my personal controls. ( To Button For example, other controls are similar ) .
Let's just look like this. No matter what the shape is, you can also make the button into the shape, and so on. It was too difficult to calculate the coordinates of a star. If you are interested, you can implement it.
Next I will introduce the main content of these personal controls.
In fact, control rewriting inherits the control class and reloads its functions. The so-called control is a visible component. The component is the base class of the control. The textbox is used as an example, the family relationship of the control class is as follows:
System. Object
System. externalbyrefobject
System. componentmodel. Component
System. Windows. Forms. Control
System. Windows. Forms. textboxbase
System. Windows. Forms. textbox
System. Windows. Forms. datagridtextbox
System. Windows. Forms. datagridviewtextboxeditingcontrol
We found that textbox has two sub-classes.
When developing controls, for example, when developing Textbox, I can use textbox as the base class, textboxbase, or even control as the base class.
The controls in the C/S architecture are time-rich, so we can rewrite the paint function to implement control face changes without having to re-write anything.
Create a project and add a class named mybutton to the project, Code Is: Using System;
Using System. Collections. Generic;
Using System. text;
Using System. Windows. forms;
Using System. drawing;
Using System. componentmodel;
Using System. Drawing. drawing2d;
Namespace Checkboxrodio
{
Class Mybutton: button
{
Public Mybutton ()
{
This . Paint + = New Painteventhandler (mybutton_paint );
// Base. Paint + = new painteventhandler (mybutton_paint );
// This. mousemove + = new mouseeventhandler (mybutton_mousemove );
// This. mouseclick + = new mouseeventhandler (mybutton_mouseclick );
}
Void Mybutton_paint ( Object Sender, painteventargs E)
{
// Create path object
Graphicspath mypath = New Graphicspath ();
Pen P = New Pen (color. Red, 5 );
Solidbrush sb = New Solidbrush (color. Gold );
Int W = This . Width;
Int H = This . Height;
// Pentagram
// Point P1 = new point (W/2, 3 );
// Point P2 = new point (W/3, H-4 );
// Point P3 = new point (W-4, H/3 );
// Point P4 = new point (3, H/3 );
// Point P5 = new point (2 * w/3, H-4 );
// Mypath. addpolygon (PS );
// Diamond
Point P1 = New Point (W / 2 , 3 );
Point p2 = New Point ( 3 , H / 2 );
Point p3 = New Point (W / 2 , H - 6 );
Point p4 = New Point (W - 6 , H / 2 );
Point [] PS = {P1, P2, P3, P4, P1} ;
Mypath. addpolygon (PS );
// Triangle
// Point P1 = new point (w-9)/2, 3 );
// Point P2 = new point (3, h-6 );
// Point P3 = new point (w-6, H-6 );
// Point [] PS = {P1, P2, P3, P1 };
// Mypath. addpolygon (PS );
// Elliptic
// Mypath. addellipse (5, 5, w-10, h-10 );
// Mypath. addlines (PS );
This . Region = New Region (mypath );
E. Graphics. fillellipse (SB, 20 , 20 , 20 , 20 ); // . Drawellipse ();
}
}
}
Compile the file to see if it is successful. If it is successful, open the Form class. In this case, the toolbar is displayed and the toolbar is opened. You can see that the mybutton control is in your toolbar! It is too easy to use it. Drag it to the form and it will be OK. Because I did not override the properties of the control, the attribute box does not change.