延迟打开菜单条中的子菜单

发布于 2024-11-10 14:31:07 字数 390 浏览 11 评论 0原文

我们的环境:Visual Studio 2010、c#、.net 4 客户端配置文件。

我们有一个 Winforms 应用程序,其主窗体中包含一个菜单条。菜单条的项目包含图像 (64x64) 和文本。主窗体还有一个 TabControl,其中包含 5 个选项卡。在主窗体的 OnLoad() 方法中,我们隐藏 TabControl 标头,以便它们不可见,因此不可单击。相反,当用户单击菜单条中的某个项目时,我们会切换活动选项卡。

然而,我们的菜单有很多子菜单项,并且由于我们使用主菜单条来选择活动选项卡,因此我们希望子菜单项仅在用户单击菜单项一段时间后才出现,而不是立即出现。否则,每当用户更改他/她的活动视图(通过选择 tabPage)时,子菜单就会出现在屏幕上,因为他/她单击了包含子菜单的菜单条项目。

这可能吗?

Our environment: Visual Studio 2010, c#, .net 4 client profile.

We have a Winforms application that contains a menustrip in its main form. The items of the menustrip contain both an image (64x64) and text. The main form also has a TabControl which contains 5 tabs. In the OnLoad() method of the main form, we hide the TabControl headers so that they are not visible and therefore not clickable. Instead, when the user clicks on an item in the menustrip, we switch the active tab.

However, our menus have many sub-menu items, and since we use the main menustrip to select the active tab, we would like the sub-menu items to appear only after the user clicks the menu item for a period of time, not instantaneously. Otherwise, whenever the user changes his/her active view (by selecting a tabPage), the sub-menus appear on the screen since he/she clicked a menustrip item that contains sub menus.

Is this possible?

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

来日方长 2024-11-17 14:31:07

我不完全理解其基本原理,但是您可以使用 MouseDown 处理程序和 sleep 函数来延迟子菜单的显示,如下所示:

Private Sub FileToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FileToolStripMenuItem.MouseDown
System.Threading.Thread.Sleep(2000) ' wait two seconds
End Sub

===================== =

(编辑:添加了第二个解决方案)

您可以使用计时器控件和 ShowDropDown/HideDropDown 来完成此操作:

Private Sub FileToolStripMenuItem_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles FileToolStripMenuItem.MouseDown
' show tab here'
FileToolStripMenuItem.HideDropDown()
Timer1.Interval = 500
Timer1.Start()
End Sub

Private Sub FileToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FileToolStripMenuItem.Click
FileToolStripMenuItem.HideDropDown()
End Sub

Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Timer1.Stop()
FileToolStripMenuItem.ShowDropDown()
End Sub

I don't completely understand the rationale, but you can delay the display of a submenu using the MouseDown handler and sleep function, like this:

Private Sub FileToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FileToolStripMenuItem.MouseDown
System.Threading.Thread.Sleep(2000) ' wait two seconds
End Sub

======================

(Edit: Added second solution)

You can do this with a timer control and ShowDropDown/HideDropDown:

Private Sub FileToolStripMenuItem_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles FileToolStripMenuItem.MouseDown
' show tab here'
FileToolStripMenuItem.HideDropDown()
Timer1.Interval = 500
Timer1.Start()
End Sub

Private Sub FileToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FileToolStripMenuItem.Click
FileToolStripMenuItem.HideDropDown()
End Sub

Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Timer1.Stop()
FileToolStripMenuItem.ShowDropDown()
End Sub
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文