110,538
社区成员
发帖
与我相关
我的任务
分享
private void DrawLabel(Label l, Graphics g)
{
Rectangle r = GetControlRect(l);
if (l.AutoSize)
{
r.Width = (int)g.MeasureString(l.Text, l.Font).Width;
}
if (l.BorderStyle != BorderStyle.None)
{
g.DrawRectangle(_pen, r);
}
r.Width = (int)(r.Width * 1.1);
r.Height = (int)(r.Height * 1.1);
if (l.TextAlign == ContentAlignment.BottomRight || l.TextAlign == ContentAlignment.MiddleRight || l.TextAlign == ContentAlignment.TopRight)
g.DrawString(GetControlText(l), l.Font, l.Enabled ? new SolidBrush(l.ForeColor) : Brushes.Gray, (RectangleF)r, new StringFormat(StringFormatFlags.DirectionRightToLeft));
else
g.DrawString(GetControlText(l), l.Font, l.Enabled ? new SolidBrush(l.ForeColor) : Brushes.Gray, (RectangleF)r);
}
private void button1_Click(object sender, EventArgs e)
{
CaptureImage(this.Location,Point.Empty, new Rectangle(0,0,Width,Height), "a.bmp");
}
public static void CaptureImage(Point SourcePoint, Point DestinationPoint, Rectangle SelectionRectangle, string FilePath)
{
using (Bitmap bitmap = new Bitmap(SelectionRectangle.Width, SelectionRectangle.Height))
{
using (Graphics g = Graphics.FromImage(bitmap))
{
g.CopyFromScreen(SourcePoint, DestinationPoint, SelectionRectangle.Size);
}
bitmap.Save(FilePath, System.Drawing.Imaging.ImageFormat.Bmp);
}
}