Windows Develop Bookmark and Share   
 index > Windows Forms Sample Applications > problem to load form by usercontrol button.
 

problem to load form by usercontrol button.

Hello,

I need help to get a way to call a mdi form instance by my usercontrol menu.
At the Mainform, there is a usercontrol that is part of usercontrol_container.

at the usercontrol; I have a button to call the new form.
But I can´t call the method to load the form thought this usercontrol.

I tried to pass it using delegates; but didn´t works well.

Please, see the code bellow:

//MainForm.Designer.cs


private void InitializeComponent()
{

//////////////////////////////////////////////////////////////////////////
// THIS PARAMETER IS TO SET A DELEGATE FOR "WIZAR MENU" TO GET PARAMETERS
// WHEN WIZARD MENU IS ACTIVATED TO CALL A NEW HEADER FORM
//////////////////////////////////////////////////////////////////////////

this.uC_Steps1.callmainloadForm += new UCmenus.UC_Steps.CallMainLoadForm(LoadNewFormExternal);

this.uC_Steps1.Dock = System.Windows.Forms.DockStyle.Fill;
this.uC_Steps1.Location = new System.Drawing.Point(0, 0);
this.uC_Steps1.Name = "uC_Steps1";
toolStripProfessionalRenderer1.RoundedEdges = true;
this.uC_Steps1.Renderer = toolStripProfessionalRenderer1;
this.uC_Steps1.Size = new System.Drawing.Size(222, 578);
this.uC_Steps1.TabIndex = 0;

}
// My UserControl Container instance
private Template.UCmenus.UC_Steps uC_Steps1;



//USER CONTROL CONTAINER

private UC_MenuSteps _menusteps;
private UC_MenuSTart _menustart;
// private static string testvoid;

public UC_Steps()
{
InitializeComponent();
InitializeMenu();
}

public void InitializeMenu()
{
_menustart = new UC_MenuSTart();
_menusteps = new UC_MenuSteps();


//DELEGATE TO USE AT USERCONTROL ITEM
_menusteps.callmainloadFormMenu += new UC_MenuSteps.CallMainLoadFormMenu(SendHeaderFormComfirm);



IDockingPanel leftPanel = this.Panels[DockingType.Left].InsertPanel(0);
leftPanel.Tabbed = true;
IDockingControl dock2 = leftPanel.DockedControls.Add("Getting Started", _menustart);
IDockingControl dock3 = leftPanel.DockedControls.Add("Template Steps", _menusteps);

//user control item that calls the form


public delegate void CallMainLoadFormMenu(object sender, FormValues myformvalues);
public CallMainLoadFormMenu callmainloadFormMenu;


private void btnCallForm1_Click(object sender, EventArgs e)
{
if (callmainloadFormMenu != null)
{
FormValues formvalues = new FormValues(ht, "Edit Template");

callmainloadFormMenu(this, formvalues);
}
}


Does anyone can help me with this issue??

Tks
Vagner
DotNetCon  Tuesday, March 04, 2008 11:53 AM

There's a ParentForm property on the UserControl which can tell which form the UserControl is on, you can create new form for the MDI parent form from UserControlin this way

Code Snippet

partial class UserControl1 : UserControl

{

public UserControl1()

{

InitializeComponent();

}

private void button1_Click(object sender, EventArgs e)

{

if (this.ParentForm != null)

{

Form childForm = new Form();

childForm.MdiParent = this.ParentForm;

childForm.Show();

}

}

}

Zhi-Xin Ye  Monday, March 10, 2008 7:24 AM

There's a ParentForm property on the UserControl which can tell which form the UserControl is on, you can create new form for the MDI parent form from UserControlin this way

Code Snippet

partial class UserControl1 : UserControl

{

public UserControl1()

{

InitializeComponent();

}

private void button1_Click(object sender, EventArgs e)

{

if (this.ParentForm != null)

{

Form childForm = new Form();

childForm.MdiParent = this.ParentForm;

childForm.Show();

}

}

}

Zhi-Xin Ye  Monday, March 10, 2008 7:24 AM

You can use google to search for other answers

Custom Search

More Threads

• Xpander & chart control
• Well, this is it
• .NET Updater Component
• Pocket PC Client and accessing the server version on GotDotNet
• IssueVision Issue
• Smart Client problem with me
• AppUpdater and IIS6 problem
• Amazing !!!
• ¿Why TaskVision does NOT use DataBinding?
• about Icons of XPander