Use C # write controls (on)

zhaozj2021-02-17  72

Write the control with C #

WillSound (willsound@163.com)

Key words

C # ,. Net, control, GDI

I usually prefer to use delphi, not only, I like Delphi, usually develop (at least now) multi-use Delphi, but I am not afraid that you have a joke, I have not written control with Delphi, although I know, I don't know how I don't know Start with: L

But since I have contacted C #, which beautiful posture (code style), the wind is not indulging, and is better than Delphi, it is strong than Delphi. After a period of practice, I found that in development controls and components (other aspects, I don't dare to decompress), and it is simple to be refreshing. How, try it .j .j

Yes, my development platform is Windows 2000 Server .vs.Net official version

The control I implemented is followed by the Form Control Button, which can realize gradient background, realize pattern and texture fill text.

Ok, let's start.

1 First play vs.net

2 In the File menu, point to New, then select Project to open the New Project dialog. Select the "Windows Control Library" project template from the C # Projects list, and then type lineargradientButtonLib in the Name box, then click OK.

3 In the Solution Explorer, right-click UserControl1.cs and select View Code from the shortcut menu.

4 Locate the Class Statement Public Class UserControl1, change UserControl1 to LinearGradientButton to change the name of the component. Find constructor public userControl1 (), change it to public lineargradientButton ().

5 Change the control from System.Windows.Forms.userControl to System.Windows.Forms.Button in the Class statement. This allows inherited controls to inherit all functions of the Button control.

6 In the Solution Explorer, click UserControl1.cs and change the fileName property to lineargradientButton.cs in the Properties window.

Ok, I will tell the work now, the following work is to add attributes to our controls. Drink water, continue!

Plus the name space for use system.drawing.drawing2d;

1 Locate the Class statement. Type the following code on the back of {:

Private color frocolor; // Gradient foreground color

Private color backcolor; // Gradient background color

Private bool isusefloat; // Do not use angle transformation

Private float angle; // placement angle

Private lineargradientmode mode; // Set the angle of gradient

Private HatchStyle HatchStyle; / / Setting the filler pattern of the text

Private bool isusestyle; / / Set whether to fill the pattern with a pattern

Above these is the private domain we need, the following starts to do their corresponding properties for each private domain. In the above code, write the following code:

[Description ("Setting Button Gravity Prospect"), Category ("Appearance")]]]

Public color frontcolor {

get

{

Return frocolor;

}

set

{

Frocolor = Value;

}

}

[Description ("Set button gradient background color"), category ("APPEARANCE")]

Public Color BackgroundColor

{

get

{

Return backcolor;

}

set

{

Backcolor = Value;

}

}

[DefaultValue (false), Description ("Set whether to manually set angle")]

Public Bool Usefloat

{

get

{

Return isusefloat;

}

set

{

ISUSEFLOAT = VALUE;

}

}

[DefaultValue (false), Description ("Set whether to use the pattern fill text")]

Public Bool USTYLELELELELELELE

{

get

{

Return isusestyle;

}

set

{

ISUSESTYLE = VALUE;

}

}

[DefaultValue (0), Description ("Defines the angle of the gradient direction, the unit is measured from the x-axis."), Category ("Appearance")]

Public Float Angle

{

get

{

Return Angle;

}

set

{

Angle = Value;

}

}

[DefaultValue (0), Description ("When USEFLOAT is set to FALSE, set the gradient direction."), Category ("Appearance")]

Public LineargradientMode Mode

{

get

{

Return Mode;

}

set

{

Mode = Value;

}

}

[DefaultValue (false), Description ("Setting the text to populate the pattern"), category ("Appearance")]]

Public HatchStyle FillStyle

{

get

{

Return HatchStyle;

}

set

{

HatchStyle = Value;

}

}

Ok, we have designed the properties of the control. Here we want to write an event.

转载请注明原文地址:https://www.9cbs.com/read-31232.html

New Post(0)