c# - Custom ProgressBar control issue -


i created simple cool progressbar control using tutorial. however, i'm facing issue. code:

using system; using system.collections.generic; using system.drawing; using system.drawing.drawing2d; using system.linq; using system.text; using system.threading.tasks; using system.windows.forms;  namespace revarz {     class graphicshelper     {         public graphicspath createround(int x, int y, int width, int height, int cornerradius)         {             graphicspath gfxpath = new graphicspath();             try             {                 gfxpath.addarc(x, y, cornerradius, cornerradius, 180, 90);                 gfxpath.addarc(x + width - cornerradius, y, cornerradius, cornerradius, 270, 90);                 gfxpath.addarc(x + width - cornerradius, y + height - cornerradius, cornerradius, cornerradius, 0, 90);                 gfxpath.addarc(x, y + height - cornerradius, cornerradius, cornerradius, 90, 90);                 gfxpath.closeallfigures(); return gfxpath;             }             catch (exception) { return null; }         }     }      public class customprogressbar : control     {          public int value { get; set; }         private int _maximum = 100;         public int maximum         {             { return _maximum; }             set { if (value > 0) { _maximum = value; } else { throw new exception("maximum should bigger zero!"); }; }         }          public customprogressbar()         {             setstyle(controlstyles.allpaintinginwmpaint | controlstyles.optimizeddoublebuffer | controlstyles.userpaint | controlstyles.resizeredraw, true);             doublebuffered = true;         }          protected override void onpaint(painteventargs e)         {             e.graphics.clear(backcolor);             e.graphics.smoothingmode = smoothingmode.highquality;               graphicspath barpath = new graphicshelper().createround(0, 0, width - 1, height - 1, 3);             e.graphics.drawpath(new pen(color.fromargb(50, color.black)), barpath);             e.graphics.setclip(barpath);             lineargradientbrush lgb = new lineargradientbrush(new rectangle(0, 2, width - 1, height - 3), color.fromargb(241, 229, 201), color.fromargb(237, 218, 202), 90f);             e.graphics.fillrectangle(lgb, lgb.rectangle);             e.graphics.resetclip();              int drawwidth = (int)(((double)value / (double)_maximum) * (double)(width - 1));             if (drawwidth > 1)             {                 graphicspath filledpart = new graphicshelper().createround(0, 0, drawwidth, height - 1, 3);                 lineargradientbrush lgb2 = new lineargradientbrush(new rectangle(0, 1, drawwidth, height - 2), color.fromargb(232, 119, 9), color.fromargb(255, 171, 3), 90f);                 e.graphics.fillrectangle(lgb2, lgb2.rectangle);                 e.graphics.drawpath(new pen(color.fromargb(146, 101, 11)), filledpart);             }              base.onpaint(e);         }        } } 

the issue that, when increase value, value doesn't acutally apply (the bar itself, doesn't increase). firned told me have invalidate value when it's changed, have no idea how so!

i'd help, thanks!

you need call invalidate() method force repaint:

int _value; public int value {    { return _value;}    set {        if(_value != value) {            _value = value;            invalidate();        }    } } 

Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -