Bonsoir à tous,
Je suis nouveau sur ce super forum qui m’a sorti de grosses galères plusieurs fois !! Je vous en remercie.
Cependant je poste cette demande d’aide car j’ai cherché toute la journée et je n’ai pas trouvé réponse à mon problème.
C'est la première fois que j'utilise un formulaire et je n'ai peu être pas fais les bons choix...
Pour débuter j’ai crée un formulaire de base (code visual c++) et j'ai crée un composant picturebox en dynamique (jusque là ça va… enfin je pense…) .
Dans mes événements je voudrais que dès que je click sur ce picturebox, l’image change sur ce même picturebox.
Voici mon code (qui ne marche 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
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
#pragma once
#include "Struct.h"
#include <string>
using namespace std;
 
namespace ftuy 
{	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;
 
	public ref class Form1 : public System::Windows::Forms::Form
	{	public:
			Form1()
			{	InitializeComponent();
 
			//creation et initialisation du picturebox dynamiquement ( à terme il y en aura un nombre indeterminé)
				System::Windows::Forms::PictureBox^  Picture;
				Picture = (gcnew System::Windows::Forms::PictureBox());
				(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(Picture))->BeginInit();
				Picture->Name="image";
				Picture->Location = System::Drawing::Point(0, 0);
				Picture->TabIndex = 0;
				Picture->ImageLocation="C:\\mon_image.bmp";
				Controls->Add(Picture);
				(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(Picture))->EndInit();
 
				Picture->Click += gcnew System::EventHandler(this, &Form1::Picture_Click);				
			}
 
		private: System::Void Picture_Click(System::Object^  sender, System::EventArgs^  e) 
		{	Form1::Picture->ImageLocation="C:\\mon_image2.bmp";
		}
 
		protected:
			~Form1()
			{	if (components)
				{	delete components;
				}
			}
		private:
			System::ComponentModel::Container ^components;
 
#pragma region Windows Form Designer generated code
		void InitializeComponent(void)
		{this->SuspendLayout();
		// 
		// Form1
		// 
		this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
		this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
		this->ClientSize = System::Drawing::Size(284, 262);
		this->Name = L"Form1";
		this->Text = L"Form1";
		this->ResumeLayout(false);
 
		}
		#pragma endregion
	 }
	};
}
Dans la méthode Picture_Click() il me dit que le composant Picture ne fait pas partie de Form1, ce qui est normal vu qu’il est crée dynamiquement.
Auriez vous une solution ?
Merci d’avance
Bonne soirée