Control visibility Problem in Inheriting WinForm!
-
Hi Dears! I need ur help to tackle the following scenario. I have total two win forms. F1,F2 F1 contains control,Timer,DateTimePicker ,Some text lable and A pictureBox, all are private. F2 inherits F1 ( F2:F1) when i call show methed for F2 with its instance all the controls of form F1 are visible on F2 hat i want to keep some of the controls invisble(not inherted and not visble) in inherited form F2. For Example i want the pictureBox control in F1 to be (public/private)static and not inhertable ,non visble on form F2. How to do this? Thnx in Advance!
-
Hi Dears! I need ur help to tackle the following scenario. I have total two win forms. F1,F2 F1 contains control,Timer,DateTimePicker ,Some text lable and A pictureBox, all are private. F2 inherits F1 ( F2:F1) when i call show methed for F2 with its instance all the controls of form F1 are visible on F2 hat i want to keep some of the controls invisble(not inherted and not visble) in inherited form F2. For Example i want the pictureBox control in F1 to be (public/private)static and not inhertable ,non visble on form F2. How to do this? Thnx in Advance!
When you inherit a class all your base private members ar hidden. You can not inherit only certain memberber... Here are some possible resolutions for your problem : 1) make a base constuctor that allows you to specify the hiding of certain controls. Let's say you have a form (F1) with a button. The form which inherits F1 can call a base constuctor to specify this :
// The base class
public class F1 : ... {
...
System.Windows.Forms.Button button1 = new System.Windows.Form.Button();
...
// Here is your standar .ctor
public F1() {
...
// Initialize the form in what ever wy you desire
...
}
// Here is the .ctor that hides the button
public F1(bool hideButton) : this() {
button1.Visible = hideButton;
}
...
}// The derived class
public class F2 : F1 {
...
public F2 : base(true) {
// initialize the form normaly
}
...
}- Build in the base class an accesor that let's you change the state of certain controls (ie. the visible property of a button as in the previous example)
// The base class
public class F1 : ... {
...
System.Windows.Forms.Button button1 = new System.Windows.Form.Button();
...
public SetButtonVisibility {
get {
return button1.Visible;
}
set {
button1.Visile = value;
}
}
// Here is your standar .ctor
public F1() {
...
// Initialize the form in what ever wy you desire
...
}
...
}// The derived class
public class F2 : F1 {
...
public F2 : base(true) {
SetButtonVisibility = false; // same as base.SetButtonVisibility = false;
// initialize the form normaly
}
...
}I hope you understand...because is a rough world out there...