ActiveX控件在一个主机容器中变为空白而在其他容器中不变

时间:2010-08-02 13:26:34

标签: winforms activex tstcon32

我需要使用activeX为遗留应用程序创建插件。我正在使用C#,以便我可以共享几个相关独立产品的代码库。

当我在SDK的测试容器(TstCon32.exe)中托管控件时,一切正常。问题是,当我尝试在目标应用程序中加载它时,我第一次点击控件,除了我点击的项目(文本框或数据网格单元格)之外的所有内容都涂有控件灰色,如果我更改了背景颜色控制到其他东西背景保持我指定的相同颜色,但所有控件仍然覆盖控制灰色(从容器应用程序?)。单击其他控件将导致它们绘制,调整控件的大小将导致重绘所有内容。初始消隐后,控制功能正常,直到下次创建副本为止。

1 个答案:

答案 0 :(得分:1)

我终于找到了解决方案。第一部分是将我的目标框架从4.0更改为先前版本。这揭示了当控件被消隐之前发生的异常,这是以前被消耗并对我隐藏的:

System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
   at System.Windows.Forms.UnsafeNativeMethods.IOleInPlaceSite.OnUIActivate()
   at System.Windows.Forms.Control.ActiveXImpl.InPlaceActivate(Int32 verb)
   at System.Windows.Forms.Control.ActiveXImpl.OnFocus(Boolean focus)
   at System.Windows.Forms.Control.ChildGotFocus(Control child)
   at System.Windows.Forms.Control.OnGotFocus(EventArgs e)
   at System.Windows.Forms.Control.WmSetFocus(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

从那里我能够找到tomasvdb的post,他遇到了与Google边栏相同的问题。

该帖子的一个回复链接到此message,它为侧边栏应用程序向.net控件发送无效数据的错误提供了一种解决方法。

在Control的VisibleChanged事件处理程序中调用该变通方法也解决了我的问题。