Dou*_*rch 10
表单是控件,因此您应该能够将整个内容保存到位图,例如:
var bm = new Bitmap(yourForm.Width, yourForm.Height);
yourForm.DrawToBitmap(bm, bm.Size);
bm.Save(@"c:\whatever.gif", ImageFormat.Gif);Run Code Online (Sandbox Code Playgroud)
DrawToBitmap只画出屏幕上的内容.如果要绘制列表的全部内容,则必须遍历列表以查找内容的大小,然后绘制每个项目.就像是:
var f = yourControl.Font;
var lineHeight = f.GetHeight();
// Find size of canvas
var s = new SizeF();
using (var g = yourControl.CreateGraphics())
{
foreach (var item in yourListBox.Items)
{
s.Height += lineHeight ;
var itemWidth = g.MeasureString(item.Text, f).Width;
if (s.Width < itemWidth)
s.Width = itemWidth;
}
if (s.Width < yourControl.Width)
s.Width = yourControl.Width;
}
using( var canvas = new Bitmap(s) )
using( var g = Graphics.FromImage(canvas) )
{
var pt = new PointF();
foreach (var item in yourListBox.Items)
{
pt.Y += lineHeight ;
g.DrawString(item.Text, f, Brushes.Black, pt);
}
canvas.Save(wherever);
}Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5842 次 |
| 最近记录: |