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);
}
};
} |
Partager