Results 1 to 4 of 4

Thread: Two forms and call event

  1. #1

    Thread Starter
    Fanatic Member sridharavijay's Avatar
    Join Date
    Sep 2002
    Location
    http://www.vijaysridhara.in
    Posts
    589

    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

  2. #2
    Fanatic Member brown monkey's Avatar
    Join Date
    Jun 2004
    Location
    Cebu
    Posts
    552
    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.

  3. #3

    Thread Starter
    Fanatic Member sridharavijay's Avatar
    Join Date
    Sep 2002
    Location
    http://www.vijaysridhara.in
    Posts
    589
    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

  4. #4
    Fanatic Member brown monkey's Avatar
    Join Date
    Jun 2004
    Location
    Cebu
    Posts
    552
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width