mardi 15 mars 2016

Modifying randomly button location

I'm trying to change randomly the location of a button when the mouse is hover it. To do that, I'm using the following source code :

    private int modifX()
    {
        int rdmx;
        int x_max = this.Width;
        Random rdm = new Random();
        rdmx = rdm.Next(0, x_max);
        return rdmx;
    }

    private int ModifY(){
      // same with y_max = this.Height;
    } 

    private void bt_win_MouseEnter(object sender, EventArgs e)
    {
        bt_win.Location = new Point(modifX(), modifY());
    }

The problem is that my button's position is always on a straight line like that

How can I fix it? I tried to use bt_win.Location.X = modifX(); on the mouseEnter event But it seems that I can't handle Location.X or Location.Y I don't really get what I'm doing wrong, anyone got an idea and could explain me what I'm doing wrong?




Aucun commentaire:

Enregistrer un commentaire