Learning notes-simple example of progressbar

Source: Internet
Author: User

A simple example of a progress bar is actually not your own thing. Just keep a Learning Record.

Using system. Windows. forms;

// Add reference in step 1

Using system. Threading;

Using system. IO;

Namespace progressbar

{

Public partial class form1: From

{

Public form1 ()
{
Initializecomponent ();
}

// Step 2 defines the value of the delegate update progress bar
Private delegate void setpos (int ipos );
// Update the progress bar value in step 3
Private void settextmessage (int ipos)
{
If (this. invokerequired)
{
Setpos = new setpos (settextmessage );

// This. Invoke is used when the main thread is modified outside the main thread
This. Invoke (setpos, new object [] {IPOs });
}
Else
{
This. label1.text = IPOs. tostring () + @ "/100 ";
This. pgb. value = convert. toint32 (IPOs );
}
}

// Use progress bars and develop functions
Private void button#click (Object sender, eventargs E)
{
Thread fthread = new thread (New threadstart (sleept ));
// Open up a new thread
Fthread. Start ();
}

// Prompt message
Public Delegate void showmsg (string MSG );
Public void msgbox (string MSG)
{
If (this. invokerequired)
{
Showmsg show_msg = new showmsg (msgbox );
This. Invoke (show_msg, new object [] {MSG });
}
Else
{
MessageBox. Show (MSG );
}
}

Private void sleept ()
{
For (INT I = 0; I <200; I ++)
{
// Simple latency
Thread. Sleep (100 );
Settextmessage (100 * I/200 );
}
Settextmessage (100 );
Msgbox ("success ");
}

}

}

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.