Порядок создания элементов управления



 

Рис. Окно дизайнера формы

Класс формы

#pragma once

#include <math.h>

#include <stdlib.h>

using namespace std;

namespace tmr1 {

 

using namespace System;

using namespace System::ComponentModel;

using namespace System::Collections;

using namespace System::Windows::Forms;

using namespace System::Data;

using namespace System::Drawing;

 

public ref class Form1 : public System::Windows::Forms::Form

{

public:

Form1(void)

{

InitializeComponent();

//TODO: Add the constructor code here

im=this->CreateGraphics();

col=gcnew Color;

pen =gcnew Pen(col->Red);

// Build the rectangles from points and size

Drawing::Point point1 = Drawing::Point(25,45);

Drawing::Size size = Drawing::Size(150, 105);

rect1 = Drawing::Rectangle(point1, size);

}

protected:

~Form1()

{

if (components)

{

       delete components;

}

}

private: System::Windows::Forms::Button^ button1;

protected:

private: System::Windows::Forms::Button^ button2;

private: System::Windows::Forms::Timer^ timer1;

private: System::ComponentModel::IContainer^ components;

private:

 Color ^col;

 Graphics ^im;

 Pen ^ pen ;

 Drawing::Rectangle rect1;

#pragma region Windows Form Designer generated code

void InitializeComponent(void)

{

this->components = (gcnew System::ComponentModel::Container());

this->button1 = (gcnew System::Windows::Forms::Button());

this->button2 = (gcnew System::Windows::Forms::Button());

this->timer1 = (gcnew System::Windows::Forms::Timer(this->components));

this->SuspendLayout();

this->Paint +=

gcnew System::Windows::Forms::PaintEventHandler(this,

       &Form1::Form1_Paint);

// button1

this->button1->Location = System::Drawing::Point(43, 203);

this->button1->Name = L"button1";

this->button1->Size = System::Drawing::Size(74, 30);

this->button1->TabIndex = 0;

this->button1->Text = L"Start";

this->button1->UseVisualStyleBackColor = true;

this->button1->Click += gcnewSystem::EventHandler(this,&Form1::button1_Click);

// button2

this->button2->Location = System::Drawing::Point(164, 203);

this->button2->Name = L"button2";

this->button2->Size = System::Drawing::Size(75, 27);

this->button2->TabIndex = 1;

this->button2->Text = L"Stop";

this->button2->UseVisualStyleBackColor = true;

this->button2->Click += gcnew System::EventHandler(this, &Form1::button2_Click);

// timer1

this->timer1->Interval = 1000;

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(284, 262);

this->Controls->Add(this->button2);

this->Controls->Add(this->button1);

this->Name = L"Form1";

this->Text = L"Form1";

this->ResumeLayout(false);

     

}

#pragma endregion

//----------My code--------------

private:

System::Void Form1_Paint(System::Object^ sender,

System::Windows::Forms::PaintEventArgs^ e)

{

// Draw a rectangle

e->Graphics->DrawRectangle(Pens::Black, rect1);

}

 

private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {

if(timer1->Enabled);else timer1->Enabled=true;

 im->DrawRectangle(Pens::Black, rect1);}

private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {

 if(!timer1->Enabled);else timer1->Enabled=false; }

private: System::Void timer1_Tick(System::Object^ sender, System::EventArgs^ e) {

static float x=100,y=100,fi=0,hfi=3.14159/30,fil,pi=3.14159 ,

x1=100,y1=100,xl,yl,x1l,y1l,cx=100,

cy=100,l1=20,l=50,ts=0;

x1l=x1;y1l=y1;xl=x;yl=y;

static int t;

t++;

y=100-l*sin(fi+pi/2);

x=100-l*cos(fi+pi/2);

x1=cx+l1*cos(fi+pi/2);

y1=cy+l1*sin(fi+pi/2);

fi=fi+hfi;

pen->Color=this->BackColor;

pen->Width=2;

im->DrawLine(pen,int(xl),int(yl),100,100);

im->DrawLine(pen,int(x1l),int(y1l),int(cx),int(cy));

if(t%2)pen->Color=col->Cyan;else pen->Color=col->Red;

im->DrawLine(pen,int(x1),int(y1),int(cx),int(cy));

im->DrawLine(pen,int(x),int(y),100,100);

im->DrawEllipse((pen->Width=1,pen),int(cx-5),int(cy-5),10,10);

 }

};

}

 

Контрольные вопросы.


 

Список литературы

1. Анисимов, А.Е. Сборник заданий по основаниям программирования : учеб.пособие / А.Е.Анисимов,В.В.Пупышев .— М. : Интернет-ун-т информ. технологий; БИНОМ. Лаборатория знаний, 2006 .— 348с. <15>

2. Макконелл, Д. Основы современных алгоритмов : учеб. пособие — М. : Техносфера, 2006 .— 368 с. <7>

3. Подбельский, В.В. Язык Си+ : Учеб.пособие для вузов / В.В.Подбельский .— 5-е изд. — М. : Финансы и статистика, 2003 .— 560с. <13>

4. Павловская, Т.А. C/C++:Программирование на языке высокого уровня : Учебник для вузов / Т.А.Павловская .— М.и др. : Питер, 2004 .— 461с.<7>

5. Ганеев, Р.М. Проектирование интерфейса пользователя средствами Win32 API : учеб. пособие для вузов / Р. М. Ганеев .— 2-е изд., испр. и доп. — М. : Горячая линия-Телеком, 2007 .— 358 с.<3>

6. Вирт Н. Алгоритмы + структуры данных = программы. М.; Mиp, 1985. – 281 с.

7. Шлее, М. Профессиональное программирование на С++ / М.Шлее .— СПб. : БХВ-Петербург, 2005 .— 544с. : ил. + 1 CD .— (В подлиннике). <3>

8. Страуструп, Б. Язык программирования Си++ : Спец.изд. / Б.Страуструп;Пер.с англ.С.Анисимова,М.Кононова;Под ред.Ф.Андреева,А.Ушаков .— М. : Бином, 2004 .— 1098с. <4>

9. Шилдт, Г. C# : Учеб.курс / Г.Шилдт;Пер.с англ.А.Падалки .— М.и др. : Питер, 2003 .— 512 с. <4>

10. Секунов, Н.Ю. Разработка приложений на С++ и С# / Н.Ю.Секунов .— М.и др. : Питер, 2003 .— 608с. — (Б-ка программиста) . <3>

11. Рихтер, Д. Windows для профессионалов : Создание эффективных Win32-приложений с учетом специфики 64-разрядной версии Windows / Д.Рихтер;Пер.с англ.:Ю.Е.Е.Купцевич,А.Р.Врублевский;Под общ.ред.Ю.Е.Купцевича .— 4-е изд. — М.и др. : Питер, 2004 .— 722с.<3>

 


Дата добавления: 2019-09-13; просмотров: 193; Мы поможем в написании вашей работы!

Поделиться с друзьями:






Мы поможем в написании ваших работ!