0

hi, i have 2 buttons in form1
-> btnAdd
-> btnDelete

clicking one of these buttons will open the same form (form2). In this form i have 2 methods.
-> Add
-> Delete


Depending on which button is clicked one of the methods will work.

How can i no what button was clicked in form2?

3
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by xanawa
0

hi,
xanawa
you can create public properties which you can access through that form2 object
see the Example.
in form have two button

Class Form1
{
	private void btnAdd_click()
	{
	Form2 f=new Form2;		
	f.select=0;
	f.show();
	}
	private void btnDelete_click()
	{
	Form2 f=new Form2;
	f.select=1;
	f.show();
	}
}

In form2 have two method say add & Delete

Class Form2
{
	//first I will create public properties
	private int _select;
	//here we are just the value we don't need og get
	Public int Select
	{
		set 
		{ _select=value;
			if(_select==0){ //Call Add Methos }
			Else if(_select==1){ //Call Delete Methos }
		}
	}
	
	//your Methods
	private void Add(){}
	private void Delete(){}
}

I think this will solve your problem.
Enjoy

Edited by pritesh2010: n/a

0

Great example showed pritesh. I would only like to show you one more simplier, but the methods are less proptective, because they are marked ass public, so you can access to them from every class, but anyway:

//form1:
        private void buttonAdd_Click(object sender, EventArgs e)
        {
            Form2 f2 = new Form2();
            f2.AddMethod2();
            f2.Show();
        }

        private void buttonDel_Click(object sender, EventArgs e)
        {
            Form2 f2 = new Form2();
            f2.DeleteMethod2();
            f2.Show();
        }

//form2:
        public void AddMethod2()
        { 
        
        }

        public void DeleteMethod2()
        { 
        
        }

Edited by Mitja Bonca: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.