VB6应用程序打开C#模态窗口时KeyPress触发点击事件

发布于 2024-12-15 17:15:22 字数 1059 浏览 2 评论 0原文

我创建了一个简单的 C# dll,由 VB6 应用程序调用。它只是以模态方式打开一个表单,没有其他任何东西。 ShowInTaskbar 设置为 false。

namespace ComTest{
  [ComVisible(true)]
  [Guid("0A62D0AC-F396-4089-ADF0-330B356E2559")]
  [ClassInterface(ClassInterfaceType.None)]
  public class Test
  {
    private frmTest frm = null;

    [STAThread]
    public void ShowForm()
    {
      frm = new frmTest();
      frm.ShowDialog();
      //...
    }
  }
}

表单上有一个按钮用于显示“单击按钮”消息框。

VB6 应用程序只是一个带有按钮的表单(ShowInTaskbar 设置为 true)。单击它会显示 C# 窗口。按“Esc”会根据按下的键显示一个消息框。

Private Sub Command1_Click()
  Dim test As Object
  Set test = CreateObject("ComTest.Test")
  If Not test Is Nothing Then
    test.ShowForm
  End If
  Set test = Nothing
End Sub

应用程序启动后(这只发生在启动项目 exe 时,而不是调试时!)并且按下按钮以打开 C# 对话框时,我选择应用程序的任务栏图标。 VB6 窗口处于焦点状态(为什么?),按“Escape”会打开另一个 C# 对话框(尽管第一个对话框仍然可见),就好像再次单击了该按钮一样。

表单上没有默认按钮;当没有打开的对话时,按“Escape”会弹出正确的消息框。

这种行为可以无限地重复。我尝试过设置父母和孩子,这种互操作应用程序的常见答案是使用互操作表单工具包。

我仍然不明白为什么按“Escape”会触发按钮单击事件。有人知道为什么吗?

提前致谢

I've created a simple C# dll which is to be called by a VB6 application. It just opens a form modally, nothing else. ShowInTaskbar is set to false.

namespace ComTest{
  [ComVisible(true)]
  [Guid("0A62D0AC-F396-4089-ADF0-330B356E2559")]
  [ClassInterface(ClassInterfaceType.None)]
  public class Test
  {
    private frmTest frm = null;

    [STAThread]
    public void ShowForm()
    {
      frm = new frmTest();
      frm.ShowDialog();
      //...
    }
  }
}

There's one button on the form to show a "button clicked"-message box.

The VB6 application is just a form (ShowInTaskbar set to true) with a button as well. Clicking it shows the C# window. Pressing "Esc" shows a message box according to the key pressed.

Private Sub Command1_Click()
  Dim test As Object
  Set test = CreateObject("ComTest.Test")
  If Not test Is Nothing Then
    test.ShowForm
  End If
  Set test = Nothing
End Sub

Once the application has started (this only happens when starting the project exe, not when debugging!) and the button's been pushed in order to open the C# dialogue, I select the application's task bar icon. The VB6 window is being focused (why?) and pressing "Escape" opens up another C# dialogue (the first one's still visible though), as if the button had beed clicked again.

There's no default button on the form; when there's no open dialogue, pressing "Escape" pops up the proper message box.

This behaviour can be repeated indefinitely. I've tried setting parents and children, the common answer to such a kind of interop application is to make use of the Interop Form Toolkit.

Still I don't understand why pressing "Escape" fires the button-clicked event. Does anyone have an idea why?

Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文