保持窗体始终在Excel应用程序中可见 [英] Keeping windows form always visible within Excel application

查看:162
本文介绍了保持窗体始终在Excel应用程序中可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将Excel  VBA工作簿转换为VB.NET中的VSTO加载项。 在原始(即-VBA)版本中,我有一个无模式的UserForm(称为frmMain)浮动在顶部,并且在用户仍在Excel应用程序中时始终可见,
但如果用户移动则不可见到Excel之外的另一个窗口。

I'm trying to convert an Excel VBA workbook to a VSTO Add-in in VB.NET.  In the original (i.e.- VBA) version I have a modeless UserForm (called frmMain) that floats on top and is visible at all times while the user is still within the Excel application, but is not visible if the user moves to another window outside of Excel.

例如,在Excel中,用户可以单击任何工作表选项卡,选择任何单元格等,UserForm仍然可见。 这正是我想要的。

For example, within Excel the user can click on any worksheet tab, select any cell, etc. and the UserForm is still visible.  This is exactly how I want it.

问题是,在新的VSTO加载项中,我无法让Windows表单模仿这种相同的行为。 我使用frmMain.Show()将表单显示为无模式表单,但是当用户单击Excel工作表(即激活工作表)时,
表单将隐藏在工作表后面。 我可以手动Alt-Tab将表单恢复到视图中,但我需要它始终保持在视图中 - 只要用户没有离开Excel应用程序,就浮在Excel工作表的顶部。

The problem is, that in the new VSTO add-in, I can not get the Windows form to mimick this same behavior.  I use frmMain.Show() to show the form as a modeless form, but the moment the user clicks an Excel worksheet (i.e.- activates a worksheet) the form becomes hidden behind the worksheet.  I can manually Alt-Tab to bring the form back into view, but I need it to always remain in view - floating on top of the Excel worksheets so long as the user hasn't left the Excel aplication.

我尝试了各种各样的东西,包括将表单设置为TopMost,然而,这导致表单在任何地方都是TopMost - 包括在Excel之外。 更糟糕的是,如果用户执行任何通常会导致Excel启动对话框
框的任何内容(例如关闭打开的工作簿,提高警报"是否要保存更改...")警告对话框本身隐藏在frmMain表单后面并且无法访问(因为frmMain是TopMost)。

I tried various things, including setting the form to TopMost, however, that causes the form to be TopMost everywhere - including outside of Excel.  Worse than that, if the user does anything that would normally result in Excel's launching a dialog box (e.g.- closing an open workbook, raising the alert "Do you want to save the changes...") the alert dialog box itself is hidden and inaccessible behind the frmMain form (since the frmMain is TopMost).

如何让我的表单以所需的方式运行(即 - 同样的方式在VBA做过吗?

How can I get my form to behave in the desired way (i.e.- the same way it did in VBA)?

谢谢!!!

Rob

Rob Shurman

Rob Shurman

推荐答案

嗨Rob,

感谢您在MSDN上发帖论坛。

Thanks for posting in the MSDN Forum.

您能告诉我您的Office版本吗?我在我身边使用了Office 2010。如果我显示用户表单,我无法切换到其他工作表。你能告诉我更多细节吗?

Would you please tell me your Office version? I used Office 2010 on my side. I can't switch to other sheet if I show the user form. Would you please show me more details?

祝你有个美好的一天,

Tom


这篇关于保持窗体始终在Excel应用程序中可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆