IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C++/CLI Discussion :

Création animation en fonction d'une valeur


Sujet :

C++/CLI

  1. #1
    Futur Membre du Club
    Profil pro
    Inscrit en
    Mai 2013
    Messages
    7
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2013
    Messages : 7
    Points : 6
    Points
    6
    Par défaut Création animation en fonction d'une valeur
    Bonsoir,


    J'ai un logiciel que j'ai du réalisé pour un projet.

    Le but est d'afficher la température d'un module EnOcean.




    Un label affiche une température et je voudrai si possible que sur une image de thermomètre que j'ai placé , mettre un rectangle rouge, et celui ci monte et descend en fonction de la valeur (Approximativement , des valeurs en pourcentage)


    Je ne vois vraiment pas comment faire, le code à utiliser.

    Les labels en question :
    ______________________________________________________________

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) {
    			 label1->Text=this->donnees; //on affiche la dernière trame reçue
    		 }
    private: System::Void timer1_Tick(System::Object^  sender, System::EventArgs^  e) {
    			 label2->Text=this->temperature.ToString()+ " °C"; // avec un timer , on va toutes les 100ms mettre à jour la température affichée
    			 panel1->Size.Height=temperature*2;
    		 }
    J'ai donc pensé à crée un panel rouge, qui changerai de taille en fonction de la température du label, sauf aucune idée comment faire.... :
    Genre ceci..
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    panel1->Size.Height=temperature*2;
    Vraiment besoin de votre aide.

    Cordialement

  2. #2
    Expert confirmé
    Inscrit en
    Avril 2008
    Messages
    2 564
    Détails du profil
    Informations personnelles :
    Âge : 64

    Informations forums :
    Inscription : Avril 2008
    Messages : 2 564
    Points : 4 441
    Points
    4 441
    Par défaut
    bonjour R3d0x

    Un panel oui c'est une idee mais il servira juste à contenir ton image :
    - mets sa prop BackgroundImage sur ton image du thermometre .....
    - ajuste la taille du panel au mieux de ta presentation

    - droppe un label (voir code ci-apres:lblThermo) dans le panel..
    - ajuste la taille de ce label pour cacher la zone rectangulaire de dilatation verticale (liquide dilation) de ton image thermometre .
    - la hauteur du label s'etendrait des graduations rouges jusqu'au graduations bleues....
    Cet ajustement se fait sur le designer...

    Helas
    - varier la hauteur du label en fonction de la temperature donnerait un ecoulement vers le bas,pas plus que sa prop Top.
    - faire une rotation d'un control winform n'existe pas non plus dans l'api....
    Il reste GDI et on va dans l'event Paint de notre label recuperer une copie de son DisplayRectangle et :
    - translater l'origine des coords vers le sommet BottomRight du lblThermo(oppose de TopLeft)
    - faire tourner les axes de 180 degres ce qui amene notre copie rectangle avec tete en bas et posterieur en haut..

    - ensuite un timer est charger de generer une valeur alea avec random (entre 0 et hauteur max du label ) et de le peindre .....a chaque tick.

    code du simplistic winform(projet winform) :
    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
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
     
    #pragma once
     
    namespace ThermoCelsius {
     
    	using namespace System;
    	using namespace System::ComponentModel;
    	using namespace System::Collections;
    	using namespace System::Windows::Forms;
    	using namespace System::Data;
    	using namespace System::Drawing;
    	using namespace System::Drawing::Drawing2D;
    	/// <summary>
    	/// Description résumée de Form1
    	/// </summary>
    	public ref class Form1 : public System::Windows::Forms::Form
    	{
    	public:
    		Form1(void)
    		{
    			InitializeComponent();
    			//
    			//TODO: ajoutez ici le code du constructeur
    			//
    			/*this->panel1->Height=200;
    			this->panel1->Width=50;*/
    		}
     
    	protected:
    		/// <summary>
    		/// Nettoyage des ressources utilisées.
    		/// </summary>
    		~Form1()
    		{
    			if (components)
    			{
    				delete components;
    			}
    		}
    	private: System::Windows::Forms::Label^  lblCelsius;
    	protected: 
    	private: System::Windows::Forms::Button^  btnStart;
    	private: System::Windows::Forms::Button^  btnStop;
    	private: System::Windows::Forms::Panel^  panel1;
    	private: System::Windows::Forms::Label^  lblThermo;
    	private: System::Windows::Forms::Timer^  timer1;
    	private: System::ComponentModel::IContainer^  components;
     
    	private:
    		/// <summary>
    		/// Variable nécessaire au concepteur.
    		/// </summary>
     
    		// label  lblThermo : "rectangle rouge" à hauteur variable...
     
    		// panel panel1: contiendra ton image dans prop Backgroundimage
    		// dans ce panel dropper le label lblThermo  et l'ajuster à la zone
    		// graduee (hauteur et largeur)
     
    		// temperature max = hauteur init.de lblThermo
    		static int maxtemp = 0;
     
    		// temperature (varie de 0 à maxTemp la hauteur de lblThermo)
    		static int temp = 0;
     
    		//simule la variation de temp 
    		static Random^ rnd  = gcnew Random();
     
    #pragma region Windows Form Designer generated code
    		/// <summary>
    		/// Méthode requise pour la prise en charge du concepteur - ne modifiez pas
    		/// le contenu de cette méthode avec l'éditeur de code.
    		/// </summary>
    		void InitializeComponent(void)
    		{
    			this->components = (gcnew System::ComponentModel::Container());
    			System::ComponentModel::ComponentResourceManager^  resources = (gcnew System::ComponentModel::ComponentResourceManager(Form1::typeid));
    			this->lblCelsius = (gcnew System::Windows::Forms::Label());
    			this->btnStart = (gcnew System::Windows::Forms::Button());
    			this->btnStop = (gcnew System::Windows::Forms::Button());
    			this->panel1 = (gcnew System::Windows::Forms::Panel());
    			this->lblThermo = (gcnew System::Windows::Forms::Label());
    			this->timer1 = (gcnew System::Windows::Forms::Timer(this->components));
    			this->panel1->SuspendLayout();
    			this->SuspendLayout();
    			// 
    			// lblCelsius
    			// 
    			this->lblCelsius->BackColor = System::Drawing::Color::DarkBlue;
    			this->lblCelsius->Font = (gcnew System::Drawing::Font(L"Tahoma", 9.75F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
    				static_cast<System::Byte>(0)));
    			this->lblCelsius->ForeColor = System::Drawing::Color::White;
    			this->lblCelsius->Location = System::Drawing::Point(158, 58);
    			this->lblCelsius->Name = L"lblCelsius";
    			this->lblCelsius->Size = System::Drawing::Size(100, 23);
    			this->lblCelsius->TabIndex = 0;
    			this->lblCelsius->Text = L"label1";
    			// 
    			// btnStart
    			// 
    			this->btnStart->Location = System::Drawing::Point(31, 13);
    			this->btnStart->Name = L"btnStart";
    			this->btnStart->Size = System::Drawing::Size(75, 23);
    			this->btnStart->TabIndex = 1;
    			this->btnStart->Text = L"start";
    			this->btnStart->UseVisualStyleBackColor = true;
    			this->btnStart->Click += gcnew System::EventHandler(this, &Form1::btnStart_Click);
    			// 
    			// btnStop
    			// 
    			this->btnStop->Location = System::Drawing::Point(161, 12);
    			this->btnStop->Name = L"btnStop";
    			this->btnStop->Size = System::Drawing::Size(75, 23);
    			this->btnStop->TabIndex = 2;
    			this->btnStop->Text = L"stop";
    			this->btnStop->UseVisualStyleBackColor = true;
    			this->btnStop->Click += gcnew System::EventHandler(this, &Form1::btnStop_Click);
    			// 
    			// panel1
    			// 
    			this->panel1->BackColor = System::Drawing::Color::White;
    			this->panel1->BackgroundImage = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"panel1.BackgroundImage")));
    			this->panel1->BackgroundImageLayout = System::Windows::Forms::ImageLayout::Stretch;
    			this->panel1->BorderStyle = System::Windows::Forms::BorderStyle::Fixed3D;
    			this->panel1->Controls->Add(this->lblThermo);
    			this->panel1->Location = System::Drawing::Point(31, 72);
    			this->panel1->Name = L"panel1";
    			this->panel1->Size = System::Drawing::Size(50, 200);
    			this->panel1->TabIndex = 3;
    			// 
    			// lblThermo
    			// 
    			this->lblThermo->BorderStyle = System::Windows::Forms::BorderStyle::FixedSingle;
    			this->lblThermo->FlatStyle = System::Windows::Forms::FlatStyle::Flat;
    			this->lblThermo->Location = System::Drawing::Point(13, 28);
    			this->lblThermo->Name = L"lblThermo";
    			this->lblThermo->Size = System::Drawing::Size(20, 110);
    			this->lblThermo->TabIndex = 0;
    			this->lblThermo->Text = L"lbl thermo";
    			this->lblThermo->Paint += gcnew System::Windows::Forms::PaintEventHandler(this, &Form1::lblThermo_Paint);
    			// 
    			// timer1
    			// 
    			this->timer1->Tick += gcnew System::EventHandler(this, &Form1::timer1_Tick);
    			// 
    			// Form1
    			// 
    			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
    			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
    			this->ClientSize = System::Drawing::Size(281, 317);
    			this->Controls->Add(this->panel1);
    			this->Controls->Add(this->btnStop);
    			this->Controls->Add(this->btnStart);
    			this->Controls->Add(this->lblCelsius);
    			this->Name = L"Form1";
    			this->Text = L"Form1";
    			this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
    			this->SizeChanged += gcnew System::EventHandler(this, &Form1::Form1_SizeChanged);
    			this->panel1->ResumeLayout(false);
    			this->ResumeLayout(false);
     
    		}
    #pragma endregion
    	private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
     
    		   maxtemp  = this->lblThermo->Height ;
    		 }
     
    private: System::Void btnStart_Click(System::Object^  sender, System::EventArgs^  e) {
                    timer1->Enabled = true;
    				timer1->Interval = 1000;
    				timer1->Start();		 
     
     
    		 }
    private: System::Void btnStop_Click(System::Object^  sender, System::EventArgs^  e) {
     
    			 timer1->Stop();
     
    		 }
    private: System::Void timer1_Tick(System::Object^  sender, System::EventArgs^  e) {
     
    			 temp = rnd->Next(0,   maxtemp );
     
    			 /*label auxiliaire affiche valeur temp*/
               	 this->lblCelsius->Text = temp.ToString();
     
    			/*	demande lblThermo de se paindre */
    			this->lblThermo->Invalidate();
     
    		 }
     
     
     
    		  /*tenir compte du resize*/
    private: System::Void Form1_SizeChanged(System::Object^  sender, System::EventArgs^  e) {
     
    			 /*update maxtemp*/
    			 maxtemp  = this->lblThermo->Height ;
    			 this->lblThermo->Invalidate();
     
     
    		 }
    private: System::Void lblThermo_Paint(System::Object^  sender, System::Windows::Forms::PaintEventArgs^  e) {
     
    		    Graphics^  gr = e->Graphics;
    			gr->ResetTransform();
     
    			/*dessine countour de lblThermo */
    			Rectangle outRect  = this->lblThermo->ClientRectangle;
    			gr->DrawRectangle(Pens::Black, outRect);
     
     
    			/*translate l'origine des coords vers 
    			le sommet BottomRight du lblThermo(oppose de TopLeft)*/
     
    			float ox=(float)this->lblThermo->Width;
    			float oy=(float)this->lblThermo->Height;
    		    gr->TranslateTransform(ox, oy);
     
    			/* rotation des axes de 180(c'est ce que fait gr.rotate helas)
    			 se croiser la nuque hein....*/ 
     
    			gr->RotateTransform(180);
     
    			/*update height*/
     
    			outRect.Height = temp;
    			gr->FillRectangle(Brushes::Red, outRect);
     
    	 }
     
     
    };
    }

    bon code..........

Discussions similaires

  1. Réponses: 0
    Dernier message: 18/03/2013, 13h05
  2. Création de listes déroulante fonction d'une valeur
    Par toutoune60 dans le forum Excel
    Réponses: 3
    Dernier message: 11/04/2008, 12h11
  3. [VBA-E]couper en fonction d'une valeur
    Par captaine93 dans le forum Macros et VBA Excel
    Réponses: 4
    Dernier message: 06/06/2006, 13h18
  4. Taches en fonction d'une valeur
    Par petitours dans le forum C
    Réponses: 14
    Dernier message: 06/11/2005, 10h40
  5. fonction retournant une valeur
    Par ryan dans le forum ASP
    Réponses: 4
    Dernier message: 06/09/2004, 18h45

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo