This is a migrated thread and some comments may be shown as answers.

Active from screen capture

2 Answers 294 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Chian Yuh
Top achievements
Rank 2
Chian Yuh asked on 06 Nov 2015, 12:40 PM

I have 2 forms:1 is parent form and another is child form. When I click capture the active screen, the title(Black area) of the image that I captured will be in black color. I couldn't capture the whole active screen(child form) including the form title.

 

Here is my code:

 

private void btnCapture_Click(object sender, EventArgs e)

{

    Form activeChild = this.ActiveMdiChild;

if (activeChild == null){MessageBox.Show("no active form child found!");return;}else{SaveAsBitmap(activeChild, activeChild + ".Jpeg");MessageBox.Show("Screen Captured successfully.");}}public void SaveAsBitmap(Control control, string fileName){SaveFileDialog dialog = new SaveFileDialog(); dialog.Filter = "JPeg Image|*.jpg|Bitmap Image|*.bmp|Gif Image|*.gif";if (dialog.ShowDialog() == DialogResult.OK){Graphics g = control.CreateGraphics();Bitmap bmp = new Bitmap(control.Width, control.Height); control.DrawToBitmap(bmp, new Rectangle(0, 0, control.Width, control.Height)); bmp.Save(dialog.FileName, ImageFormat.Jpeg);//bmp.Save("C://test.jpg", ImageFormat.Jpeg);}}

2 Answers, 1 is accepted

Sort by
0
Chian Yuh
Top achievements
Rank 2
answered on 06 Nov 2015, 01:10 PM

Sorry. Please refer to this. I attached the image.
Thank you.

 Code:

 private void btnCapture_Click(object sender, EventArgs e)

   {
        Form activeChild = this.ActiveMdiChild;
        if (activeChild == null)

{
            MessageBox.Show("no active form child found!");
            return;
        }
        else
        {
            SaveAsBitmap(activeChild, activeChild + ".Jpeg");
            MessageBox.Show("Screen Captured successfully.");
        }
    }

    public void SaveAsBitmap(Control control, string fileName)
    {
        SaveFileDialog dialog = new SaveFileDialog();
        dialog.Filter = "JPeg Image|*.jpg|Bitmap Image|*.bmp|Gif Image|*.gif";
        if (dialog.ShowDialog() == DialogResult.OK)
        {
            Graphics g = control.CreateGraphics();
            Bitmap bmp = new Bitmap(control.Width, control.Height);
            control.DrawToBitmap(bmp, new Rectangle(0, 0, control.Width, control.Height));
            bmp.Save(dialog.FileName, ImageFormat.Jpeg);
            //bmp.Save("C://test.jpg", ImageFormat.Jpeg);

        }
    }

0
Hristo
Telerik team
answered on 09 Nov 2015, 01:38 PM
Thank you for writing.

I managed to reproduce the incorrect behavior and I logged this issue in our feedback portal. You can track its progress, subscribe for status changes and add your vote/comment to it on the following link - feedback item. I have also updated Telerik points

Until a permanent fix becomes available please use the following workaround: 
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);
    }
}

I hope this helps. Should you have further questions please do not hesitate to write back.

Regards,
Hristo Merdjanov
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
General Discussions
Asked by
Chian Yuh
Top achievements
Rank 2
Answers by
Chian Yuh
Top achievements
Rank 2
Hristo
Telerik team
Share this question
or