Hi,

I have some question to ask because I don't understand why is it happening like that.

I have 2 polygon created and displayed.
I've make mouseDown, mouseUp, mouseMove event. (For some movement for the polygon)
Now i wanted to implement keyUp(pressing delete button from keyboard, then delete the polygon)

This is the code for MouseUp:

private void Shape_MouseUp(object sender, MouseEventArgs e)
      {
         isDraggingA = false;
         controlALL = (Control)sender;

         if (e.Button == MouseButtons.Left)
         {
            OB = sender;
            controlALL.KeyUp += new KeyEventHandler(DeleteButton);
            
         }
      }

the " object sender " is to identify which polygon I've selected
then, I've made "Shape_MouseUp" it so that it will run "DeleteButton" function

Below is my DeleteButton code:

private void DeleteButton(object sender, KeyEventArgs e)
      {

         controlALL = (Control)OB;

         if (e.KeyCode == Keys.Delete)
         {
            controlALL.Dispose();
         }

         
      }

PROBLEM : When i execute this 2 code, the result i got is,

when i click on polygon 1, then press 'delete' SUCCESS
But when i click on polygon 2, then press 'delete' NOTHING HAPPEN

I don't know why the function "DeleteButton(object sender, KeyEventArgs e) cannot get the polygon 2.
Any idea?

Hi,

Maybe you are forgetting to attach the Shape_MouseUp method to 'poligon2'. Say poligon2.MouseUp += new MouseEventHandler(Shape_MouseUp) .

Hope this Help
Regards,
Camilo.

Hi,

Thanks for replying. I've already attach to my polygon2 as well for the mouseUp.

But seems like the problem still exists...
:(

Hi,

Why don't you set a Breakpoint in this line if (e.Button == MouseButtons.Left) to see if your program it's entering the method when you click on 'poligon2'

Camilo

Hi,

I tried, the method can run towards that point.
I've solve the problem with .focus ( focusing the control of which i selected )

Thanks !!

Regards,
Kar Hong

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.