none
Inherited NumericUpDown control not painted when maximize and restore it RRS feed

  • Question

  • I have inherited MS NumericUpDown control in winforms and override CreateParams property to avoid flickering issue it will causes the control to not painted when maximize and restore the form. I have set anchor as Top,Right. Please find my code on below


    using System.Windows.Forms;

    namespace PaintingIssue { public partial class Form1 : Form { string test = string.Empty; public Form1() { InitializeComponent(); } } public class MyUpDpwn : NumericUpDown { protected override /*ContainerControl*/ CreateParams CreateParams { get { CreateParams cp = base.CreateParams; cp.ExStyle |= 0x02000000; return cp; } } } }

    For ease,

    1. Run the sample - PaintingIssue.
    2. Maximize the form.
    3. Then click the caption bar and drag to restore the form.(Maximize the form and back to previous state of the form)
    4. Now derived control is not painted until you perform any action on control.

    Please provide any solution for this issue!!!






    • Edited by ssaran046 Friday, June 7, 2019 7:20 AM
    Friday, June 7, 2019 5:23 AM

All replies

  • Hello,

    I have not looked at your sample so the following may not work for you.  

    https://stackoverflow.com/questions/8046560/how-to-stop-flickering-c-sharp-winforms

    public class MyUpDpwn : NumericUpDown
    {
        protected override /*ContainerControl*/ CreateParams CreateParams
        {
            get
            {
                var cp = base.CreateParams;
    
                cp.ExStyle |= 0x02000000;
                return cp;
            }
        }
    
        public MyUpDpwn()
        {
            SetStyle(
                ControlStyles.UserPaint |
                ControlStyles.AllPaintingInWmPaint |
                ControlStyles.OptimizedDoubleBuffer,
                true);
        }
    }


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Friday, June 7, 2019 9:55 AM
    Moderator
  • Hi ssaran046,

    Please try to add the following code to override "CreateParams" in the form class.

        protected override CreateParams CreateParams
        {
            get
            {
                CreateParams cp = base.CreateParams;
                cp.ExStyle |= 0x02000000;  // Turn on WS_EX_COMPOSITED
                return cp;
            }
        }

    Regards,

    Kyle


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, June 10, 2019 3:12 AM
    Moderator
  • Hi ssaran046,

    Did you keep your original code? I tested it on my machine, and it works fine.

    Regards,

    Kyle


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, June 10, 2019 5:12 AM
    Moderator
  • Hi Kyle,

    Please try my sample and ensure whether it is working on your machine. Follow the steps mentioned in the questions.

    Sample link : PaintingIssue

    Thanks & Regards

    Saravanan G



    • Edited by ssaran046 Monday, June 10, 2019 7:29 AM
    Monday, June 10, 2019 7:25 AM
  • Hi ssaran046,

    Yes, I just modified it in the demo you provided.

    Here is the modified project: 

    https://1drv.ms/u/s!AqgLs2tdMyFNg2ZzIBQ2FNmV2tm0.

    Regards,

    Kyle


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, June 10, 2019 7:33 AM
    Moderator
  • Hi Kyle,

    I have used derived control as UserContol, so we want handle this issue in UserControl not Form. So If there any possibilities to fix this issue on UserContol rather than Form?

    Thanks for the response!!!

    Regards,

    Saravanan G


    • Edited by ssaran046 Monday, June 17, 2019 5:06 AM
    Monday, June 17, 2019 5:04 AM
  • Hi,

    Similarly, have you tried rewriting the method "CreateParams" in the class "UserControl"?

    Regards,

    Kyle


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, June 18, 2019 6:35 AM
    Moderator
  • Hi Kyle,

    Yes, I have tried but it is not working. If any possibilities to provide solution on derived class itself rather than form.

    Regards,

    Saravanan G


    G.Saravanan

    Wednesday, June 19, 2019 4:54 AM
  • Hi ssaran046,

    Sorry, I didn't understand your needs. Can you provide your current project and explain it in detail?

    Regards,

    Kyle


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, June 20, 2019 9:43 AM
    Moderator
  • Hi Kyle,

    You have provided a solution by rewriting "CreateParams" method on Form1 class but my need is, I want solution code on MyUpDown class itself, So If there any possibilities to provide solution on MyUpDown class itself rather than Form1 class.

    Regards,

    Saravanan


    G.Saravanan


    • Edited by ssaran046 Thursday, June 20, 2019 12:15 PM
    Thursday, June 20, 2019 12:14 PM
  • Hi ssaran046,

    If so, I advise you define the class "MyUpDpwn" in a UserControl, rather than the form. And then, you just need to override "CreateParams" in the class "UserControl".

    Regards,

    Kyle


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, June 21, 2019 9:56 AM
    Moderator
  • Hi Kyle,

    This is my issue, I have used  "MyUpDpwn" in UserControl and then overriden "CreateParams" in the class UserControl but it is not working. I need solution for this one, If there any possible solution for this issue!!

    Regards,

    Saravanan G


    G.Saravanan

    Friday, June 21, 2019 11:44 AM