DrawToBitmap RadForm not working with themes enabled

4 posts, 0 answers
  1. Amand
    Amand avatar
    25 posts
    Member since:
    Aug 2012

    Posted 15 Jun 2018 Link to this post

    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

     

  2. Dimitar
    Admin
    Dimitar avatar
    2728 posts

    Posted 18 Jun 2018 Link to this post

    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.
  3. Amand
    Amand avatar
    25 posts
    Member since:
    Aug 2012

    Posted 18 Jun 2018 in reply to Dimitar Link to this post

    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)

     

  4. Dimitar
    Admin
    Dimitar avatar
    2728 posts

    Posted 19 Jun 2018 Link to this post

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