There is a rectangle that can be moved. It is necessary that when you click on it, a window opens. Tried to do so, but does not work.
private void rect1_Click(object sender, EventArgs e) { MessageBox.Show("lol"); } There is a rectangle that can be moved. It is necessary that when you click on it, a window opens. Tried to do so, but does not work.
private void rect1_Click(object sender, EventArgs e) { MessageBox.Show("lol"); } Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .
You must first subscribe to an event (if it exists at all). Perhaps so:
rect1.Click += rect1_Click; In order for a dynamically created object to react to a mouse click, you need to specify the method that will be called when an event is triggered. For example:
obj.Click += obj_Click; In your case, this must be done for the object rect1
It is important to note that not every method can be attached to the delegate chain: the method must accept the following object and EventArgs parameters
You can also attach a method as follows using lambda expressions
obj.Click += (sender, e) => MessageBox.Show("obj click!"); Source: https://ru.stackoverflow.com/questions/616522/
All Articles