Marty

Marty

  • NA
  • 8
  • 11.5k

Setting a Parent GroupBox visiblity from a UserControl class

Feb 25 2006 2:19 PM
Untitled Document

I have a main Windows application called MainApp which has a panel with a GroupBox with buttons in it. The GroupBox is called groupBoxCommand

In the same project there are UserControls class form which also has a GroupBox called groupBox1UserControl1 which just has one button (for simplicity) that when pressed will make groupBox1UserControl1 visiblity false and groupBoxCommand visiblity false.

I have no problem displaying the differnet UserConrtols GroupBoxes onto the MainApp panel when a button pressed or canceling the UserConrol and making them invisible. My problem is getting MainApp groupBoxCommand visiblity to come back on when the UserContol button is pressed. The UserContol GroupBox disapears but the MainApp groupBoxCommand does not reappear . Most likley I'm out of scope when I try this.

I ran out of ideas and hope someone can see my error(s).

Thanks

Marty

Here is the MainApp Code minus the Window generated code

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using nsGoToWayPoint;
using nsUserControl1;

namespace MainApp
{
public class Form1 : System.Windows.Forms.Form
{
public System.Windows.Forms.Panel panel1;
public System.Windows.Forms.Button btnGotToWayPoint;
public System.Windows.Forms.Button button2;
public System.Windows.Forms.Button button3;
public System.Windows.Forms.GroupBox groupBoxCommand;
private System.ComponentModel.Container components = null;
private nsGoToWayPoint.GoToWayPoint goToWayPoint;
private System.Windows.Forms.Button button1;
private nsUserControl1.UserControl1 groupBox1UserControl1;

public Form1()
{
InitializeComponent();
this.goToWayPoint = new nsGoToWayPoint.GoToWayPoint();
this.groupBox1UserControl1 = new nsUserControl1.UserControl1();
}

private void button2_Click(object sender, System.EventArgs e)
{
this.groupBoxCommand.Visible = false; //

// place UseControl GroupBox in place of the MainApp groupBoxCommand
//
// panel1
//
this.panel1.Controls.Add(this.groupBox1UserControl1);

this.panel1.SuspendLayout();
this.groupBoxCommand.SuspendLayout();
this.SuspendLayout();

this.groupBox1UserControl1.Location = new System.Drawing.Point(16, 40);

this.groupBox1UserControl1.Name = "User Conrol";
this.groupBox1UserControl1.Size = new System.Drawing.Size(152, 184);
this.groupBox1UserControl1.TabIndex = 1;
//
// Form1
//
this.panel1.ResumeLayout(false);
this.groupBox1UserControl1.ResumeLayout(false);
this.ResumeLayout(false);
}

Here is the UserConrtol code minus the Window generated code

using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using MainApp;

namespace nsUserControl1
{

public class UserControl1 : System.Windows.Forms.UserControl
{
private System.Windows.Forms.Button btnUserControl1;

private System.ComponentModel.Container components = null;
private System.Windows.Forms.GroupBox groupBox1UserControl1;
private MainApp.Form1 mainApp;

public UserControl1()
{
InitializeComponent();
}
private void btnUserControl1_Click(object sender, System.EventArgs e)
{
this.mainApp = new Form1();

// Make UserControl GroupBox disapear
this.groupBox1UserControl1.Visible = false;

// Setup to see the Main GroupBox again
this.mainApp.groupBoxCommand.Visible = true; // this never gets set!!!!

// What else is missing here?
}
}