C++ > CLI:トラックバー

基本プロジェクトにトラックバーを配置します。


ラベルも配置します。


ラベルのプロパティのフォントサイズを24にします。


トラックバーをダブルクリックして自動作成されたコードに
以下のコードを追加します。

label1->Text=trackBar1->Value.ToString();


ビルドして実行してみましょう。

 MyForm.cpp

#pragma comment(linker, "/SUBSYSTEM:WINDOWS /ENTRY:mainCRTStartup")
#include "MyForm.h"

using namespace Project1;

[STAThreadAttribute]
int main(){
 MyForm ^form1 = gcnew MyForm;
 form1->ShowDialog();
 return 0;
}

MyForm.h

#pragma once

namespace Project1 {

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

 /// <summary>
 /// MyForm の概要
 /// </summary>
 public ref class MyForm : public System::Windows::Forms::Form
 {
 public:
  MyForm(void)
  {
   InitializeComponent();
   //
   //TODO: ここにコンストラクター コードを追加します
   //
  }

 protected:
  /// <summary>
  /// 使用中のリソースをすべてクリーンアップします。
  /// </summary>
  ~MyForm()
  {
   if (components)
   {
    delete components;
   }
  }
 private: System::Windows::Forms::TrackBar^  trackBar1;
 protected:
 private: System::Windows::Forms::Label^  label1;


 protected:

 private:
  /// <summary>
  /// 必要なデザイナー変数です。
  /// </summary>
  System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
  /// <summary>
  /// デザイナー サポートに必要なメソッドです。このメソッドの内容を
  /// コード エディターで変更しないでください。
  /// </summary>
  void InitializeComponent(void)
  {
   this->trackBar1 = (gcnew System::Windows::Forms::TrackBar());
   this->label1 = (gcnew System::Windows::Forms::Label());
   (cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->trackBar1))->BeginInit();
   this->SuspendLayout();
   //
   // trackBar1
   //
   this->trackBar1->Location = System::Drawing::Point(48, 75);
   this->trackBar1->Name = L"trackBar1";
   this->trackBar1->Size = System::Drawing::Size(104, 45);
   this->trackBar1->TabIndex = 0;
   this->trackBar1->Scroll += gcnew System::EventHandler(this, &MyForm::trackBar1_Scroll);
   //
   // label1
   //
   this->label1->AutoSize = true;
   this->label1->Font = (gcnew System::Drawing::Font(L"MS UI Gothic", 24, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
    static_cast<System::Byte>(128)));
   this->label1->Location = System::Drawing::Point(55, 164);
   this->label1->Name = L"label1";
   this->label1->Size = System::Drawing::Size(92, 33);
   this->label1->TabIndex = 1;
   this->label1->Text = L"label1";
   //
   // MyForm
   //
   this->AutoScaleDimensions = System::Drawing::SizeF(6, 12);
   this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
   this->ClientSize = System::Drawing::Size(284, 261);
   this->Controls->Add(this->label1);
   this->Controls->Add(this->trackBar1);
   this->Name = L"MyForm";
   this->Text = L"Hello C++/CLI World !!";
   (cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->trackBar1))->EndInit();
   this->ResumeLayout(false);
   this->PerformLayout();

  }
#pragma endregion

 private: System::Void trackBar1_Scroll(System::Object^  sender, System::EventArgs^  e) {
     label1->Text=trackBar1->Value.ToString();
    }
 };
}

 

 

 

 

 

 

最終更新:2013年10月06日 09:45