Newbie with Panel & User Control Query

  • Thread starter Thread starter What To Do
  • Start date Start date
W

What To Do

Hi All,

Firstly, im a real newbie to C# so appologies for asking what might be a
very basic question.

Basically im using DotNetBar and have a Ribbon form. On my Ribbon form, I
have a ribbon Bar, With 5 buttons. I also have a a panel on my Main form
(pnlMainMenu) I have serveral user controls also.

When a user clicks on a button I would like it to display the user control
in the Panel.

So far i have the following code:-

private void btnComplaints_Click(object sender, EventArgs e)
{
pnlMainMenu.Controls.Clear();
TestApp.User_Controls.uctComplaints = new UserControl(Complaints);
Complaints.TopLevel = true;
pnlMainMenu.Controls.Add(Complaints);
Complaints.Show();
}

Could somebody be kind enought to point me in the right direction, or where
im going wrong?

I have Googled but cant seem to find anything.

Many Thanks
Simon
 
Hi Simon,

question: do you have a one to one correspondence between your menu
items and user controls? Like if you click on menu item1 -- it will
only bring up one user control? Menu item2 will bring only another
specific user control?

And one other question: when you refer to user controls -- are these
controls that you drag from the toolbox? or are these custom user
controls that you (or someone) created as a user control item?

Rich
 
What To Do said:
Hi All,

Firstly, im a real newbie to C# so appologies for asking what might be a
very basic question.

Basically im using DotNetBar and have a Ribbon form. On my Ribbon form, I
have a ribbon Bar, With 5 buttons. I also have a a panel on my Main form
(pnlMainMenu) I have serveral user controls also.

When a user clicks on a button I would like it to display the user control
in the Panel.

So far i have the following code:-

private void btnComplaints_Click(object sender, EventArgs e)
{
pnlMainMenu.Controls.Clear();
TestApp.User_Controls.uctComplaints = new UserControl(Complaints);
Complaints.TopLevel = true;
pnlMainMenu.Controls.Add(Complaints);
Complaints.Show();
}

Could somebody be kind enought to point me in the right direction, or where
im going wrong?

I have Googled but cant seem to find anything.

Many Thanks
Simon

.

I'm guessing Complaints is the type of your control to add, and not an
instance of some control. You also should be more clear whether there is an
error, or it does not do what you wanted/expected your code to do. In this
case, I think it is the latter.

I think you want the following:

private void btnComplaints_Click (object sender, EventArgs e)
{
pnlMainMenu.Controls.Clear();
Complaints ui = new Complaints();
pnlMainMenu.Controls.Add(ui);
TestApp.User_Controls.uctComplaints = ui;
}

Mike
 
Hi There,

Yes it is a one to one correspondence and they are customer User Control.

Many Thanks
Si
 
Hi There,

Thanks for your help.

OK i`ve added the following to my prject:

pnlMainMenu.Controls.Clear();
TestApp.User_Controls.uctComplaints ui = new
TestApp.User_Controls.uctComplaints();
pnlMainMenu.Controls.Add(ui);
uctComplaints = ui;

But I now get an error saying:

Error 1 The name 'uctComplaints' does not exist in the current context
Q:\Winform Projects\TestApp\Forms\frmMainMenu.cs 25 17 TestApp on line:
uctComplaints = ui;

My User Control Code is:

namespace TestApp.User_Controls
{
public partial class uctComplaints : UserControl
{
public uctComplaints()
{
InitializeComponent();
}

My Main Form Code is:

namespace TestApp
{
public partial class frmMainMenu :
DevComponents.DotNetBar.Office2007RibbonForm
{
public frmMainMenu()
{
InitializeComponent();
}

private void btnComplaints_Click(object sender, EventArgs e)
{
{
pnlMainMenu.Controls.Clear();
TestApp.User_Controls.uctComplaints ui = new
TestApp.User_Controls.uctComplaints();
pnlMainMenu.Controls.Add(ui);
uctComplaints = ui;
}
}

}
}

Sorry its probably something so stupid ... I just cant figure out what:(

Also I notice you have UI im guessing this could be anything ... Bob, Same,
Paul, etc?

Many Many Thanks Again for you help
Si
 
Not So Clever said:
Hi There,

Thanks for your help.

OK i`ve added the following to my prject:

pnlMainMenu.Controls.Clear();
TestApp.User_Controls.uctComplaints ui = new
TestApp.User_Controls.uctComplaints();
pnlMainMenu.Controls.Add(ui);
uctComplaints = ui;

But I now get an error saying:

Error 1 The name 'uctComplaints' does not exist in the current context
Q:\Winform Projects\TestApp\Forms\frmMainMenu.cs 25 17 TestApp on line:
uctComplaints = ui;


I believe you should just delete the line uctComplaints = ui; From what you
have said, uctComplaints is a type, but here it is being referenced as a
variable. You don't appear to have such a variable defined, so remove that
line.

Oh, and yes, "ui" could be any variable name. I tend to use "ui" for a
temporary user interface variable name.

Mike
 
Back
Top