如何在Tshape中写字符串(delphi)
 尽量能附上源程序说明,最好能有个具体的事例
 

解决方案 »

  1.   

    TCustomShape   =   class(TShape)   
          private   
              procedure   CMTextChanged(var   Message:   TMessage);   message   CM_TEXTCHANGED;   
          protected   
              procedure   Paint;   override;   
          public   
              property   Text;   
              property   Color;   
              property   Font;   
          end;   
        
      procedure   TCustomShape.CMTextChanged(var   Message:   TMessage);   
      begin   
          Invalidate   
      end;   
        
      procedure   TCustomShape.Paint;   
      begin   
          Brush.Color   :=   Color;   
        
          inherited;   
        
          Canvas.Font   :=   Font;   
          Canvas.TextOut(2,   2,   Text);   
      end;   
        
        
      procedure   TForm1.Button1Click(Sender:   TObject);   
      begin   
          with   Shape   do   
          begin   
              Color   :=   clWhite;   
              Font.Color   :=   clRed;   
              Text   :=   'WGYKING'   
          end;   
      end;   
        
      procedure   TForm1.FormCreate(Sender:   TObject);   
      begin   
          Shape   :=   TCustomShape.Create(nil);   
          Shape.Parent   :=   Self   
      end;   
        
      procedure   TForm1.FormClose(Sender:   TObject;   var   Action:   TCloseAction);   
      begin   
          FreeAndNil(Shape);   
      end;
      

  2.   

    pilicat 
     感谢你的回答,能稍微加的注释么?
    本人刚开始接触delphi,不太懂....
      还有这个怎么给回答人分数??