#using <mscorlib.dll>
#using <System.dll>
#using <System.Drawing.dll>
#using <System.Windows.Forms.dll>
using namespace System;
using namespace System::Drawing;
using namespace System::Windows::Forms;
__gc public class SimpleForm : public Form
{
public:
// This is the form that will host the application
SimpleForm();
private:
// The control created with the TrackBar class
TrackBar *Tracker;
// This label will be used to display the position of the track bar
Label *lblPosition;
// This method will be used to initialize the TrackBar control
void CreateTrackBar();
// This event will fire when the user scrolls the track bar
void TrackerChange(Object *Sender, System::EventArgs *pArgs);
};
SimpleForm::SimpleForm()
{
// Set the caption of the form
this->Text = "TrackBar Example";
// Create a label that will show the position of the TrackBar control
lblPosition = new Label;
lblPosition->Location = Point(75, 80);
lblPosition->Text = "10";
lblPosition->AutoSize = true;
Controls->Add(lblPosition);
CreateTrackBar();
}
void SimpleForm::CreateTrackBar()
{
// Create a TrackBar control
Tracker = new TrackBar;
Tracker->Location = Point(20, 20);
Tracker->Orientation = Orientation::Vertical;
Tracker->Size = Drawing::Size(20, 150);
Tracker->Minimum = 10;
Tracker->Maximum = 180;
Tracker->TickFrequency = 10;
Tracker->add_ValueChanged(new EventHandler(this, TrackerChange));
Controls->Add(Tracker);
}
void SimpleForm::TrackerChange(Object *Sender, System::EventArgs *pArgs)
{
// When the value of the TrackBar changes as the user scrolls
// display the value of its position in the label
lblPosition->Text = Tracker->Value.ToString();
}
int __stdcall WinMain()
{
SimpleForm *FM = new SimpleForm();
Application::Run(FM);
return 0;
}
|