好奇怪,编译并安装后,托到FORM上,为什么显示一片空白 ?该组件主要功能是,用WIN函数画线,并把最终画出来线组合成一个座标图,
直接把这个图放在窗口上..
高人帮看看!
谢了
unit MyDraw1;interfaceuses Classes, Controls, Messages, Windows, Forms, Graphics, StdCtrls,
  Grids, SysUtils,DateUtils;type
  TMyDraw1 = class(TGraphicControl)
  private
    { Private declarations }
  protected
    { Protected declarations }
  public
    mydc:HDC; //定义要设置座标的对象
    Procedure DrawRec(MyDC:HDC;LocX,LocY,W,H:Integer);
    Procedure DrawLine(MyDC:HDC;X1,Y1,X2,Y2:Integer);
    Procedure DrawZero;
    constructor Create(AOwner: TComponent); override;
    
  published
    { Published declarations }
  end;procedure Register;implementationprocedure Register;
begin
  RegisterComponents('ActiveX', [TMyDraw1]);
end;{ TMyDraw1 }Procedure TMyDraw1.DrawRec(MyDC:HDC;LocX,LocY,W,H:Integer);
var
    HalfW,HalfH:Integer;
begin
     Windows.SelectObject(mydc,CreatePen(PS_SOLID,0,clYellow)); 
    HalfW:= W div 2;
    HalfH:= H div 2;
    windows.Rectangle(MyDC,LocX-HalfW,LocY-HalfH,LocX+HalfW,LocY+HalfH);
end;Procedure TMyDraw1.DrawLine(MyDC:HDC;X1,Y1,X2,Y2:Integer);
begin
     //CreatePen( int nPenStyle, int nWidth, COLORREF crColor );
    Windows.SelectObject(mydc,CreatePen(PS_SOLID,0,clYellow)); 
    windows.MoveToEx(mydc,x1,y1,nil);
    windows.LineTo(mydc,x2,y2);
end;
procedure TMyDraw1.DrawZero;
begin
    //设置空心
    Windows.SelectObject(mydc,GetStockObject(NULL_BRUSH));
    SetTextColor(mydc,clRed); //文本颜色
    setbkmode(mydc,transparent);//文本透明    //画座标
    
    DrawRec(mydc,0,0,5,5);
    DrawLine(mydc,0,0,50,0);
    DrawLine(mydc,0,0,0,50);
    //三角形X
    DrawLine(mydc,50,2,50,-2);
    DrawLine(mydc,50,-2,55,0);
    DrawLine(mydc,55,0,50,2);
    //三角形Y
    DrawLine(mydc,-2,50,2,50);
    DrawLine(mydc,2,50,0,55);
    DrawLine(mydc,0,55,-2,50);    Windows.TextOut(mydc,25,8,'X',1);
    Windows.TextOut(mydc,1,25,'Y',1);
end;constructor TMyDraw1.Create(AOwner: TComponent);
begin
  inherited;
    //mydc:=GetDC(self.Parent.Handle);
    DrawZero;
end;

解决方案 »

  1.   

    楼上,怎么改?
    在哪个位置加repaint?
      

  2.   

    TGraphicControl本来就是没东西显示的,请参考TImage放到界面时的样子。不过TImage专门针对设计期进行了判断,如果是设计期的画,就画个框框。
    procedure TImage.Paint;
    var
      Save: Boolean;
    begin
      if csDesigning in ComponentState then
    with inherited Canvas do
    begin
      Pen.Style := psDash;
      Brush.Style := bsClear;
      Rectangle(0, 0, Width, Height);
    end;
      Save := FDrawing;
      FDrawing := True;
      try
    with inherited Canvas do
      StretchDraw(DestRect, Picture.Graphic);
      finally
    FDrawing := Save;
      end;
    end;