giovedì 21 agosto 2014

Aggiunta di un button e ridimensionamento del form

Ho inserito un button nel form.
Il codice, che viene fuori facendo doppio click sul button appena inserito, è scritto nel file Form1.h:
#pragma once

namespace MyCLRProject {

 using namespace System;
 using namespace System::ComponentModel;
 using namespace System::Collections;
 using namespace System::Windows::Forms;
 using namespace System::Data;
 using namespace System::Drawing;

 /// 
 /// Riepilogo per Form1
 /// 
 public ref class Form1 : public System::Windows::Forms::Form
 {
 public:
  Form1(void)
  {
   InitializeComponent();
   //
   //TODO: aggiungere qui il codice del costruttore.
   //
  }

 protected:
  /// 
  /// Liberare le risorse in uso.
  /// 
  ~Form1()
  {
   if (components)
   {
    delete components;
   }
  }
 private: System::Windows::Forms::Button^  button1;
 protected: 

 private:
  /// 
  /// Variabile di progettazione necessaria.
  /// 
  System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
  /// 
  /// Metodo necessario per il supporto della finestra di progettazione. Non modificare
  /// il contenuto del metodo con l'editor di codice.
  /// 
  void InitializeComponent(void)
  {
   this->button1 = (gcnew System::Windows::Forms::Button());
   this->SuspendLayout();
   // 
   // button1
   // 
   this->button1->Location = System::Drawing::Point(12, 12);
   this->button1->Name = L"button1";
   this->button1->Size = System::Drawing::Size(137, 93);
   this->button1->TabIndex = 0;
   this->button1->Text = L"button1";
   this->button1->UseVisualStyleBackColor = true;
   this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
   // 
   // Form1
   // 
   this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
   this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
   this->ClientSize = System::Drawing::Size(284, 261);
   this->Controls->Add(this->button1);
   this->Name = L"Form1";
   this->Text = L"Form1";
   this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
   this->ResumeLayout(false);

  }
#pragma endregion
 private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
    }
 private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
    }
 };
}
Adesso trovo il modo di ridimensionare il form, cui va sempre fatto riferimento con this
 private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
     this->Size=System::Drawing::Size(1000,200 );
    }
 };
E funziona: alla pressione del button il form diventa largo e basso.

Nessun commento:

Posta un commento