禁用选项卡控件事件中的选项卡页单击操作

编程入门 行业动态 更新时间:2024-10-25 12:24:03
本文介绍了禁用选项卡控件事件中的选项卡页单击操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 嘿团队。我开发了一个小的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); } }

更多推荐

禁用选项卡控件事件中的选项卡页单击操作

本文发布于:2023-11-25 02:05:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1627874.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:选项卡   控件   单击   操作   事件中

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!