How to create a processor for dynamic objects



  • Can you tell me how to write a processor for dynamically constructed objects (in my case, the mouse is shaped with buttons) and, for example, if applied to each of them, the rear lamp colour changes?

    The buttons are created in this code:

    private void Form1_MouseDown(object sender, MouseEventArgs e)
    {
        System.Windows.Forms.Button btn = new System.Windows.Forms.Button();
    
    btn.Location = new System.Drawing.Point(e.X, e.Y);
            
    this.Controls.Add(btn);
    

    }



  • For example,

    private void Form1_MouseDown(object sender, MouseEventArgs e)
    {
        Button btn = new Button();
        btn.Location = new Point(e.X, e.Y);
        btn.Click += Button_Click;
    
    this.Controls.Add(btn);
    

    }

    private void Button_Click(object sender, EventArgs e)
    {
    Button currentBtn = (Button)sender;
    currentBtn.Background = Colors.Green;
    }



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2