Ouvrir une form avec une position alleatoire (startposition)

mathvez Messages postés 42 Date d'inscription vendredi 5 janvier 2007 Statut Membre Dernière intervention 15 février 2008 - 27 janv. 2007 à 03:00
Lutinore Messages postés 3246 Date d'inscription lundi 25 avril 2005 Statut Membre Dernière intervention 27 octobre 2012 - 27 janv. 2007 à 03:22
je voudrais savoir comment faire pour qu'une nouvelle fenetre ai une position allétoire dans l'écran apres avoir fais exemple nomdelaform.show();    S.V.P avec windowsdefaultposition, etc elle apparait toujours au meme endroit

1 réponse

Lutinore Messages postés 3246 Date d'inscription lundi 25 avril 2005 Statut Membre Dernière intervention 27 octobre 2012 41
27 janv. 2007 à 03:22
Salut,

Random r = new Random( ( int )DateTime.Now.Ticks );
int x = r.Next( 0, Screen.PrimaryScreen.Bounds.Width - this.Width );
int y = r.Next( 0, Screen.PrimaryScreen.Bounds.Height - this.Height );


this.StartPosition = FormStartPosition.Manual;
this.Location = new Point( x, y );
this.Show( );
0
Rejoignez-nous