"How to: Create A Smooth Progress Bar In Visual C # .NET" learning notes

xiaoxiao2021-03-06  75

Now use .NET, always feel that the function of the control .Net comes with a lot of functions, so refer to Microsoft's learning materials, I feel that I have complied with the Control or very simple.

How to: Create A Smooth Progress Bar in Visual C # .NET is how we do your own control

In fact, it is possible to do a good job of rewriting from the important functions.

For example onResize (), onpaint ()

protected override void OnPaint (PaintEventArgs e) {Graphics g = e.Graphics; SolidBrush brush = new SolidBrush (BarColor); float percent = (float) (val - min) / (float) (max - min); Rectangle rect = this .ClientRectangle; // calculate area for draking the progress. Rect.width = (int)); // Draw the program (brush, rect); // Draw A Three-Dimensional Border Around THE Control. Draw3dborder (G); // Clean Up. Brush.dispose (); g.dispose ();} Private Void Draw3DBorder (GRAPHICS G) {INT PENWIDTH = (int) Pens.White.Width ; g.DrawLine (Pens.DarkGray, new Point (this.ClientRectangle.Left, this.ClientRectangle.Top), new Point (this.ClientRectangle.Width - PenWidth, this.ClientRectangle.Top)); g.DrawLine (Pens. DarkGray, new Point (this.ClientRectangle.Left, this.ClientRectangle.Top), new Point (this.ClientRectangle.Left, this.ClientRectangle.Height - PenWidth)); g.DrawLine (Pens.White, new Point (this. ClientRectangle.left, this.clientRectangle.height - Penwidth, new Point (this.ClientRectangle.Width - PenWidth, this.ClientRectangle.Height - PenWidth)); g.DrawLine (Pens.White, new Point (this.ClientRectangle.Width - PenWidth, this.ClientRectangle.Top), new Point ( This.ClientRectangle.width - Penwidth, this.clientRectangle.Height - Penwidth);} This program is the appearance of your own control, very simple.

You can add controls, properties, methods, methods

Public int minimum {get {ket {} set {// prevent a negative value. if (value <0) {min = 0; // Make Sure That The Minimum Value Is Never set higher Than THE MAXIMUM VALUE. IF Value> max) {min = value; min = value;} // ensure value is still in} {val = min;} // invalidate the control to get a repaint. THIS.INVALIDATE (); }}} public int maximum {get {keturn} set {// make sure that the maximum value is never set limited} {min = value;} max = value; // make Sure That Value Is Still in Range. if (VAL> max) {VAL = max;} // invalidate the control to get a repaint. this.invalidate ();}} public int value {get {return val;} set { INT OLDVALUE = VAL; // make sure that the value does not stray outside the valid {value {val = min;} else f (value> max) {val = max;} else {val = value } // invalidate only the change area. Float percent; Rectangle newValueERECT = this.clientRectangle; Rectang Le OldRueRect = this.clientRectangle; // use a new value to calculate the Rectangle for Progress. Percent = (float) / (float) (MAX - min); newValueRect.Width = (int) ((Float) NewValueRect.width * percent; // use an old value to calculate the Rectangle for progress. Percent = (float) / (float) (mAX - min); OldValueRect.Width = (int) (INT) float) oldValueRect.Width * percent); Rectangle updateRect = new Rectangle ();. // Find only the part of the screen that must be updated if (newValueRect.Width> oldValueRect.Width) {updateRect.X = oldValueRect.Size. Width; UpdateRect.width = newValueRect.width - OldValueRect.width;

} Else {updateRect.X = newValueRect.Size.Width; updateRect.Width = oldValueRect.Width - newValueRect.Width;} updateRect.Height = this.Height; // Invalidate the intersection region only this.Invalidate (updateRect); /. / Note that this is forced to redraw, must have, otherwise the graph does not change ^ _ ^}} public color progressbarcolor // control color {get {returnal = value; // invalidate the control TO GET A Repaint. this.invalidate ();}} This is the feature added. Although this is a small example, it is powerful to our rookie. Net is strong. In this way we are complete Can develop controls that meet your requirements.

Program from Microsoft website

转载请注明原文地址:https://www.9cbs.com/read-121005.html

New Post(0)