Using Delphi BDS 2006, if I have a TPanel on a form, with BorderStyle = BsSingle, and BorderWidth = 1,
if you paint on the form's canvas and paint something over this border,
and then I call Panel1.repaint and Form1.repaint;
everything is redrawn except for the border.
To redraw the border, I have to say:
Panel1.BorderStyle := bsNone;
Panel1.BorderStyle := bsSingle;
(the reason this works is because this calls panel1.RecreateWnd which "destroys the underlying windows object" and recreates it. You cannot however call panel1.RecreateWnd directly because it is private);
Another solution seems to be:
How can I repaint this border properly?
Attached are more detailed instructions on how to recreate the problem...
On a form, place a TPanel.
Set its Left to 50;
Set its Top to 50;
Set its BorderStyle = bsSingle
Set BorderWidth to 1 // (this doesn't actually matter, it can also be 0).
//Paint onto the forms canvas by putting a TButton with this OnClick event:
procedure TForm1.Button1Click(Sender: TObject);
C : TCanvas;
MyHDC : HDC;
C := TCanvas.Create;
with C do
MyHDC := GetWindowDC(self.handle);
Handle := MyHDC;
Brush.Style := bsSolid;
Pen.Width := 8;
//NOW REPAINT THE PANEL
//NOW REPAINT THE FORM
panel1.BorderStyle := bsNone;
panel1.BorderStyle := bsSingle;