问题描述
限时送ChatGPT账号..我正在用 C# 做一个 Winform 应用程序,我有一些标签页,比如 tabPage1
、tabPage2
和 tabPage3
,在一个标签控件中,并且 tabPage1
被选中.
I am doing a Winform application in C# and I have some tab pages, say tabPage1
, tabPage2
and tabPage3
, in a tab control, and tabPage1
is selected.
我想在点击任何标签页标题时触发事件,但我只能为页面更改执行此操作(通过使用SelectedIndexChanged
) 但不要点击选定的标签页标题.
I want to trigger event when any tab page header is clicked, but I could do it only for page change (by using SelectedIndexChanged
) but not click on a selected tab page header.
我尝试了 Selecting
和 Selected
事件,但它们都不起作用.我在 MSDN 上搜索,但没有找到在页眉上定义的任何 Click
事件.那么我应该如何实现这一目标?
I tried with Selecting
and Selected
events but both of them didn't not work. I searched on MSDN but didn't find any Click
event defined on a page header. So how should I achieve this?
另一个问题,是否有可能以及如何检测选定标签页上的DoubleClick
?
One further question, is it possible, and how, to detect DoubleClick
on a selected tab page?
推荐答案
只需使用 tabcontrol 的 MouseDoubleClick 事件.您必须迭代选项卡以找出单击的特定选项卡:
Just use the tabcontrol's MouseDoubleClick event. You'll have to iterate the tabs to find out what specific tab was clicked:
private void tabControl1_MouseDoubleClick(object sender, MouseEventArgs e) {
for (int ix = 0; ix < tabControl1.TabCount; ++ix) {
if (tabControl1.GetTabRect(ix).Contains(e.Location)) {
// Found it, do something
//...
break;
}
}
}
请记住,这对用户来说是完全无法发现的,他永远不会想到双击该选项卡.你必须写一本手册.
Do keep in mind that this is completely undiscoverable to the user, he'll never think to double-click the tab. You'll have to write a manual.
这篇关于单击选项卡控件的选定选项卡页眉时如何触发事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论