本文介绍了禁用选项卡控件事件中的选项卡页单击操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嘿团队。我开发了一个小的win表单,它有一个用于在标签页之间切换的标签控件。表单由两个标签页组成。 提前感谢您的帮助。 我需要的标准: 1.鼠标点击不应该选中标签页 我尝试过: 禁用手动选择标签的代码。(不工作) private void tabControl1_Click ( object sender,EventArgs e) { if (tabControl1.SelectedTab = = tabPage2) { tabControl1.SelectedTab = tabPage1; MessageBox.Show( 你没有权限!!); } else if (tabControl1.SelectedTab == tabPage1 ) { tabControl1.SelectedTab = tabPage2; MessageBox.Show( 你没有权限!!); } }
从tabpage1重定向到tabpage2的代码(工作良好)
private void t1NextTabRedirectButton_Click( object sender,EventArgs e) { tabControl1.SelectedTab = tabPage2; }解决方案
试试这样: public class myTabControl:TabControl { protected 覆盖 void OnSelecting(TabControlCancelEventArgs e) { e.Cancel = true ; base .OnSelecting(e); } 受保护 覆盖 void OnMouseClick(MouseEventArgs e) { MsgBox( !没有许可!); } }
private void tabControl_MouseDown( object sender,MouseEventArgs e) { if (tabControl.SelectedTab == tabPage2) { tabControl.SelectedIndex = 0 ; tabControl.SelectedTab = tabPage1; MessageBox.Show( Action Denied !!, 错误,MessageBoxButtons.OK,MessageBoxIcon.Warning); } else if (tabControl.SelectedTab == tabPage1) { tabControl.SelectedTab = tabPage2; MessageBox.Show( Action Denied !!, 错误,MessageBoxButtons.OK,MessageBoxIcon.Warning); } }
Hey team. I developed a small win forms that has a tab control for switching between tab pages.The form consists of two tab pages. Thanks in advance for the help. Criteria what i need: 1. tab pages should not get selected on mouse click What I have tried: Code for disabling the manual selection of tab.(NOT WORKING)
private void tabControl1_Click(object sender, EventArgs e) { if (tabControl1.SelectedTab == tabPage2) { tabControl1.SelectedTab = tabPage1; MessageBox.Show("You don’t have permission !!"); } else if(tabControl1.SelectedTab == tabPage1) { tabControl1.SelectedTab = tabPage2; MessageBox.Show("You don’t have permission !!"); } }Code for redirecting from tabpage1 to tabpage2(WORKING GOOD)
private void t1NextTabRedirectButton_Click(object sender, EventArgs e) { tabControl1.SelectedTab = tabPage2; } 解决方案 Try it like this : public class myTabControl : TabControl { protected override void OnSelecting(TabControlCancelEventArgs e) { e.Cancel = true; base.OnSelecting(e); } protected override void OnMouseClick(MouseEventArgs e) { MsgBox("! No Permission !"); } }private void tabControl_MouseDown(object sender, MouseEventArgs e) { if (tabControl.SelectedTab == tabPage2) { tabControl.SelectedIndex = 0; tabControl.SelectedTab = tabPage1; MessageBox.Show("Action Denied!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else if (tabControl.SelectedTab == tabPage1) { tabControl.SelectedTab = tabPage2; MessageBox.Show("Action Denied!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }更多推荐
禁用选项卡控件事件中的选项卡页单击操作
发布评论