Displaying the interface in an irregular shape on the desktop gives you a fresh feeling.
022 non-rectangular form
In the. NET4.0 framework, you can easily implement this function without calling APIs. You only need to override the OnPaint method of the form, re-draw the form in the method, and then set the form to transparent with a transparent color.
1. Create a project. The default form is Form1. Add the Label control to the Form1 form, set the BackColor attribute to transparent, and set the text attribute to null.
2. Set the TransparencyKey attribute of the form to Control and FormBorderStyle to None.
Namespace _ 022_SpecialSharpWindows {public partial class Form1: Form {Bitmap bit; // declare a System. drawing. bitmap class object bit public Form1 () {InitializeComponent ();} private void Form1_Load (object sender, EventArgs e) {bit = new Bitmap ("Heart.bmp "); // initialize System from the specified image. drawing. bitmap class new instance bit. makeTransparent (Color. blue); // use the default transparent color for the System. drawing. bitmap class transparent settings} protected override void OnPaint (PaintEventArgs e) {e. graphics. drawImage (Image) bit, new Point (0, 0); // draw the picture} private void label1_Click (object sender, EventArgs e) {this. close ();}}}
023 create a font shape form
In the. NET4.0 framework, you can easily implement this function without calling APIs. You only need to first draw the font on a graph, then override the OnPaint method of the form, re-draw the form with the graph in the method, and set the form to transparent with the background color.
1. Create a project. The default form is Form1. Add the Label control to the Form1 form, set the BackColor attribute to transparent, and set the text attribute to null.
2. Set the TransparencyKey attribute of the form to Control and FormBorderStyle to None.
namespace _023_WordWindows{ public partial class Form1 : Form { Bitmap bit; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { bit = new Bitmap("1.bmp"); bit.MakeTransparent(Color.Blue); } protected override void OnPaint(PaintEventArgs e) { e.Graphics.DrawImage((Image)bit, new Point(0, 0)); } private void label1_Click(object sender, EventArgs e) { this.Close(); } }}
In the. NET4.0 framework, you can easily implement this function without calling APIs. Most controls have the Anchor attribute. You can set the Anchor attribute when adding controls to a form. The Anchor attribute is an Anchor attribute that specifies the distance between the control and the container edge. When the size of the form changes, the distance between the control and the edge of the form remains unchanged, and the natural size is automatically adjusted with the form.
Create a project. The default form is Form1. Add the MenuStrip control, ToolStrip control, and Button control to the Form1 form, and set the Anchor and Text attributes of the Button control.
In the. NET4.0 framework, you can easily implement this function without calling APIs. You only need to add the SplitContainer control to the form. The SplitContainer control has a separator bar to divide the form into two parts.
Create a project. The default form is Form1. Add the MenuStrip control to the Form1 form to design the menu bar, add the ToolStrip control to design the toolbar, and add the SplitContainer control to design the separation bar.
026 randomly change the background of the main interface
Use the Random class and ImageList control to randomly change the background of the main interface. First, add a group of images to the ImageList control, instantiate a Random class, and use the Next method to generate a Random number to determine which image is set as the background.
Create a project. The default form is Form1. Add the ImageList control to the Form1 form and add images to the ImageList control.
Namespace _ 026_RandomBackGround {public partial class Form1: Form {public Form1 () {InitializeComponent ();} private void Form1_Load (object sender, EventArgs e) {Random rdn = new Random (); // define a pseudo-random number generator object int I = rdn. next (imageList1.Images. count); // generate a random number this. backgroundImage = imageList1.Images [I]; // set the background image of the Form }}}