选项卡控件标签页禁用

编程入门 行业动态 更新时间:2024-10-25 08:27:03
本文介绍了选项卡控件标签页禁用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

亲爱的开发人员, 我在Windows窗体中有tabcontrol(tab_control)和3个标签页(tb1,tb2,tb3)。当我加载表单时,我想禁用访问tb3页面。用户可以看到该页面,但用户无法访问tb3页面。像textbox.Enable = false; 我尝试下面的代码,但它不工作 表格加载 { tab_control.SelectedIndex [ 2 ]。启用= 假; }

问候 Vasanthakumar

解决方案

在TabControl中添加选择事件:

private void tab_control_Selecting( object sender,TabControlCancelEventArgs e) { if (e.TabPage == tb3) { e.Cancel = 真; } }

如果用户选择tb3,则此代码取消选择。

据我所知,标签页没有Enabled属性。在你使用的代码中, SelectedIndex 只设置或获取选项卡控件选择的索引,它不会改变页面的属性。 你可以通过禁用该页面中的控件或取消选择事件来实现类似的效果。 这是禁用页面内容的简单方法之一

((控制)此 .tb3).Enabled = false ;

或者,如果用户选择tb3,您可以取消选择事件。

private void tabControl1_Selecting( object sender,TabControlCancelEventArgs e) { if ( this .tabControl1.SelectedTab.Name == tb3 ) { e.Cancel = true ; } }

这样,用户甚至无法查看页面内容,他们只知道那里有存在tb3。请注意,事件handeler是 tabControl1_Selecting 而不是 tabControl1_SelectedIndexChanged 。在你的情况下,我认为第二个选项更符合你的要求。 希望这是有帮助的。

如果你有兴趣可以通过创建自己的TabControl来隐藏它们:

public class MyTabControl:TabControl { protected 覆盖 void WndProc( ref 消息m) { // 通过捕获TCM_ADJUSTRECT消息来隐藏标签 如果(m。 Msg == 0x1328&&!DesignMode) m.Result = IntPtr .Zero; else base .WndProc(参考 m); } }

您可以在TabPages by SelectedIndex ++或SelectedIndex -

Dear Developers, I have tabcontrol (tab_control) with 3 tab pages (tb1,tb2,tb3)in the Windows Form. When I load the form I want to disable to access the tb3 pages. User can see that page, but user couldn't be able to access the tb3 page. Like textbox.Enable=false; I try that below code but it is not working

Form Load { tab_control.SelectedIndex[2].Enable = false; }

Regards Vasanthakumar

解决方案

Add a Selecting event to your TabControl:

private void tab_control_Selecting(object sender, TabControlCancelEventArgs e) { if (e.TabPage == tb3) { e.Cancel = true; } }

If the user selects tb3, this code cancels the selecting.

Hi, As far as I know, a tab page doesn't have an Enabled property. In the code you use, SelectedIndex only set or get the tab controls selected index, it does not change the property of the page. You can achieve similar effect by disabling the controls in that page or cancel the selection event. This is one of the easy way of disabling the contents in the page

((Control)this.tb3).Enabled = false;

Or you can cancel the selection event if user select tb3.

private void tabControl1_Selecting(object sender, TabControlCancelEventArgs e) { if (this.tabControl1.SelectedTab.Name == "tb3") { e.Cancel = true; } }

This way, user cannot even view the content of the page, they just know there's a tb3 exists. Note that the event handeler is tabControl1_Selecting not tabControl1_SelectedIndexChanged. In your case I think the second option fits your requirement more. Hope this is helpful.

If you are interested you can hide them by creating your own TabControl:

public class MyTabControl : TabControl { protected override void WndProc(ref Message m) { // Hide tabs by trapping the TCM_ADJUSTRECT message if (m.Msg == 0x1328 && !DesignMode) m.Result = IntPtr.Zero; else base.WndProc(ref m); } }

You can navigate between TabPages by SelectedIndex++ or SelectedIndex--

更多推荐

选项卡控件标签页禁用

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

发布评论

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

>www.elefans.com

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