Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // dodgy; not recommended
- Panel query;
- Form form = new Form
- {
- Controls = {new Panel {
- Visible = false,
- Controls = {
- (query = new Panel {Visible = true})
- }
- }
- }
- };
- form.Show();
- // this is the dodgy bit...
- bool visible = (bool)typeof(Control)
- .GetMethod("GetState", BindingFlags.Instance | BindingFlags.NonPublic)
- .Invoke(query, new object[] { 2 });
- var frm2 = new Form {Text = "Form2"};
- var lbl = new Label {Visible = true};
- frm2.Controls.Add(lbl);
- frm2.Show();
- var frm1 = new Form {Text = "Form1"};
- var lblVis = new Label { Text = lbl.Visible.ToString(), Left = 10, Top = 10};
- lbl.VisibleChanged += (sender, args) => MessageBox.Show("Label Visible changed");
- var btnShow = new Button {Text = "Show", Left = 10, Top = lblVis.Bottom + 10};
- btnShow.Click += (sender, args) =>
- {
- frm2.Visible = true;
- lblVis.Text = lbl.Visible.ToString();
- };
- var btnHide = new Button {Text = "Hide", Left = 10, Top = btnShow.Bottom + 10};
- btnHide.Click += (sender, args) =>
- {
- frm2.Visible = false;
- lblVis.Text = lbl.Visible.ToString();
- };
- frm1.Controls.AddRange(new Control[] {lblVis, btnShow, btnHide});
- Application.Run(frm1);
Add Comment
Please, Sign In to add comment