简体   繁体   中英

How can I print a ListView in C#

Does any body have a solution for printing a multi column and row Listview in C#?

Thanks in Advance.

If you are using WinForms, the ObjectListView project has a ListViewPrinter component which will do exactly that.

It is described in this CodeProject article , but don't use the code from the article -- it's out of date. The most recent version is in the ObjectListView project.

It even handles grouping:

在此处输入图片说明

  private void SnapShotPNG(ListView source, string destination)
        {
            var lastHeight = source.Height;
            source.Height = 10000;
            Graphics canvas = source.CreateGraphics();            
            Bitmap bmp = new Bitmap(1000, 1000, canvas);
            source.DrawToBitmap(bmp, new Rectangle(0, 0, 1000, 1000));
            bmp.Save(destination);
            source.Height = lastHeight;
        }

Easy!!!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM