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

DrawToBitmap RadForm not working with themes enabled

3 Answers 19 Views
This is a migrated thread and some comments may be shown as answers.
Amand
Top achievements
Rank 1
Amand asked on 15 Jun 2018, 03:05 PM

Hi,

I try to save the content of a simple RadForm to a Bitmap.The non client area of the form is not drawn at all (transparent value). If I disable Theming, it works.

Here is the code I used :

static void Main()
{
    Application.EnableVisualStyles();
    var form = new RadForm1();
     //form.AllowTheming = false;  --> Works is Theming is disabled ! Otherwise no.
    form.Show();
    var rect = new Rectangle(0, 0, form.Bounds.Width, form.Bounds.Height);
    var image = new Bitmap(rect.Width, rect.Height);
    form.DrawToBitmap(image, rect);
    image.Save("d:/test.png");
}

 

How can I force the drawing of the NC area of the form ?

Thks

 

3 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 18 Jun 2018, 08:32 AM
Hello Amand,

The DrawToBitmap method comes from .NET and we do not have control over what is drawn. In this case, you can create your own method that saves a screenshot of the window. An example is available in the following post: c# - Get a screenshot of a specific application. Check the second answer and use the code from it. I have tested it on my side and it captures the entire form.

I hope this will be useful. Let me know if you have additional questions. 

Regards,
Dimitar
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Amand
Top achievements
Rank 1
answered on 18 Jun 2018, 12:51 PM

Hi Dimitar,

Thanks for your answer and the link but I would like to avoid doing a screenshot because of some other reasons (some side effects in our test pipeline)

How do you explain that the theme is correctly applied to the client area of the form. Do you guys intercept and implement WM_PRINT messages for NC areas  ? (https://msdn.microsoft.com/fr-fr/library/windows/desktop/dd145216(v=vs.85).aspx)

 

0
Dimitar
Telerik team
answered on 19 Jun 2018, 12:18 PM
Hi Amand,

No, the WM_PRINT message is not causing this. We are intercepting the most of the NC area messages (WM_NCUAHDRAWCAPTION, WM_NCUAHDRAWFRAME, WM_NCPAINT, WM_NCCALCSIZE) and performing various actions instead of painting the default NC area.

Could you share more inforation about your exact case? Why do you need such functionality (taking image on NC area)? 

The suggested solution uses a similar to the DrawToBitmap method code. However is just gets the screen rectangle. Why exactly is it not possible to use it? I have attached a small example that shows how you can use this approach.

I am looking forward to your reply.

Regards,
Dimitar
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Asked by
Amand
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Amand
Top achievements
Rank 1
Share this question
or