Bonjour,
je dessine un carre (qui en fait mon canvas) en fonction des different processus lancé sur mon ordinateur.
cette fonction est appelé
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 public Canvas dessineRectangle(int width, int heigth, int top, int left) { Canvas windowsCanvas = new Canvas(); windowsCanvas.Background = new SolidColorBrush(colors[i]); // tableau de differentes couleurs windowsCanvas.Width = width; windowsCanvas.Height = heigth; Canvas.SetTop(windowsCanvas, top); Canvas.SetLeft(windowsCanvas, left); i++; if (i == colors.Length) i = 0; return windowsCanvas; }
dans une autre fonction
J'ai donc une representation sous forme de carre de mes fenetre windows ouverte.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 public void Info(Canvas can) { Process[] processList = Process.GetProcesses(); foreach (Process process in processList) { { IntPtr ptr = process.MainWindowHandle; RECT ProcRect = new RECT(); GetWindowRect(ptr, ref ProcRect).Equals(true); int height = (ProcRect.Bottom - ProcRect.Top) / coeff; int width = (ProcRect.Right - ProcRect.Left) / coeff; int left = ProcRect.Left / coeff; int top = ProcRect.Top / coeff; can.Children.Add(dessineRectangle(width, height, top, left)); } }
la fonction Info est elle appele a l'aide d'un timer pour rafraichir l'ecran.
J'aimerais pouvoir associer une couleur differente a mes canvas sans que celle ci change. En effet comme dans mon timer j'appelle Info() qui appeller Draw Rectangle. J'ai un changement de couleur continu... normal. Mais je ne vois pas comment faire autrement. J'espere avoir ete clair.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 public MainWindow() { InitializeComponent(); DispatcherTimer timer = new DispatcherTimer(); timer.Tick += new EventHandler(timer_tick); timer.Interval = new TimeSpan(0, 0, 0); timer.Start(); myParentCanvas = new Canvas(); positionMainWindows(); this.AddChild(myParentCanvas); } private void timer_tick(object sender, EventArgs e) { myParentCanvas.Children.RemoveRange(0, myParentCanvas.Children.Count); Info(myParentCanvas); }
Si quelqu'un peu m'aider.
merci
Partager