Active from screen capture

3 posts, 0 answers
  1. Chian Yuh
    Chian Yuh avatar
    3 posts
    Member since:
    Jul 2015

    Posted 06 Nov 2015 Link to this post

    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. Chian Yuh
    Chian Yuh avatar
    3 posts
    Member since:
    Jul 2015

    Posted 06 Nov 2015 Link to this post

    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);

            }
        }

  3. UI for WinForms is Visual Studio 2017 Ready
  4. Hristo Merdjanov
    Admin
    Hristo Merdjanov avatar
    711 posts

    Posted 09 Nov 2015 Link to this post

    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
Back to Top