Hi all,
I am trying to make a dummy animation program.There is a button and a picturebox.When I click the button I want a line to move from the top to the bottom of the picturebox.
In my program when I click the button the line is drawn in its initial position and stays there BUT when I move the window or minimize it then maximize it again the line appears in another position.Why is this happening?
Sorry if the question is silly but i am new at this.
My Form1.h code follows.Thanks
//
#pragma once
namespace ScintiVCpp
{
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System:ata;
using namespace System:rawing;
using namespace System:rawing:rawing2D;
/// <summary>
/// Summary for Form1
///
/// WARNING: If you change the name of this class, you will need to change the
/// 'Resource File Name' property for the managed resource compiler tool
/// associated with all .resx files this class depends on. Otherwise,
/// the designers will not be able to interact properly with localized
/// resources associated with this form.
/// </summary>
public __gc class Form1 : public System::Windows::Forms::Form
{
public: static System::Windows::Forms::Timer *timer1=new System::Windows::Forms::Timer(); //th
public: int x; //th
public: int y; //th
//public: int Button1Clicked;
public:
Form1(void)
{
InitializeComponent();
//enabling double-buffering to avoid flick
SetStyle(System::Windows::Forms::ControlStyles::UserPaint, true);
SetStyle(System::Windows::Forms::ControlStyles::AllPaintingInWmPaint, true);
SetStyle(System::Windows::Forms::ControlStyles:oubleBuffer, true);
}
protected:
void Dispose(Boolean disposing)
{
if (disposing && components)
{
components->Dispose();
}
__super:ispose(disposing);
}
private: System::Windows::Forms:ictureBox * pictureBox1;
private: System::Windows::Forms::Button * button1;
private:
/// <summary>
/// Required designer variable.
/// </summary>
System::ComponentModel::Container * components;
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
this->pictureBox1 = new System::Windows::Forms:ictureBox();
this->button1 = new System::Windows::Forms::Button();
this->SuspendLayout();
//
// pictureBox1
//
this->pictureBox1->BorderStyle = System::Windows::Forms::BorderStyle::Fixed3D;
this->pictureBox1->Location = System:rawing:oint(152, 64);
this->pictureBox1->Name = S"pictureBox1";
this->pictureBox1->Size = System:rawing::Size(288, 224);
this->pictureBox1->TabIndex = 0;
this->pictureBox1->TabStop = false;
this->pictureBox1->Click += new System::EventHandler(this, pictureBox1_Click);
//
// button1
//
this->button1->Location = System:rawing:oint(32, 152);
this->button1->Name = S"button1";
this->button1->TabIndex = 1;
this->button1->Text = S"button1";
this->button1->Click += new System::EventHandler(this, button1_Click);
//
// Form1
//
this->AutoScaleBaseSize = System:rawing::Size(5, 13);
this->ClientSize = System:rawing::Size(568, 366);
this->Controls->Add(this->button1);
this->Controls->Add(this->pictureBox1);
this->Name = S"Form1";
this->Text = S"Form1";
this->Load += new System::EventHandler(this, Form1_Load);
this->ResumeLayout(false);
}
private: System::Void Form1_Load(System::Object * sender, System::EventArgs * e)
{
}
void pictureBox1_Paint(Object * sender, System::Windows::Forms:aintEventArgs* e)
{
Graphics* g = e->Graphics;
x=pictureBox1->Width-100;
g->DrawLine(new System:rawing:en(System:rawing::Color::Black,2.),x,y,x,y+10);
}
private: System::Void button1_Click(System::Object * sender, System::EventArgs * e)
{
timer1->Start();
timer1->Interval=5;
timer1->Tick += new System::EventHandler(this,&Form1::Ticker);
pictureBox1->BackColor = Color::White;
pictureBox1->Paint += new System::Windows::Forms:aintEventHandler(this, &Form1:ictureBox1_Paint);
this->Invalidate();
}
void Ticker(System::Object* sender, System::EventArgs* e)
{
if(y>0)
y-=1;
else
y=pictureBox1->Height;
this->Invalidate();
}
};
}
I am trying to make a dummy animation program.There is a button and a picturebox.When I click the button I want a line to move from the top to the bottom of the picturebox.
In my program when I click the button the line is drawn in its initial position and stays there BUT when I move the window or minimize it then maximize it again the line appears in another position.Why is this happening?
Sorry if the question is silly but i am new at this.
My Form1.h code follows.Thanks
//
#pragma once
namespace ScintiVCpp
{
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System:ata;
using namespace System:rawing;
using namespace System:rawing:rawing2D;
/// <summary>
/// Summary for Form1
///
/// WARNING: If you change the name of this class, you will need to change the
/// 'Resource File Name' property for the managed resource compiler tool
/// associated with all .resx files this class depends on. Otherwise,
/// the designers will not be able to interact properly with localized
/// resources associated with this form.
/// </summary>
public __gc class Form1 : public System::Windows::Forms::Form
{
public: static System::Windows::Forms::Timer *timer1=new System::Windows::Forms::Timer(); //th
public: int x; //th
public: int y; //th
//public: int Button1Clicked;
public:
Form1(void)
{
InitializeComponent();
//enabling double-buffering to avoid flick
SetStyle(System::Windows::Forms::ControlStyles::UserPaint, true);
SetStyle(System::Windows::Forms::ControlStyles::AllPaintingInWmPaint, true);
SetStyle(System::Windows::Forms::ControlStyles:oubleBuffer, true);
}
protected:
void Dispose(Boolean disposing)
{
if (disposing && components)
{
components->Dispose();
}
__super:ispose(disposing);
}
private: System::Windows::Forms:ictureBox * pictureBox1;
private: System::Windows::Forms::Button * button1;
private:
/// <summary>
/// Required designer variable.
/// </summary>
System::ComponentModel::Container * components;
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
this->pictureBox1 = new System::Windows::Forms:ictureBox();
this->button1 = new System::Windows::Forms::Button();
this->SuspendLayout();
//
// pictureBox1
//
this->pictureBox1->BorderStyle = System::Windows::Forms::BorderStyle::Fixed3D;
this->pictureBox1->Location = System:rawing:oint(152, 64);
this->pictureBox1->Name = S"pictureBox1";
this->pictureBox1->Size = System:rawing::Size(288, 224);
this->pictureBox1->TabIndex = 0;
this->pictureBox1->TabStop = false;
this->pictureBox1->Click += new System::EventHandler(this, pictureBox1_Click);
//
// button1
//
this->button1->Location = System:rawing:oint(32, 152);
this->button1->Name = S"button1";
this->button1->TabIndex = 1;
this->button1->Text = S"button1";
this->button1->Click += new System::EventHandler(this, button1_Click);
//
// Form1
//
this->AutoScaleBaseSize = System:rawing::Size(5, 13);
this->ClientSize = System:rawing::Size(568, 366);
this->Controls->Add(this->button1);
this->Controls->Add(this->pictureBox1);
this->Name = S"Form1";
this->Text = S"Form1";
this->Load += new System::EventHandler(this, Form1_Load);
this->ResumeLayout(false);
}
private: System::Void Form1_Load(System::Object * sender, System::EventArgs * e)
{
}
void pictureBox1_Paint(Object * sender, System::Windows::Forms:aintEventArgs* e)
{
Graphics* g = e->Graphics;
x=pictureBox1->Width-100;
g->DrawLine(new System:rawing:en(System:rawing::Color::Black,2.),x,y,x,y+10);
}
private: System::Void button1_Click(System::Object * sender, System::EventArgs * e)
{
timer1->Start();
timer1->Interval=5;
timer1->Tick += new System::EventHandler(this,&Form1::Ticker);
pictureBox1->BackColor = Color::White;
pictureBox1->Paint += new System::Windows::Forms:aintEventHandler(this, &Form1:ictureBox1_Paint);
this->Invalidate();
}
void Ticker(System::Object* sender, System::EventArgs* e)
{
if(y>0)
y-=1;
else
y=pictureBox1->Height;
this->Invalidate();
}
};
}