1. 程式人生 > >C# Winform UserControl 建立視窗控制代碼時出錯。 setVisibleCore createHandle

C# Winform UserControl 建立視窗控制代碼時出錯。 setVisibleCore createHandle

這種問題,原因不好找的,嘗試在Form的子類中重寫一下CreateHandle,
如果建立不成功,通過RecreateHandle,一般都會成功

C# code?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

        protected override void CreateHandle()

        

{

            if (!IsHandleCreated)

            {

                try

                

{

                    base.CreateHandle();

                

                

catch {}

                finally

                {

                    if (!IsHandleCreated)

                    {

                        base.RecreateHandle();

                    }

                }

            }            

        }