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?

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

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()
        { 
        
        }

ok thx :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.