C # gradually display the WinForm,

Source: Internet
Author: User

C # gradually display the WinForm,

C # gradually display the WinForm. Other people in this blog Park have already implemented it. The principle is very simple, that is, by regularly changing the transparency of the form (from 0 to 1, that is to say, transparency is from full transparency to opacity. I also follow this idea here, but the form I made is reusable, that is, after other forms inherit from it, the Code is as follows:

Using System; using System. componentModel; using System. windows. forms; namespace TEMS. forms {public partial class FormBase: Form {private Timer formTimer = null; // <summary> // obtain the Opacity attribute /// </summary> [DefaultValue (0)] [Browsable (false)] public new double Opacity {get {return base. opacity;} set {base. opacity = 0 ;}} public FormBase () {InitializeComponent (); formTimer = new Timer () {Interval = 100}; formTimer. tick + = new EventHandler (formTimer_Tick); base. opacity = 0;} private void formTimer_Tick (object sender, EventArgs e) {if (this. opacity> = 1) {formTimer. stop ();} else {base. opacity ++ = 0.2 ;}} private void FormBase_Shown (object sender, EventArgs e) {formTimer. start ();}}}

The following is the automatically generated code:

Namespace TEMS. forms {partial class FormBase {// <summary> // Required designer variable. /// </summary> private System. componentModel. IContainer components = null; // <summary> // Clean up any resources being used. /// </summary> /// <param name = "disposing"> true if managed resources shocould be disposed; otherwise, false. </param> protected override void Dispose (bool disposing) {if (disposing & & (Components! = Null) {components. dispose ();} base. dispose (disposing );} # region Windows Form Designer generated code // <summary> // Required method for Designer support-do not modify // the contents of this method with the code editor. /// </summary> private void InitializeComponent () {this. suspendLayout (); // FormBase // this. autoScaleDimensions = new System. drawing. sizeF (6F, 12F); this. autoScaleMode = System. windows. forms. autoScaleMode. font; this. clientSize = new System. drawing. size (284,262); this. name = "FormBase"; this. text = "FormBase"; this. shown + = new System. eventHandler (this. formBase_Shown); this. resumeLayout (false) ;}# endregion }}View Code

In the code, I used the NEW keyword to overwrite the Opacity attribute in the FORM class so that it is read-only and not editable. Some people may say that the read-only code of this attribute is not written properly, it should be to remove the SET accesser or SET the SET as private. That's right. The standard is to do this, but why not do it? The reason is that if the attribute is set to private, when other forms inherit it, because we generally create a standard form first, when a standard form is created, if there is a default value for the form attribute, the default value will be automatically generated for initialization. After the standard form is created, the base class will be changed to the FormBase class. This will cause an error: Opacity is read-only, no value assignment is allowed, so we can only make it read and write, but the assignment of the actual sub-form does not take effect, it has a read-only effect, of course, if you do not feel the trouble, you can set according to the standard attributes. After creating a form, clear the Opacity code and then change the inheritance class. This is also possible.

It is easy to use. It is the same as a normal form. We will not describe it here. You can copy the above Code to your project and use it directly.

In fact, through the above code, we can design a basic form class for the universal shutter switching effect. I will try to implement these functions if I have time. Hope you can support them. Thank you!

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.