在哪个表单事件中我可以隐藏用户控件的标签
本文关键字:用户 隐藏 控件 标签 我可以 表单 事件 | 更新日期: 2023-09-27 18:31:09
在一个Windows应用程序项目中,我有一个使用用户控件的窗体。我想隐藏用户控件上的标签和文本框。在哪种情况下我可以这样做?
用户控件中名为 DoctorPermissionApproved 的此方法:
public void LoadDoctorPermission(int fromWhere)
{
if (fromWhere == 0) // Başhekimden geldiyse?
{
labelDoctor.Visible = true;
editDoctorWithoutHead.Visible = true;
}
else if (fromWhere == 1) // Normal Hekimden geldiyse
{
labelDoctor.Visible = false;
editDoctorWithoutHead.Visible = false;
}
}
并在形式上:
private void ExistRequestAndNewEntryForm_Shown(object sender, EventArgs e)
{
var obj = new DoctorPermissionApprove();
obj.LoadDoctorPermission(0);
}
例如,我在显示的事件中尝试过。但它仍然可见
我想在任何人打开表单时隐藏或显示此组件
非常感谢
在 UserControl 类中添加一个公共属性,以将内部标签可见性设置为 true 或 false。这可以从添加了用户控件的父窗体访问。
例:
public class YourUserControl
{
//This code will be in designer class
private Label lblYourLabelToHide = new Label();
//Create this public property to hide the label
public bool IsLabelVisible
{
set { lblYourLabelToHide.Visible = value; }
}
}
public class YourParentForm
{
//This will be in designer
private YourUserControl userControl = new YourUserControl();
public void Form_Load()
{
//based on some criteria
userControl.IsLabelVisible = false;
}
}