-
Two forms and call event
I have notepad like application.
I have two forms basically and one button on each form and my mainform is the startup form. If I click on button1 on it. Form2 appears which has a button2 on it.. I need to raise a event in Form1(or a method in Form1) when I click button on form2. How can I do it. I'm completely new to C#... but aware of oop...
Please help
-
you can pass a reference to your MainForm and call the event you want. Something like this. But still, you can variate to something you are comfortable with. C# is flexible.
Form1 is the main form
Code:
static void Main()
{
Application.Run(new Form1());
}
public void button2_Click(object sender, System.EventArgs e)
{
MessageBox.Show("Button 2 Clicked");
}
private void button1_Click(object sender, System.EventArgs e)
{
new Form2(this).ShowDialog();
}
and on Form2
Code:
Form1 caller;
public Form2(Form1 f)
{
InitializeComponent();
this.caller=f;
}
private void Form2_Load(object sender, System.EventArgs e)
{
}
private void button1_Click(object sender, System.EventArgs e)
{
caller.button2_Click(this,e);
}
Hope this helps. :)
-
Oh it helps.. thanks ...
I also have some problems to set the window style.. I want it to be Fixed Dialog/Fixed Tool tip etc.. which property will fetch me that?
thank you
-
FormBorderStyle
About the ToolTip, there's a control named ToolTip. You can add it on your from then go to every controls you want to have tooltip'ed. There should be something like ToolTip on ToolTipn property.