Newbie graphics programming

  • Thread starter Thread starter Kyle
  • Start date Start date
K

Kyle

I want to build a simple application in VC++ using .NET that draws a line in
a graphics panel when a button is hit. I can see the APIs Graphics.DrawLine
etc. But there is this Graphics object that appears to be available only in
a repaint function. I could use some examples on how to do some simple
graphics (rectangle, line, circle, etc.) on a graphics panel.

Thanks,
Kyle
 
Panel has a CreateGraphics () method (inherited from Control) that you can
call to get a Graphics object when one is not passed to you.

Regards,

Jasper Kent
 
I put the following code in.. but I get a compile error:
private: System::Windows::Forms::Button * button1;

private: System::Windows::Forms::PictureBox * pictureBox1;

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->button1 = new System::Windows::Forms::Button();

this->pictureBox1 = new System::Windows::Forms::PictureBox();

this->SuspendLayout();

//

// button1

//

this->button1->Location = System::Drawing::Point(40, 16);

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

this->button1->TabIndex = 0;

this->button1->Text = S"button1";

this->button1->Click += new System::EventHandler(this, button1_Click);

//

// pictureBox1

//

this->pictureBox1->Location = System::Drawing::Point(168, 16);

this->pictureBox1->Name = S"pictureBox1";

this->pictureBox1->Size = System::Drawing::Size(752, 576);

this->pictureBox1->TabIndex = 1;

this->pictureBox1->TabStop = false;

this->pictureBox1->Click += new System::EventHandler(this,
pictureBox1_Click);

//

// Form1

//

this->AutoScaleBaseSize = System::Drawing::Size(6, 15);

this->ClientSize = System::Drawing::Size(944, 608);

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

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

this->Name = S"Form1";

this->Text = S"Form1";

this->ResumeLayout(false);

}

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

{

Graphics g = CreateGraphics();

Pen pen = new Pen(Color.Blue);

}

private: System::Void pictureBox1_Click(System::Object * sender,
System::EventArgs * e)

{


}

};

}



Error is:

Illegal use of managed type 'System::Drawing::Graphics'; did you forget a
'*'?
 
Back
Top