Unplanned
Last Updated: 17 Feb 2017 13:34 by Vladimir
ADMIN
Hristo
Created on: 09 Nov 2015 11:52
Category: Form
Type: Bug Report
0
FIX. RadForm - the title bar is not painted if the form is saved as an image by calling the DrawToBitMap method
How to reproduce: 
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();

        this.IsMdiContainer = true;
        this.Load += Form1_Load;
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        RadForm form = new RadForm();
        form.Text = "MDI Child 1";
        form.MdiParent = this;
        form.Show();
    }

    private void radButton1_Click(object sender, EventArgs e)
    {
        RadForm activeChild = this.ActiveMdiChild as RadForm;
        if (activeChild == null)
        {
            MessageBox.Show("no active form child found!");
            return;
        }
        else
        {
            SaveAsBitmap(activeChild, activeChild + ".Jpeg");
            MessageBox.Show("Screen Captured successfully.");
        }
    }

    public void SaveAsBitmap(Form form, string fileName)
    {
        SaveFileDialog dialog = new SaveFileDialog();
        dialog.Filter = "JPeg Image|*.jpg|Bitmap Image|*.bmp|Gif Image|*.gif";
        if (dialog.ShowDialog() == DialogResult.OK)
        {
            Bitmap bmp = new Bitmap(form.Width, form.Height);
            form.DrawToBitmap(bmp, new Rectangle(0, 0, form.Width, form.Height));
            bmp.Save(dialog.FileName, ImageFormat.Jpeg);
        }
    }
}

Workaround:

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();

        this.IsMdiContainer = true;
        this.Load += Form1_Load;
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        RadForm form = new RadForm();
        form.Text = "MDI Child 1";
        form.MdiParent = this;
        form.Show();
    }

    private void radButton1_Click(object sender, EventArgs e)
    {
        RadForm activeChild = this.ActiveMdiChild as RadForm;
        if (activeChild == null)
        {
            MessageBox.Show("no active form child found!");
            return;
        }
        else
        {
            SaveAsBitmap(activeChild, activeChild + ".Jpeg");
            MessageBox.Show("Screen Captured successfully.");
        }
    }

    public void SaveAsBitmap(Form form, string fileName)
    {
        Bitmap bmpScreenshot = new Bitmap(form.Bounds.Width, form.Bounds.Height, PixelFormat.Format32bppArgb);
        Graphics gfxScreenshot = Graphics.FromImage(bmpScreenshot);
        Point pt = form.Parent.PointToScreen(form.Location);
        gfxScreenshot.CopyFromScreen(pt.X, pt.Y, 0, 0, form.Bounds.Size, CopyPixelOperation.SourceCopy);
        SaveFileDialog saveImageDialog = new SaveFileDialog();
        saveImageDialog.Title = "Select output file:";
        saveImageDialog.Filter = "JPeg Image|*.jpg|Bitmap Image|*.bmp|Gif Image|*.gif";
        if (saveImageDialog.ShowDialog() == DialogResult.OK)
        {
            bmpScreenshot.Save(saveImageDialog.FileName, ImageFormat.Png);
        }
    }
}
1 comment
Vladimir
Posted on: 17 Feb 2017 13:34
deleted by v_temporarus