int count;
        int i = 0;
        int x = 5;
        int y=10;

        Panel[] pnl_new_ = new Panel[10];
        PictureBox[] usr_pic_ = new PictureBox[10];
        Label[] lbl_username_ = new Label[10];
        Label[] lbl_account_type_ = new Label[10];
             
        private void button1_Click(object sender, EventArgs e)
        {
            i = Convert.ToInt32(txt_num.Text);            
          
            for (count = 0; count < i; )
            {
                    Panel pnl = new Panel();

                    pnl.Location = new Point(x, y);
                    pnl.Size = new Size(238, 97);
                    pnl.BackColor = Color.LightGray;    
                    pnl.Cursor = System.Windows.Forms.Cursors.Hand;

                    //pnl.MouseLeave += new EventHandler(pnl_MouseLeave);
                    //pnl.MouseHover += new System.EventHandler(pnl_MouseHover);

                    pnl_new_[count] = pnl;
                    pnl_new_[count].MouseHover+=new EventHandler(Manage_Another_Account_frm_MouseHover);
                    grp_account.Controls.Add(pnl_new_[count]);

                    PictureBox pic = new PictureBox();

                    pic.Location = new Point(12, 12);
                    pic.Size = new Size(70, 74);
                    pic.BackColor = Color.Green;

                    usr_pic_[count] = pic;
                    pnl_new_[count].Controls.Add(usr_pic_[count]);

                    Label lbl_name = new Label();

                    lbl_name.Location = new Point(94, 21);
                    lbl_name.Size = new Size(122, 18);
                    lbl_name.Text = "Sunita Shrestha";
                    lbl_name.ForeColor = Color.Green;
                    lbl_name.Font = new Font("Tahoma", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));

                    lbl_username_[count] = lbl_name;
                    pnl_new_[count].Controls.Add(lbl_username_[count]);

                    Label lbl_actype = new Label();

                    lbl_actype.Location = new Point(94, 47);
                    lbl_actype.Size = new Size(122, 18);
                    lbl_actype.Text = "Administrator";
                    lbl_actype.ForeColor = Color.Black;
                    lbl_actype.Font = new Font("Tohama", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));

                    lbl_account_type_[count] = lbl_actype;
                    pnl_new_[count].Controls.Add(lbl_account_type_[count]);

                count = count + 1;
                x += 257;
            }
        }

        public void Manage_Another_Account_frm_MouseHover(object sender, EventArgs e)
        {
            pnl_new_[count].BackColor = Color.Green;
        }
public void pnl_MouseHover(object sender, EventArgs e)
{
pnl[1].BackColor=Color.Green;
}

//This did not work any idea...
//The system couldnot define which control was selected... there was the error in count too.. caus i have defined count already above as a globle value...

Please don't post threads twice!

Use the sender object, perhaps like this:

public void Manage_Another_Account_frm_MouseHover(object sender, EventArgs e)
{
//pnl_new_[count].BackColor = Color.Green;
    Panel hoveredoverPnl = sender as Panel; //you know it is a Panel right?
    hoveredoverPnl.BackColor = Color.Green;
}

When input is 11 or more then there will be errors. You can use List<T> for PictureBoxes , Labels and other controls.

List<Label> lab=new List<Label>();
 List<PictureBox> pictures=new List<PictureBox>();

 void Test()
  {
     for(int i=1;i<=20;i++) 
      {
          PictureBox pc=new PictureBox();
          pc.MouseHover+=new EventHandler(Manage_Another_Account_frm_MouseHover);
          this.Controls.Add(pc);
          pictures.Add(pc);
         
         
          ....
      }  
  }
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.