zoukankan      html  css  js  c++  java
  • Invisible or disabled control cannot be activated

    在WPF 应用程序下出现:Invisible or disabled control cannot be activated(不见的或禁用的控件不能被激活)错误。

    System.ArgumentException: Invisible or disabled control cannot be activated
       at System.Windows.Forms.ContainerControl.SetActiveControlInternal(Control value)
       at System.Windows.Forms.ContainerControl.SetActiveControl(Control ctl)
       at System.Windows.Forms.ContainerControl.set_ActiveControl(Control value)
       at System.Windows.Forms.Integration.WindowsFormsHost.RestoreFocusedChild()
       at System.Windows.Forms.Control.InvokeMarshaledCallbackDo(ThreadMethodEntry tme)
       at System.Windows.Forms.Control.InvokeMarshaledCallbackHelper(Object obj)
       at System.Threading.ExecutionContext.runTryCode(Object userData)
       at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Windows.Forms.Control.InvokeMarshaledCallback(ThreadMethodEntry tme)
       at System.Windows.Forms.Control.InvokeMarshaledCallbacks()

    解决办法:

    该错误是线程的问题,对程序运行无影响,可以考虑过滤该错误。

    方法如下:

    1 确保删除的控件不是不见的或禁用的控件。

    2 过滤该错误方法。

    public MainWindow()
            {
                System.Windows.Forms.Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
            }

            void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
            {
                if (!FailureFromFocusedChild(e.Exception))
                {
                    System.Windows.Forms.Application.ThreadExceptionDialog dlg;
                    dlg = new System.Windows.Forms.Application.ThreadExceptionDialog(e.Exception);
                    dlg.ShowDialog();
                }

            private bool FailureFromFocusedChild(Exception e)
            {
                bool result = false;
                string stackTrace = e.StackTrace;
               
                result = (e is System.ArgumentException) && (e.Source == "System.Windows.Forms")
                        && (stackTrace.IndexOf("System.Windows.Forms.Integration.WindowsFormsHost.RestoreFocusedChild")>=0);


                return result;
            }

    参考:http://support.microsoft.com/kb/2686194

  • 相关阅读:
    12套有用的免费 PSD 格式 Android UI 素材
    使用 Canvas 和 JavaScript 创建逼真的下雨效果
    在网页设计中使用漂亮字体的16个优秀例子
    Koala – 开源的前端预处理器语言图形编译工具
    BackgroundCheck – 根据图片亮度智能切换元素样式
    经典网页设计:18个示例展示图片在网页中的使用
    TogetherJS – 酷!在网站中添加在线实时协作功能
    30个令人惊叹的灵感来自自然风光的网站设计《下篇》
    太有才了!创新的街头涂鸦手绘欣赏【中篇】
    15款美丽的设备模板,帮助展示你的 APP
  • 原文地址:https://www.cnblogs.com/chhuic/p/3245939.html
Copyright © 2011-2022 走看看