Force create handle for Control

后端 未结 5 669
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-17 21:30

I\'m currently creating a silent print module. The current control I\'m using is, it\'s making sure that the control handle is already created (IsHandleCreated)

相关标签:
5条回答
  • 2021-01-17 21:37

    I solved this annoying handle creation problem by settings the WS_VISIBLE of CreationParams. You may either override the CreationParams property of Control or call the CreateHandle method with appropriate CreateParams instance. See the link

    0 讨论(0)
  • 2021-01-17 21:51

    Calling private method CreateHandle will do the work.

    MethodInfo ch = frm.GetType().GetMethod("CreateHandle", BindingFlags.NonPublic | BindingFlags.Instance);
    ch.Invoke(frm, new object[0]);
    
    0 讨论(0)
  • 2021-01-17 21:56

    Try to overload CreateParams property getter. In it clear the WS_VISIBLE flag.

    0 讨论(0)
  • 2021-01-17 21:57

    I had the same problem with some other controls and used the Control.CreateControl() method:

    private void CheckForExistingHandle(Control control)
    {
        if (!control.IsHandleCreated)
            control.CreateControl();
    }
    

    But i don't know how it works with a print module.

    0 讨论(0)
  • 2021-01-17 22:02

    You have to access the Handle property (put the result in a dummy variable or something). Look in Reflector; it forces handle creation.

    0 讨论(0)
提交回复
热议问题