T
T
techoproMas2016-05-04 13:32:12
visual studio
techoproMas, 2016-05-04 13:32:12

How to draw in visual studio c++ 2010?

Hello. Can you please tell me how to draw a line on a PictureBox in visual studio? I did it like this, no errors, but nothing happens ...

private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
        
         pictureBox1->Refresh();
      }
  private: System::Void pictureBox1_Paint(System::Object^ sender, System::Windows::Forms::PaintEventArgs^ e) {
        // Create pen.
          Pen^ blackPen = gcnew Pen( Color::Black,3.0f );

          // Create location and size of ellipse.
          int x = 0;
          int y = 0;
          int width = 100;
          int height = 100;

          // Draw ellipse to screen.
          e->Graphics->DrawEllipse( blackPen, x, y, width, height );
      }

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Ananiev, 2016-05-04
@SaNNy32

https://social.msdn.microsoft.com/Forums/vstudio/e...

D
DivelNick, 2016-05-04
@DivelNick

Why are you drawing in pictureBox ? isn't pictureBox for placing a picture?
Try using flowLayoutPanel.
For example:
SolidBrush^ myBrush = gcnew SolidBrush(Color::White);
Graphics^ gr= this->flowLayoutPanel1->CreateGraphics(); // try this with pictureBox
gr->FillRectangle(myBrush, 0, 0, 100, 100);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question