C # transparent button and transparent gradient generated when the form is closed

Source: Internet
Author: User

On various technical forums related to. net, people often ask how to achieve transparent images or graphic effects. The answer is simple: alpha blending technology. Alpha blending technology is a process of mixing various color values to produce transparent effects. The specific implementation principle is also very simple: in GDI +, any color consists of four components-Alpha, red, green and blue. The Alpha component represents the transparency of a color. Its value ranges from 0 to 255. It is self-evident that 0 means completely transparent, while 255 means completely opaque. Therefore, you only need to use the transparent effect to create a color and use the color to draw an image to complete the transparent processing of the image.

Button transparency: Set the backcolor of the button to 0, 0, 0, and set the bordersize of flatapperance to 0 and flatstyle to flat. This makes the button completely transparent, this effect is often used as skin in the background, and a button is placed in the corresponding position to control button events, but users do not want to see the button;

C # transparent gradient generated when the form is closed:

A few days ago, I accidentally heard someone say that I want to get a form gradient. Then I searched the internet and found some methods. I tried it successfully, but there are still some {
Function onclick ()
{
Function onclick ()
{
Tagshow (Event)
}
}
} "> Problem, depressing... The following are some of my methods:
① New key form, add a button to the form, double-click the button to enter event writing {
Function onclick ()
{
Function onclick ()
{
Tagshow (Event)
}
}
} "> Code:
While (this. Opacity> 0)
{
This. OPS-= 0.02;
Thread. Sleep (20 );
}
Application. Exit ();
After the program runs, click this button to close the program. The entire form first turns black, then the transparency gradually decreases, and the program exits when it turns 0. In theory, this idea should be correct, but I don't know what's going on?
② Add the timer control to the form, and set interval to 20 ,{
Function onclick ()
{
Function onclick ()
{
Tagshow (Event)
}
}
} "> Control Event code:
If (this. Opacity> 0)
{
This. OPS-= 0.02;
}
Else {
Application. Exit ();
}
Then write timer1.start (); In the button clicking event {
Function onclick ()
{
Function onclick ()
{
Tagshow (Event)
}
}
} "> Test, this method is acceptable. The form is slowly becoming transparent and then closed...
However, the problem arises again. I want to close the form gradient when I click the close button in the upper-right corner of the form. I enter timer1.start () in the formclosing event of the form to test, the result is that when I click the close button in the upper-right corner of the form, the program exits directly, and the gradient does not disappear. I am depressed and don't know what the problem is. Then I went online for a long time, find a solution. In the formclosing event, enter e. cancel = true; timer1.start (); test, result, click Close, the form is gradient disappears, but when the transparency is 0, it is not closed, the icon on the taskbar is still present, and the task manager also has the corresponding process.

The problem has been solved.
Private void form=formclosing (Object sender, formclosingeventargs E)
{
Timer1.start ();
E. Cancel = false;

}
Two steps in reverse order
In this example, when the form is closed, the calling thread of the form reduces transparency one by one and cancel = false. This means that the form is closed without cancellation.
The landlord understands the error. True indicates that the form is canceled, so the form is not closed.

Cancel is usually written when the form is closed
Example:
Private void form=formclosing (Object sender, formclosingeventargs E)
{
Dialogresult DR = MessageBox. Show ("disable this form", "prompt", messageboxbuttons. yesno );
If (dialogresult. No = Dr) // if you click NO
{
E. Cancel = true; // cancel closing
}
}

Related Article

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.