Hello,
je code un UserControl qui affiche une picturebox sensitive. Lors d'un clic je récupère la position du clic pour modifier l'image localement, en utilisant Graphics.
mes fonctions sont correctement appelées, mais l'affichage ne change pas :/
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
27
28
29
30
31
32 private void InitializeComponent() { this.pictureBox1 = new System.Windows.Forms.PictureBox(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); this.SuspendLayout(); // // pictureBox1 // this.pictureBox1.Image = global::Projet1.Properties.Resources.image_defaut; this.pictureBox1.InitialImage = global::Projet1.Properties.Resources.imagedefaut; this.pictureBox1.Location = new System.Drawing.Point(0, 0); this.pictureBox1.Margin = new System.Windows.Forms.Padding(0, 0, 0, 0); this.pictureBox1.Name = "pictureBox1"; this.pictureBox1.Size = new System.Drawing.Size(190, 190); this.pictureBox1.TabIndex = 0; this.pictureBox1.TabStop = false; this.pictureBox1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseDown); this.pictureBox1.MouseUp += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseUp); // // VueControlePTZ // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.Controls.Add(this.pictureBox1); this.Margin = new System.Windows.Forms.Padding(0, 0, 0, 0); this.Name = "VueControlePTZ"; this.Size = new System.Drawing.Size(190, 190); ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); this.Paint += new System.Windows.Forms.PaintEventHandler(this.VueControlePTZ_Paint); this.ResumeLayout(false); }Sur evenement Paint j'appellle UpdateVue(), et lors d'une pression sur la souris, la même fonction est appelée au final.
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
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
66
67
68
69
70
71
72
73 /// <summary> /// fonciton appelée lors du clic appuyé sur bouton de la souris /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void pictureBox1_MouseDown(object sender, MouseEventArgs e) { System.Console.WriteLine("pictureBox1_MouseDown() appelée"); if (e.Button == MouseButtons.Left) { PositionCliquable posCliquee = DefinirElementDePositionClique(e.X, e.Y); //on vérifie que lon a bnien cliqué sur un élement sensitif if (posCliquee != null) { //traitement d'affichage posCourante = posCliquee; UpdateVue(); } } } /// <summary> /// cette fonction permet de mettre à jour la vue /// </summary> private void UpdateVue() { pictureBox1.Image = pictureBox1.InitialImage; PositionCliquable posMarqueurCouleur = DefinirElementMarqueurCouleur(); //A virer if (posMarqueurCouleur == null) posMarqueurCouleur = this.positionBoutonEtatUtilise; using (Graphics g = CreateGraphics()) { try { //Si le marqueur couleur n'est aps null //on est donc dans une logique d'utilisation if (posMarqueurCouleur != null) { System.Console.WriteLine("dans UpdateVue()_1"); g.DrawImage(posMarqueurCouleur.Image, posMarqueurCouleur.CoordonneeHGImage); System.Console.WriteLine("dans UpdateVue()_2"); //on regarde si le clic est actif => une posCourante existe if (posCourante != null) { g.DrawImage(posCourante.Image, posCourante.CoordonneeHGImage); System.Console.WriteLine("dans UpdateVue()_3 : on ecrit l'image supérieure"); } System.Console.WriteLine("dans UpdateVue()_4"); } } catch(Exception e){ System.Console.WriteLine(e.Message); System.Console.WriteLine(e.StackTrace); } g.Dispose(); } } /// <summary> /// Procédure de rappel sur evenement Paint /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void VueControlePTZ_Paint(object sender, PaintEventArgs e) { UpdateVue(); }
Quelqu'un peut m'expliquer ce qui cloche pour faire afficher cet élément ?
Merci![]()







Répondre avec citation
Partager