Control
Keywords
C#,.net, controls, GDI +
I usually prefer to use Delphi, the niche is not, I like the Delphi, peacetime development (at least now) more use Delphi, but not afraid of you master jokes, I did not use Delphi to write the control, although the principle of know, but always feel I do not know how to do: L
But since contact with C #, she which graceful posture (code style), coquettish but not indulgent character (to object-oriented embodiment is better, than the Delphi Strong), deeply touched me. After a period of practice, I found that in the development of controls and components (other aspects, the niche I dare not 妄断), its simplicity really makes me refreshing. What do you say, give it a try. J
Yes, my development platform is the official version of Windows Server+.vs.net.
The control I implemented is a step-by-step from the form control button that enables the gradient background to be implemented, and the pattern and texture fill text.
All right, let's start with the opening.
1 First, make a vs.net.
2 On the File menu, point to New, and then select Project to open the New Project dialog box. Select the Windows Control Library project template from the C # project list, and then type Lineargradientbuttonlib in the Name box, and then click OK.
3 In Solution Explorer, right-click UserControl1.cs and choose View Code from the shortcut menu.
4 Find the Class statement public class UserControl1, change the UserControl1 to Lineargradientbutton to alter the name of the component. Locate the constructor public UserControl1 () and change it to public Lineargradientbutton ().
5 in the Class statement, change the control from the System.Windows.Forms.UserControl inherited type to System.Windows.Forms.Button. This allows inherited controls to inherit all the functionality of the Button control.
6 In Solution Explorer, click UserControl1.cs, and in the Properties window, change the FileName property to LinearGradientButton.cs.
Well, now that the work is over, the next job is to add attributes to our controls. Drink water, go on!
First add the name space using System.Drawing.Drawing2D;
1 Find the class statement. Type the following code immediately after {:
Private Color Frocolor; Gradient foreground color
Private color backcolor;//Gradient background color
private bool isusefloat;//Whether use angle change
private float angle; Placement Angle
Private LinearGradientMode mode;//Set the angle of the gradient
Private Hatchstyle Hatchstyle; Set the fill pattern for text
private bool isusestyle;//Set whether to fill patterns with patterns
These are the private domains that our controls need, and the following starts with their corresponding properties for each private domain. Under the above code, write the following code:
[Description ("Set the foreground color of the button gradient"), Category ("appearance")]
Public Color Frontcolor
{
Get
{
return frocolor;
}
Set
{
Frocolor=value;
}
}
[Description ("Set the background color of the button gradient"), Category ("appearance")]
Public Color BackgroundColor
{
Get
{
return BackColor;
}
Set
{
Backcolor=value;
}
}
[DefaultValue (False), Description ("Set the angle Manually")]
public bool Usefloat
{
Get
{
return isusefloat;
}
Set
{
Isusefloat=value;
}
}
[DefaultValue (False), Description ("Set whether to fill text with pattern")]
public bool Usestyle
{
Get
{
return isusestyle;
}
Set
{
Isusestyle=value;
}
}
[DefaultValue (0), Description ("Defines the angle of the gradient direction, measured clockwise from the X axis)." "), Category (" appearance ")]
public float Angle
{
Get
{
return angle;
}
Set
{
Angle=value;
}
}
[DefaultValue (0), Description ("Set the gradient direction when Usefloat is set to false.) "), Category (" appearance ")]
Public LinearGradientMode Mode
{
Get
{
return mode;
}
Set
{
Mode=value;
}
}
[DefaultValue (False), Description ("Set the pattern to be filled with text"), Category ("appearance")]
Public Hatchstyle FillStyle
{
Get
{
return hatchstyle;
}
Set
{
Hatchstyle=value;
}
}
OK, so we've designed the properties of the control, and we're going to write the event here.