このサンプルを見てください:
private: System::Void GO_Click(System::Object^ sender, System::EventArgs^ e)
{
// This works, but the drawn line will be lost when refreshing the panel etc.
//Graphics^ g = panel1->CreateGraphics();
//g->DrawLine(System::Drawing::Pens::Blue, 500, 550, 700, 500);
// This approach draws the line on the BackroungImage of the panel
if (panel1->BackgroundImage == nullptr)
{
panel1->BackgroundImage = gcnew System::Drawing::Bitmap(panel1->Width, panel1->Height);
}
Graphics^ buffGraphics = Graphics::FromImage(panel1->BackgroundImage);
buffGraphics->Clear(panel1->BackColor);
buffGraphics->DrawLine(System::Drawing::Pens::Blue, 500, 550, 700, 500);
panel1->Update();
}
しかし、線を引く方法は他にもたくさんあります。