Listview with progress bar

Source: Internet
Author: User
Public class listviewprogress: system. Windows. Forms. listview
{
Private string progresstext;

Private system. Drawing. Color progressbackcolor;

Public System. Drawing. Color progressbackcolor
{
Get {return progressbackcolor ;}
Set {progressbackcolor = value ;}
}
Private system. Drawing. Color progresstextcolor;

Public System. Drawing. Color progresstextcolor
{
Get {return progresstextcolor ;}
Set {progresstextcolor = value ;}
}
Private int progresscolumnindex =-1;

Public int progresscolumnindex
{
Get {return progresscolumnindex ;}
Set {progresscolumnindex = value ;}
}

Public listviewprogress ()
{
This. Name = "progresslistview ";
This. progressbackcolor = system. Drawing. color. yellowgreen;
This. progresstextcolor = base. forecolor;
This. ownerdraw = true;
}

Protected override void ondrawcolumnheader (system. Windows. Forms. drawlistviewcolumnheadereventargs E)
{
E. drawdefault = true;
Base. ondrawcolumnheader (E );
}

Protected override void ondrawsubitem (system. Windows. Forms. drawlistviewsubitemeventargs E)
{
If (E. columnindex = This. progresscolumnindex)
{
// Draw a progress bar
System. Drawing. Graphics progressgraphics = E. graphics;
System. Drawing. Rectangle progressrect = new system. Drawing. rectangle (
E. bounds. Left, E. bounds. Top, E. bounds. Width, E. bounds. Height );

If (progressrect. Height> 6 & progressrect. width> 6)
{
// Adjust to a new area to produce a certain interval
Progressrect = new system. Drawing.
Rectangle (E. bounds. Left + 2, E. bounds. Top + 2, E. bounds. Width-5, E. bounds. Height-5 );
Single percent = 0;
Try
{
Percent = convert. tosingle (E. Subitem. Text );
}
Catch
{
Percent = 0;
}
If (percent> 1.0f)
Percent = percent/100366f;
// External box
Progressgraphics. fillrectangle (system. Drawing. Brushes. White, progressrect );
Progressgraphics. drawrectangle (new system. Drawing. Pen (E. Subitem. forecolor), progressrect );

// Content
System. Drawing. Rectangle progresscontentrect = new rectangle (
Progressrect. Left + 1, progressrect. Top + 1, (INT) (progressrect. Width * percent)-1, progressrect. Height-1 );
Progressgraphics. fillrectangle (new system. Drawing. solidbrush (progressbackcolor), progresscontentrect );
// Output text
If (E. Subitem. Font. height <progressrect. Height)
{
Progressrect = new system. Drawing. rectangle (progressrect. Left, progressrect. Top
-(Progressrect. Height-E. Subitem. Font. Height)/2), progressrect. Width, progressrect. Height );
}
Else
{
Progressrect = new system. Drawing. rectangle (E. bounds. Left, E. bounds. Top, E. bounds. Width, E. bounds. Height );
}
Using (stringformat Sf = new stringformat ())
{
SF. Alignment = system. Drawing. stringalignment. Center;
SF. linealignment = system. Drawing. stringalignment. Center;
SF. trimming = system. Drawing. stringtrimming. ellipsischaracter;

E. Graphics. drawstring (percent. tostring ("p1"), E. Subitem. Font,
New system. Drawing. solidbrush (this. progresstextcolor), progressrect, SF );
}
}
Base. ondrawsubitem (E );
}
Else
{
E. drawdefault = true;
Base. ondrawsubitem (E );
}
}
}

Usage: After the data is loaded, set the progresscolumnindex attribute.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.