Click here to Skip to main content
15,894,343 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi All,

In my UserControlProject, in which just contains MenuStrips Controls, I have two properties, one is SourceForm, and another one is DestinationForm:

C#
private Form SourceForm = new Form();
public Form _SourceForm
{
    get { return SourceForm; }
    set { SourceForm = value; }
}

private Form DestinationForm = new Form();

public Form _DestinationForm
{
     get { return DestinationForm; }
     set { DestinationForm = value; }
}

Now once I clicked the one of the MenuItems, which is dragged and dropped in WindowsFormApplication, in the MenuStrip as the code show below, ideally it suppose to navigate to the DestinationForm.

C#
private void tsmiExecuteSql_Click(object sender, EventArgs e)
{
      MenuNavigation.ShowForm(SourceForm, DestinationForm);
}

Now my issue was i can only set the SourceForm and DestinationForm in WindowsFormProject's Form_Load Event like this:

C#
private void frm1_Load(object sender, EventArgs e)
{
   ucMenuStrip._SourceForm = this;
   ucMenuStrip._DestinationForm = new frm2();
}
and the MenuItems only execute the Form_Load event on the destination form, not the source form, hence there is no way for me to re-set the DestinationForm property, and to make things even worse, the event on the UserControlProject does not have the access to the Forms in the WindowsFormProject, therefore, i can not specifiy the SourceForm and DestinationForm in the UserControlProject's MenuStripItem click events either.

To cut the thread short, really what i would like to know is how to re-set the UserControlProject's SourceForm and DestinationForm once MenuStripItems clicked on WindowsFormProject?
Posted
Updated 19-Dec-11 15:53pm
v5
Comments
Sergey Alexandrovich Kryukov 19-Dec-11 20:46pm    
What do you think is done "not dynamically"?
--SA
Sergey Alexandrovich Kryukov 19-Dec-11 20:48pm    
Please click "Improve question" -- not to to improve it -- to see how the code should be formatted, please do it yourself in your future posts.
--SA
AndieDu 19-Dec-11 21:52pm    
Thanks for that

1 solution

First thing to understand: there is nothing with is "not dynamic". Not only all the properties are assigned "dynamically", all the objects themselves are created and inserted in the Forms "dynamically" as well as the Forms themselves and the Application, that is, during run-time. There is no other way. If you thing the Designer does it is some other mystical way, think again. The Designer is only a way to generate some source code, but that code is called during run-time exactly the say way if you would write it "manually".

That said, this is one universal way to answer all questions like that. Your auto-generated (with the help of the Designer) code is written in a separate file. In particular, look at the implementation of the auto-generated method InitializeComponent to learn how all the UI objects and their properties are set up. Use this knowledge in your code.

That's it.

—SA
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 19-Dec-11 22:28pm    
OP commented:

dude, what you said here does explain the concept, but ask yourself, did you post anything helpful in terms of my post!!!!!
Sergey Alexandrovich Kryukov 19-Dec-11 22:33pm    
I'm not a dude for you, you rude one. You did not even get it: I gave you 100% precise instructions to solve your problem, and only you ignorance and attitude block you from seeing the most direct path.

If you feed it's not helpful enough even though you explain the concept, you only reveal your laziness. Nothing can help you in this case. No more help for you. And I suspect not just from me.

Thank you for this discussion.
--SA
AndieDu 20-Dec-11 2:15am    
haha, my god, what an impatient and naive person you are. I, seriously, suspect how you can be a technical personnel, or probably you are not at all, indeed.

Guess what, I resolved this issue and was going to publish my solution in here. Just because of you, i will never ever publish my solution in here. I feel sorry for those ones who had the similar issue, but I am still happy to help if anyone shoot me an email.

As been a decent person, I dont want to express any rudness in here, but me is pretty sure you already got my drift.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900