问题标签 [winforms-interop]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
3 回答
2238 浏览

wpf - 动态应用程序级资源在 ElementHost 中托管时不是动态的

我在 WinForms 容器中托管 WPF UserControl。现在,我希望能够为 UserControl 设置主题/皮肤。为此,我有几个定义“皮肤”的资源字典。当我的应用程序启动时,我创建了一个“新 System.Windows.Application()”,以便 Application.Current 存在。为了改变主题,旧皮肤被删除,新皮肤在运行时被合并到应用程序级资源字典中。但是,这不会更改 UserControl 中任何动态引用的资源。我在一个直接的 WPF 应用程序中尝试了这个,它工作得很好。我错过了什么,或者根本不可能做到这一点?顺便说一句,如果我在初始化 UserControl 之前将皮肤添加到应用程序资源中,它将起作用,但之后我无法更改皮肤。

以最基本的方式回购这个:

创建一个新的 WinForms 应用程序。将 WPF UserControl 添加到应用程序。这很简单:

创建两个 ResourceDictionaries,White.xaml 和 Black.xaml(或其他),它们具有 SolidColorBrush,键为 ButtonBG,具有各自的颜色。在 Form1.cs 中,添加两个 Button 和一个 ElementHost。将 ElementHost 的子级设置为我们刚刚创建的 UserControl 的一个实例。将按钮连接到交换皮肤的事件:

在 Program.cs 中,确保 Application.Current 存在并设置初始皮肤:

现在,当单击白色按钮时,我希望用户控件中的按钮变为白色,当单击黑色按钮时,我希望按钮变为黑色。然而,这不会发生。

有谁知道为什么?有解决办法吗?

编辑:想法:也许,如果有一种方法可以在主题更改时强制重新评估 DynamicResources,那将起作用。

谢谢,尘土飞扬

0 投票
2 回答
3065 浏览

c# - C# Winforms-WPF 互操作

目前我有一个依赖透明效果的 Winforms 应用程序。然而事实证明,这在过去的背后绝对是一种痛苦!我正在学习的 Winforms 并不能很好地处理透明度问题。

我想知道将WPF组件用于透明度位和winforms用于其余部分是否会更容易(请注意,尽管我想将整个应用程序移至WPF,但这是不可行的!)。我对 WPF 几乎一无所知,因此我在这里!我正在考虑的是:

1) 在 Winforms 用户控件中托管 WPF 组件,例如 WPF 控件示例:

2) 在 WPF 控件的白色矩形(对话框)内承载一个 Winforms 用户控件(内容)。3) 允许内容(Winforms 用户控件)调用 WPF-Control 父级上的代码。

第一件事首先...

  • 这是一个合理的做法还是我吠错了树?
  • 这可以以更简单的方式实现吗?
  • 有人能帮我一下吗?(示例代码将不胜感激!)
  • 最后......有没有任何在线资源可以帮助我a)学习WPF和b)变得更加自给自足?
0 投票
2 回答
1644 浏览

winforms - 我可以将多个 COMCTL32.dll 加载到一个进程中吗?

我正在开发一个 ActiveX 控件,它(这些天)主要用于 WinForms 应用程序。

ActiveX 控件有一个“属性页”对话框,可以使用 AxHost 类的 ShowPropertyPages 方法以编程方式显示该对话框。这是可以在 Visual Studio 中用于编辑控件属性的自定义 UI。

此属性页对话框包含一个 ListBox 控件,该控件使用 ImageList 在列表项旁边显示图标。这些图标是 32 位 alpha 混合位图。为了使这些正确显示,必须使用6.0或更高版本的 COMCTL32.DLL。

不幸的是,当我运行我的 WinForms 应用程序时,它会加载并使用 COMCTL32.DLL version 5.xxx。结果,当显示属性页对话框时,图标看起来很糟糕(半透明区域以纯黑色绘制)。

我的问题是:有什么方法可以确保在 ActiveX 控件的属性页 UI 中使用 COMCTL32.dll 版本 6.0+,而不管进程使用的是什么?或者我可以强制主机进程使用 6.0 版吗?(我认为不是,因为我认为宿主进程可能已经在 ActiveX 控件中的任何代码之前将 COMCTL32.DLL 加载到内存中。

该网页涵盖了使用 COMCTL32 6.0 的一些场景,但不是我所处的情况。

0 投票
1 回答
1347 浏览

c# - 禁用或隐藏保存/打印预览对话框弹出窗口

我正在使用放置在 winform 上的 ActiveX 控件。当用户尝试保存或打印时,它总是会首先显示一个对话框;我想要么立即关闭对话框,要么一开始就不显示它。

有问题的控件不会引发任何事件,让我知道他们按下了什么按钮,所以我无法通过寻找“on_print”通知来取消它。

0 投票
1 回答
1257 浏览

winforms - Drag-and-drop modifies read-only WinForm container (plus other peculiarities of drag-and-drop)

Sampling drag-and-drop between WinForm RichTextBoxes within one application and between them and external applications revealed two interesting observations (item 1 certainly appears to be a bug; in a perfect world, item 2 would probably be as well):

  1. Some drag-and-drop operations delete the dragged text from the source container, whether or not it is set to read-only. (Thanks to Mark Morgan for first noticing this in his bug report on my open-source site.)
  2. Whether text is retained or deleted from a source container is inconsistent among different applications.

I could not find any definitive reference indicating what drag-and-drop behavior is supposed to be. The closest I found was on page 476 of the Windows User Experience Interaction Guidelines (for Vista): "Dragging and dropping: Object is moved or copied to the drop target". Well, that certainly aligns with my observations; some applications move the object, others copy it!

The questions: I would like to find a workaround for item 1 above; it irks me that a read-only container is not inviolate! As a secondary question, I am wondering if someone has a reference to how drag-and-drop is supposed to behave? When is it a move and when is it a copy?

My sample WinForm application (code below) contains two RichTextBox controls, the left one being read-only (call this RTB1) and initialized with some text; the right one (RTB2) being read/write so it may receive text. Both have drag-and-drop enabled for the test. Here are the combinations I tested; notice that in each grouping there is at least one "odd-man-out" :


  1. From RTB1 to RTB2: move
  2. From RTB1 to other RTB (external): move
  3. From RTB1 to WordPad: copy
  4. From RTB1 to Word2003: move
  5. From RTB1 to Outlook2003: copy
  6. From RTB1 to Firefox3.0: copy


  7. From RTB2 to other RTB (external): move

  8. From RTB2 to WordPad: copy
  9. From RTB2 to Outlook2003: copy
  10. From RTB2 to Firefox3.0: copy


  11. From Outlook2003 to RTB2: move

  12. From WordPad to RTB2: move
  13. From Word2003 to RTB2: move
  14. From other RTB (external) to RTB2: move
  15. From Firefox3.0 to RTB2: copy


  16. From Word2003 to Outlook2003: copy

  17. From Outlook2003 to Word2003 : move

Tests run on WinXP.
Test app compiled with .NET 2.0 (tried a couple with .NET 3.5 with the same results).


Here is the sample application:

0 投票
6 回答
4822 浏览

c# - 如何在 ac#win forms 应用程序上捕获键盘击键(CTRl + alt +Del)

有什么方法可以处理Ctrl+ Alt+Del组合键。以测验应用程序(Win Forms)为例,在测试结束之前,用户不应该能够切换到其他窗口。

我可以使用 c# 标准属性单独捕获CtrlAlt击键。但是一旦他们的用户按下了Del键。控件脱离了我的应用程序,Windows 处理它。

任何想法都会有所帮助。

谢谢。

0 投票
2 回答
4895 浏览

wpf - 如何在 WPF 应用程序中播放 flash

我有一个 WPF 应用程序,我想在其中播放 Flash 电影。

我使用了此链接中描述的 WInforms 活动 X 控件

它部分工作,但现在每当我运行应用程序时它崩溃说“InvalidActiveXStateException”

有谁知道如何解决这个问题?

0 投票
1 回答
474 浏览

.net - Iterop Forms Toolkit 验证和焦点事件

我有一个现有的 VB6 应用程序,我正在慢慢将其代码移至 DotNet,在很多情况下,这意味着必须使用 DotNet 用户控件并使用 Interop Forms Toolkit v2 将它们托管在 VB6 表单中。

目前的方法是用C#开发用户控件,然后拥有一个继承自C#版本的VB.NET用户控件,并以VB6形式承载VB.NET控件。

我唯一苦苦挣扎的部分是当下一个获得焦点的控件位于 Dotnet 用户控件之外时,尝试在文本框中捕获 Leave 或 Validated 事件。事件根本不会触发,或者我的处理程序不会运行。

有没有人解决了这个问题或者我错过了什么?

0 投票
3 回答
10331 浏览

c# - 将自定义上下文菜单项添加到 Windows 窗体标题栏

我在 MSDN 上找到了一个线程,该线程显示了如何将项目添加到 Windows 窗体标题栏的上下文菜单中。

不幸的是,它没有显示如何使用自定义菜单项注册事件,我一直无法弄清楚如何去做。下面是一个示例应用程序,可以将其复制并粘贴到新的 Windows 窗体应用程序中。我怎样才能完成样品?

0 投票
3 回答
285 浏览

wpf - WPF App - 如何获取对相应 System.Windows.Forms.Form 的引用?

在我的 WPF 项目中,我有一个 WPF 窗口。我想在我的 WPF 项目中使用Sticky Windows 解决方案。该库只需要一个参数:System.Windows.Forms.Form 对象。

是否存在从 WPF Window 对象开始获取 Form 对象的任何方法?