In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "how to display the C# listview progress bar". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to display the C# listview progress bar".
Take a look at the specific implementation process.
The program is relatively simple, is to overload the implementation of listview, but very practical!
Using System; using System.Collections.Generic; using System.Text; using System.Windows.Forms; using System.Drawing; / / C # listview progress bar shows namespace WindowsApplication1 {class ListViewEx:System.Windows.Forms.ListView {public ListViewEx () {InitializeComponent ();} / / C # listview progress bar shows private Color mProgressColor = Color.Red; public Color ProgressColor {get {return this.mProgressColor;} set {this.mProgressColor = value }} private Color mProgressTextColor = Color.Black; public Color ProgressTextColor {get {return mProgressTextColor;} set {mProgressTextColor = value;} / / the C# listview progress bar shows public int ProgressColumIndex {set {progressIndex = value;} get {return progressIndex;}} int progressIndex =-1 / / < summary > / / check whether it can be converted to a floating point number / < / summary > const string numberstring = "0123456789."; private bool CheckIsFloat (String s) {/ / C # listview progress bar displays foreach (char c in s) {if (numberstring.IndexOf (c) >-1) {continue;} else return false;} return true } protected override void Dispose (bool disposing) {base.Dispose (disposing);} / / the C# listview progress bar shows private void InitializeComponent () {this.OwnerDraw = true; this.View = View.Details;} protected override void OnDrawColumnHeader (DrawListViewColumnHeaderEventArgs e) {e.DrawDefault = true; base.OnDrawColumnHeader (e) } protected override void OnDrawSubItem (DrawListViewSubItemEventArgs e) {if (e.ColumnIndex! = this.progressIndex) {/ / C # listview progress bar shows e.DrawDefault = true; base.OnDrawSubItem (e);} else {if (CheckIsFloat (e.Item.SubItems [e.ColumnIndex] .text)) / / determines whether the current subitem text can be converted to a floating point number {float per = float.Parse (e.Item. Subitems [e.ColumnIndex] .text); if (per > = 1.0f) {per = per / 100.0f;} Rectangle rect = new Rectangle (e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height); DrawProgress (rect, per, e.Graphics) } / / C # listview progress bar shows / draws the subitem private void DrawProgress (Rectangle rect, float percent) of the progress bar column Graphics g) {if (rect.Height > 2 & & rect.Width > 2) {/ / if ((rect.Top > 0 & & rect.Top < this.Height) & & (rect.Left > this.Left & & rect.Left < this.Width)) {/ / drawing progress int width = (int) (rect.Width * percent) Rectangle newRect = new Rectangle (rect.Left + 1, rect.Top + 1, width-2, rect.Height-2); using (Brush tmpb = new SolidBrush (this.mProgressColor)) {g.FillRectangle (tmpb, newRect);} newRect = new Rectangle (rect.Left + 1, rect.Top + 1, rect.Width-2, rect.Height-2); g.DrawRectangle (Pens.RoyalBlue, newRect); StringFormat sf = new StringFormat (); sf.Alignment = StringAlignment.Center Sf.LineAlignment = StringAlignment.Center; sf.Trimming = StringTrimming.EllipsisCharacter; newRect = new Rectangle (rect.Left + 1, rect.Top + 1, rect.Width-2, rect.Height-2); using (Brush b = new SolidBrush (mProgressTextColor)) {g.DrawString (percent.ToString ("p1"), this.Font, b, newRect, sf);} / / C# listview progress bar shows else {return } Thank you for your reading. The above is the content of "how to display the C# listview progress bar". After the study of this article, I believe you have a deeper understanding of how the C# listview progress bar is displayed, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.