This article describes the method of adding progressbar to listview by .NET WinForm. Share it for your reference, as follows:
I searched for a long time but couldn't find it, so I just wrote one by myself:
First, add progressbar to the event that loads data to the listview:
foreach (string d in arr) { int index = + 1; item = new ListViewItem(new string[] { (), d, "", "", "", "" }); (item); float progress = 0; Rectangle SizeR = default(Rectangle); ProgBar = new (); SizeR = [2].Bounds; = [2].Width; = lv; (, , , ); = (int)progress; = true; //Give a unique name, it's easy to find it later = d + "progressbar"; }
Then set its value where you need to modify the progressbar's value:
//Loop all controls on the listview and find progressbar by nameforeach (Control item in ) { if ( == + "progressbar") { ProgressBar bar = (ProgressBar)item; = (int)(() * 100); } }
In fact, we just fixed the progressbar in the grid specified by the listview according to the length, width and height. If we drag the column in the listview, the position of the grid will change. At this time, we need to modify the position of the corresponding processbar. We need to add the ColumnWidthChanging event. When dragging column, the progressbar will change its position as it is:
private void lvt_ColumnWidthChanging(object sender, ColumnWidthChangingEventArgs e) { Rectangle SizeR = default(Rectangle); int width = ; foreach (Control item in ) { // Find all progressbars based on the name if (("progressbar") >= 0) { ProgressBar bar = (ProgressBar)item; //Rectangle size=; SizeR=; //[2] is the place to place the progressbar =[2].Width; ([0].SubItems[2]., , , ); // = width; } } }
For more information about C#, please visit the special topic of this site:Summary of WinForm control usage》、《Summary of C# form operation skills》、《C# data structure and algorithm tutorial》、《Tutorial on the usage of common C# controls》、《Introduction to C# object-oriented programming tutorial"and"Summary of thread usage techniques for C# programming》
I hope this article will be helpful to everyone's C# programming.