아래와 같이 간단한 소스인데 폼에는 선을 긋는데 PaintBox에는 선을 안그리네요. 가르쳐 주셔요....
type
TForm1 = class(TForm)
PaintBox1: TPaintBox;
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure PaintBox1Paint(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
dc: HDC;
dc2: HDC;
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
begin
LineTo(dc, 100, 100);
LineTo(dc2, 100, 100);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
dc:= GetDC(PaintBox1.Canvas.Handle);
dc2:= GetDC(self.Handle);
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
ReleaseDC(PaintBox1.Canvas.Handle, dc);
ReleaseDC(self.Handle, dc2);
end;
procedure TForm1.PaintBox1Paint(Sender: TObject);
begin
LineTo(dc, 100, 100);
LineTo(dc2, 100, 100);
end;
hsr/////////////////////////////////////////////////////
그냥요 아래처럼하시면 되는데요...
procedure TForm1.Button2Click(Sender: TObject);
begin
PaintBox1.Canvas.MoveTo(0, 0);
PaintBox1.Canvas.LineTo(100,100);
end;
HDC를 사용하시려면
PaintBox1.Canvas.Handle 자체가 그값입니다
따라서 GetDC로 구할 필요없이 그냥하시면됩니다
procedure TForm1.Button1Click(Sender: TObject);
var
dc : HDC;
begin
dc:= PaintBox1.Canvas.Handle;
MoveToEX(dc,0, 0, nil);
LineTo(dc, 100, 100);
end;