在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

Invisible or disabled control cannot be activated的更多相关文章

  1. System and method for dynamically adjusting to CPU performance changes

    FIELD OF THE INVENTION The present invention is related to computing systems, and more particularly ...

  2. IBM DB2 SQL error code list

    SQL return codes that are preceded by a minus sign (-) indicate that the SQL statement execution was ...

  3. NoVNC API 文档翻译

    原文地址:https://github.com/novnc/noVNC/blob/master/docs/API.md 时间:2019-05-21     noVNC API The interfac ...

  4. 计算机程序和C++语言简介

    C++程序设计 第一章 计算机程序和C++语言简介 1.计算机是一台能够存储并处理数据的电子设备,包含硬件和软件两部分. 2.计算机硬件由: 1)中央处理单元(Central Processing U ...

  5. Windows 窗体中的事件顺序(WinForm)

    引用MSDN,以便以后查看 引用:https://msdn.microsoft.com/zh-cn/library/86faxx0d.aspx 应用程序启动和关闭事件  Form 和 Control  ...

  6. Windows 窗体中的事件顺序

    来自:https://docs.microsoft.com/zh-cn/dotnet/framework/winforms/order-of-events-in-windows-forms 对于依次处 ...

  7. 修改文件夹的protection level之后,哪个job会来执行re-stripe的操作呢?

    有下面的一些job可能参与其中的,他们的描述如下: AutoBalance,AutoBalanceLin - Balances free space in the cluster. The goal ...

  8. WinForm 生命周期, WinForm 事件执行顺序

    1.窗体启动: Control.HandleCreatedControl.BindingContextChangedForm.LoadControl.VisibleChangedForm.Activa ...

  9. 让 Winform 窗口悬浮的简单方式

    很多次设置这个 TopMost 属性会莫名的不起作用,有时又可以.一直在想是为什么会这样? 后来多次尝试,发现这个属性必须在窗体某些其他属性后设置,比如在 Height.Width 这样的属性后. 看 ...

随机推荐

  1. GoodsAndStaffManagermentSystem----Sprint 计划1

    需求分析:茗仕茶业管理系统是个商品-员工综合管理系统. 员工管理:设置不同的职位,不同职位有不同访问权限.员工只能卖商品,财务员只有查看商品的库存量和商品销售记录:公司老板可以查看所有信息--    ...

  2. HDFS Append时packet的格式以及DataNode对block/checksum文件的处理

    HDFS Append时packet的格式以及DataNode对block/checksum文件的处理 HDFS的Block一般比较大,默认64MB/128MB,客户端给DataNode发数据实际上是 ...

  3. html5菜单折纸效果

    类似猎豹浏览器安装时的用户须知效果. html文件代码,保存为html文件打开: <!DOCTYPE html> <html> <head> <meta ht ...

  4. [CLR via C#]25. 线程基础

    一.Windows为什么要支持线程 Microsoft设计OS内核时,他们决定在一个进程(process)中运行应用程序的每个实例.进程不过是应用程序的一个实例要使用的资源的一个集合.每个进程都赋予了 ...

  5. jquery实现表格内容筛选

    对于表格来说,当数据比较多的时候,我们无法一页一页的查找,这时可以通过一个搜索框来实现搜索. 对于这个搜素框,我们为了更好的体验可以利用keyup事件实现在用户输入的时候就开始筛选,而不是填完以后点击 ...

  6. .NET开发 正则表达式中的 Bug

    又发现了一个 .net 的 bug!最近在使用正则表达式的时候发现:在忽略大小写的时候,匹配值从 0xff 到 0xffff 之间的所有字符,正则表达式竟然也能匹配两个 ASCII 字符:i(code ...

  7. Linq之Lambda表达式

    一 什么是LINQ? LINQ即Language Integrated Query(语言集成查询),LINQ是集成到C#和Visual Basic.NET这些语言中用于提供查询数据能力的一个新特性. ...

  8. Array(数组)与Json String (Json字符串) 的相互转换

    1.Array转换成Json String             function jsonToString(arr) {             var s = "";     ...

  9. 【图解】Eclipse下JRebel6.2.0热部署插件安装、破解及配置【转】

    标签: 这两天在做后台管理系统,前端框架用Bootstrap,后端用SpringMVC+Velocity.在开发过程中,经常需要对界面进行微调,调整传参等,每次更改一次java代码,就得重新部署一次, ...

  10. Linux初学者指南

    1.为啥我们要学习Linux? 我们干嘛要学习Linux? Linux能给我们带来什么价值呢? Linux给我的感觉就是稳定,免费,性能好. 稳定,体现在哪里?我们使用PC机,安装的操作系统一般是wi ...