Если честно делал по литературе с разных источников. Может есть тогда иной какой то метод, а то я просто учусь, вступать в дискусии аргументировано пока по данной теме не могу. Может подскажите как надо правильно??
#pragma once
namespace animation_boyko {
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>
/// Сводка для Form1
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO: добавьте код конструктора
//
}
protected:
/// <summary>
/// Освободить все используемые ресурсы.
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::TextBox^ textBox1;
protected:
private: System::Windows::Forms::PictureBox^ pictureBox1;
private: System::Windows::Forms::Label^ label1;
private: System::Windows::Forms::Timer^ timer1;
private: System::ComponentModel::IContainer^ components;
private:
/// <summary>
/// Требуется переменная конструктора.
/// </summary>
#pragma region Windows Form Designer generated code
/// <summary>
/// Обязательный метод для поддержки конструктора - не изменяйте
/// содержимое данного метода при помощи редактора кода.
/// </summary>
void InitializeComponent(void)
{
this->components = (gcnew System::ComponentModel::Container());
System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(Form1::typeid));
this->textBox1 = (gcnew System::Windows::Forms::TextBox());
this->pictureBox1 = (gcnew System::Windows::Forms::PictureBox());
this->label1 = (gcnew System::Windows::Forms::Label());
this->timer1 = (gcnew System::Windows::Forms::Timer(this->components));
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox1))->BeginInit();
this->SuspendLayout();
//
// textBox1
//
this->textBox1->Location = System::Drawing::Point(81, 21);
this->textBox1->Name = L"textBox1";
this->textBox1->Size = System::Drawing::Size(100, 20);
this->textBox1->TabIndex = 0;
//
// pictureBox1
//
this->pictureBox1->Image = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"pictureBox1.Image")));
this->pictureBox1->Location = System::Drawing::Point(52, 124);
this->pictureBox1->Name = L"pictureBox1";
this->pictureBox1->Size = System::Drawing::Size(69, 67);
this->pictureBox1->SizeMode = System::Windows::Forms::PictureBoxSizeMode::AutoSize;
this->pictureBox1->TabIndex = 1;
this->pictureBox1->TabStop = false;
//
// label1
//
this->label1->AutoSize = true;
this->label1->Location = System::Drawing::Point(20, 24);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(38, 13);
this->label1->TabIndex = 2;
this->label1->Text = L"Speed";
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(284, 262);
this->Controls->Add(this->label1);
this->Controls->Add(this->pictureBox1);
this->Controls->Add(this->textBox1);
this->Name = L"Form1";
this->Text = L"Form1";
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox1))->EndInit();
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
double n;
private: System::Void timer1_Tick(System::Object^ sender, System::EventArgs^ e) {
if(pictureBox1->Left<this->Width-pictureBox1->Width && n==0)
pictureBox1->Left=pictureBox1->Left+1;
else n=1;
if(pictureBox1->Left>0 && n==1)
pictureBox1->Left=pictureBox1->Left-1;
else n=0;
}
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
n=0;
}
private: System::Void textBox1_TextChanged(System::Object^ sender, System::EventArgs^ e)
{
// textBox1->Text=System::Convert::ToString(timer1->Interval);
if (textBox1->Text->Length>0)timer1->Interval=System::Convert::ToInt16(textBox1->Text);
}
};
}