我刚开始学习delphi,想做一个下面的东西,请大家帮帮忙吧,要是有源码就更好了,在此先谢谢了。
1.在一个平面内,根据简易的坐标画几个填充了不同颜色的方块,每个方块有自己的名字
2.当光标移至方块上时提示方块的名字
真的很着急,在线等

解决方案 »

  1.   

    如果仅仅是为了画几个色块的话,可以考虑动态生产Shape
      

  2.   

    把楼上的意思给你写城代码:
    procedure TForm1.Button1Click(Sender: TObject);
    var
    sp : TShape;
    begin
      sp := TShape.Create(nil);
      sp.Parent := Form1;
      sp.Width := 100;
      sp.Height := 100;
      sp.Left := 100;
      sp.Top := 100;
      sp.ShowHint := true;
      sp.Hint := 'sp';
      //sp.OnMouseMove := bMouseMoveEvent;
    end;
      

  3.   

    用了wudi_1982的代码后确实可以,但是还有3个问题:
    1.怎么让每个shape有自己的颜色呢?
    2.还有就是在点击不同的shape时,弹出不同的对话框?
    3.shape里面怎么填充字?
    在帮帮忙吧,谢谢了
      

  4.   

    不用TShape,用TLabel:unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
          Shift: TShiftState; X, Y: Integer);
        procedure aLabelClick(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;
      i:integer=0;
    implementation{$R *.dfm}procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    var aLabel:TLabel;
    begin
      i:=i+1;
      Randomize;
      aLabel:=TLabel.Create(self);
      with aLabel do
        begin
          Color:=Random($FFFFFF);
          Caption:=IntToStr(i);
          Top:=Y;
          Left:=X;
          Width:=50;
          Height:=50;
          Alignment:=taCenter;
          Layout:=tlCenter;
          Parent:=Form1;
          ShowHint:=True;
          Hint:=Caption;
          OnClick:=aLabelClick;
       end;
    end;procedure TForm1.aLabelClick(Sender: TObject);
    begin
      ShowMessage(TLabel(Sender).Caption);
    end;end.