DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   C# (http://www.daniweb.com/forums/forum61.html)
-   -   Check Whether Button Clicked or not - Please Help (http://www.daniweb.com/forums/thread201290.html)

S2009 Jul 2nd, 2009 2:31 pm
Check Whether Button Clicked or not - Please Help
 
Hi all,

I am creating an Windows application.

I have 2 forms.

In First form I have two buttons. The Second Buttons Enabled property is set to False.

If the First button is clicked then Form 2 should be shown which I have done with the Coding.

In the second Form I have one button If this button is clicked then it should show first form and the second button of that form should be enabled (Enabled property to be set to TRUE).

Can anyone help me out in doing this task?

Please help me out.

Thanks in advance!!

sknake Jul 2nd, 2009 3:10 pm
Re: Check Whether Button Clicked or not - Please Help
 
Form1:
using System;
using System.Windows.Forms;

namespace daniweb
{
  public partial class frm1 : Form
  {
    public frm1()
    {
      InitializeComponent();
    }

    public void EnableButton2()
    {
      button2.Enabled = true;
    }

    private void frm1_Load(object sender, EventArgs e)
    {
      button1.Enabled = true;
      button2.Enabled = false;
    }

    private void button1_Click(object sender, EventArgs e)
    {
      new frm2().Show();
      //this.Hide();
    }

    private void button2_Click(object sender, EventArgs e)
    {
      //Dont know what you want to do
    }
  }
}

Form2:
using System;
using System.Windows.Forms;

namespace daniweb
{
  public partial class frm2 : Form
  {
    public frm2()
    {
      InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
      frm1 f = GetMainForm();
      if (f == null)
        return;
      f.EnableButton2();
      //this.Hide();
      f.BringToFront();
      f.Focus();
    }

    private static frm1 GetMainForm()
    {
      for (int i1 = 0; i1 < Application.OpenForms.Count; i1++)
      {
        if (Application.OpenForms[i1] is frm1)
          return ((frm1)Application.OpenForms[i1]);
      }
      return null;
    }

  }
}

adatapost Jul 3rd, 2009 12:28 pm
Re: Check Whether Button Clicked or not - Please Help
 
S2009,

Try to get the solution for same question with single thread. Do not open too many thread?

Scott has explained very well.

Poab9200 Jul 4th, 2009 1:02 pm
Re: Check Whether Button Clicked or not - Please Help
 
In the for loop shouldn't you use the != instead of the < than operator?


All times are GMT -4. The time now is 4:49 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC