C # A small progress bar for custom controls,

Source: Internet
Author: User

C # A small progress bar for custom controls,

First look:

A very concise progress bar.

Complete Project source code download: http://files.cnblogs.com/files/tuzhiyuan/%E8%BF%9B%E5%BA%A6%E6%9D%A1%E6%8E%A7%E4%BB%B6%E8%87%AA%E5% AE %9A%E4%B9%891.rar

The following code is used:

1 int _ now = 1; 2 Color hatchColor; 3 public MYProgressBar () 4 {5 InitializeComponent (); 6} 7 // set the current progress position 8 [Description ("set the current progress position")] // Description 9 displayed in the property design view [DefaultValue (typeof (Int32 ), "0")] // give the initial value 10 public int Value11 {12 13 get14 {15 return _ now; 16} 17 set18 {19 if (value> 100) 20 {21 _ now = 100; 22 SetJinDu (100); 23} 24 else if (value <0) 25 {26 _ now = 0; 27 SetJinDu (0 ); 28} 29 else30 {31 _ now = value; 32 SetJinDu (value); 33} 34} 35} 36 [Description ("set progress bar color")] // description 37 [DefaultValue (typeof (Color), "Control")] in the property design view // give the initial value 38 public Color BarColor39 {40 get {return hatchColor ;} 41 set42 {43 hatchColor = value; 44 panel1.BackColor = value; 45} 46} 47 private void MYProgressBar_Load (object sender, EventArgs e) 48 {49 50} 51 public void SetJinDu (int number) 52 {53 54 // obtain the control width 55 float db_this_width = this. width; 56 57 58 // percentage of the Progress Bar Width obtained by dividing the progress value by 100 59 float bfz = (float) number/100; 60 61 62 // control width multiplied by percentage to get the relative width of the progress bar Panel 63 panel1.Width = Convert. toInt32 (float) db_this_width * bfz); 64 65} 66 67 // control size change event 68 private void MYProgressBar_Resize (object sender, EventArgs e) 69 {70 panel1.Height = this. height; 71 SetJinDu (Value); 72}

In the winform toolbar, right-click "items"> "Browse" and select the custom control dll file. You can see it in the toolbar and drag it to use it.

The old saying is still incomplete and needs to be improved.

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.