using System.Drawing; using System.Drawing.Drawing2D; using System.Windows.Forms; using FastReport.Dialog; namespace FastReport.Utils { partial class DrawUtils { public static Bitmap DrawToBitmap(Control control, bool children) { if (control is Form form) return DrawForm(form); Bitmap bitmap = new Bitmap(control.Width, control.Height); using (Graphics gr = Graphics.FromImage(bitmap)) { gr.Clear(control.BackColor); } control.DrawToBitmap(bitmap, new Rectangle(0, 0, control.Width, control.Height)); return bitmap; } private static Bitmap DrawForm(Form form) { var width = form.FrameSize().Width; var height = form.FrameSize().Height; var offset = form.ClientAreaOffset(); Bitmap bitmap = new Bitmap(width, height); using (Graphics gr = Graphics.FromImage(bitmap)) { gr.Clear(SystemColors.Window); using (GraphicsPath gp = new GraphicsPath()) { var radius = 16; gp.AddArc(0, 0, radius, radius, 180, 90); gp.AddLine(radius, 0, width - radius, 0); gp.AddArc(width - radius - 1, 0, radius, radius, 270, 90); gp.AddLine(width - 1, radius, width - 1, height - 1); gp.AddLine(width - 1, height - 1, 0, height - 1); gp.CloseFigure(); var captionColor = SystemBrushes.InactiveCaption; gr.FillPath(captionColor, gp); gr.DrawPath(Pens.Gray, gp); using (var br = new SolidBrush(form.BackColor)) { gr.FillRectangle(br, offset.X, offset.Y, form.ClientRectangle.Width, form.ClientRectangle.Height); } #if AVALONIA gr.FontScale = (float)form.DpiScale; #endif TextRenderer.DrawText(gr, form.Text, form.Font, new Rectangle(8, 0, width, offset.Y), SystemColors.WindowText, SystemColors.InactiveCaption, TextFormatFlags.VerticalCenter); } } return bitmap; } } }