[C#] Affichage aleatoire de points ....!?
Bonjour a tous ,
Je suis sous visual studio . net et j'apprends le c sharp !
Je me suis fait une class que j'ai nomme MyPoint.cs que voici :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
using System;
using System.Drawing;
namespace WiNAppliLabo3
{
public class MyPoint
{
private int x=0, y=0;
private Color col = new Color();
public MyPoint()
{
}
//Methode GetX retourne la valeur X du point
public int GetX()
{
return x;
}
//Methode GetY retourne la valeur Y du point
public int GetY()
{
return y;
}
//Methode GetColor retourne la couleur du point
public Color GetColor()
{
return col;
}
//Methode SetPoint définit la position du point
public void SetPoint(int X, int Y)
{
x = X;
y = Y;
}
//Methode SetColor définit la couleur du point
public void SetColor(int R, int G, int B)
{
col= Color.FromArgb(R, G, B);
}
//Methode Méthode 2 de définition de la couleur
public void SetColor(Color color)
{
col=color;
}
//Methode Draw permettant de dessiner le point dans une fenêtre
public void Draw(Graphics dc)
{
Bitmap Bmp= new Bitmap(1,1);
Bmp.SetPixel (0, 0, col);
dc.DrawImage (Bmp, x, y);
}
}
} |
cette classe a plusieurs methodes afin de permettre la creation de points
dans ma fenetre windows je veux qu'au lancement, elle me genere des points aleatoirement voila ce que j'ai fait mais a l'affichage je n'ai rien du tout meme pas d'erreur rien !
si quelqu'un avait une idée de se qui se passe je lui en serait reconnaissant ....
Je vous remercie ...
Bon week end
Christophe
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace WiNAppliLabo3
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
/** declaration de 100.000 points **/
MyPoint[] LesPoints = new MyPoint[100000];
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void Draw(object sender, System.Windows.Forms.PaintEventArgs e)
{
foreach (MyPoint pt in LesPoints)
{
pt.Draw (e.Graphics);
}
}
/** chargement doit dessiner 100.000 points sur la form **/
private void Form1_Load(object sender, System.EventArgs e)
{
int x,y, r, g, b,i=0;
Random rnd = new Random();
for (i=0; i<LesPoints.Length; i++)
{
x=rnd.Next(ClientSize.Width);
y=rnd.Next(ClientSize.Height);
r=rnd.Next(255);
g=rnd.Next(255);
b=rnd.Next(255);
LesPoints[i] = new MyPoint();
LesPoints[i].SetPoint(x, y);
LesPoints[i].SetColor(r,g ,b );
}
}
}
} |