c# - How to drawn my own progressbar on winforms? -
yoyo experts! have several progressbars on windowsform (not wpf), , use different colors each one. how can this? i've googled , , found have create own control. have no clue , how this. idea? example progressbar1 green, progressbar2 red.
edit: ohh, solve this, without removing application.enablevisualstyles(); line, because screw form looking :/
yes, create own. rough draft 80% there, embellish needed:
using system; using system.drawing; using system.windows.forms; class myprogressbar : control { public myprogressbar() { this.setstyle(controlstyles.resizeredraw, true); this.setstyle(controlstyles.selectable, false); maximum = 100; this.forecolor = color.red; this.backcolor = color.white; } public decimal minimum { get; set; } // fix: call invalidate in setter public decimal maximum { get; set; } // fix above private decimal mvalue; public decimal value { { return mvalue; } set { mvalue = value; invalidate(); } } protected override void onpaint(painteventargs e) { var rc = new rectanglef(0, 0, (float)(this.width * (value - minimum) / maximum), this.height); using (var br = new solidbrush(this.forecolor)) { e.graphics.fillrectangle(br, rc); } base.onpaint(e); } }
Comments
Post a Comment