So, I have:
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
DrawBackground();
}
private: System::Void DrawBackground(){
Graphics^ g1=this->CreateGraphics();
SolidBrush^ p1 = gcnew SolidBrush(System::Drawing::Color::Gray);
g1->FillRectangle(p1,90,150,600,150);
}
This should load this rectangle when form loaded, but it doesn’t.
Why ?? How to you write this correctly ?
You cannot draw in the Load event, the form isn’t visible yet. Nor is it ever correct to use CreateGraphics(). Whatever you draw won’t survive until the next redraw. Override the OnPaintBackground method instead. Like this:
Note the use of the stack semantics for brush (no hat), that ensures the brush is automatically disposed.