在Windows应用程序项目中,我有一个使用用户控件的表单。我想在用户控件上隐藏标签和文本框。在哪种情况下,我可以做到这一点?
用户控件中的此方法名为DoctorPermissionApprove:
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);
}
例如,我尝试过显示的事件。但它仍然可见
我想在任何人打开表单时隐藏或显示这些组件
非常感谢
答案 0 :(得分:1)
在UserControl类中添加公共属性以将内部标签可见性设置为true或false。这可以从添加了usercontrol的父表单中访问。
示例:
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;
}
}