这个实现起来很难,但是可以给你思路,我就是做的这个东西,第一步,在一个窗体上画一个背景,代码有些地方不完整。自己分析一下,主要的在这里
procedure Tfrmbase.SetFormBackMap(mapfileName: string);
begin
FFrmBackImage := TMetaFile.create;
try
FFrmBackImage.LoadFromFile(MainForm.GetInstallDir + IMAGE_DIR + '/' +
mapFileName);
bBackImage := true;
except
FFrmBackImage.free;
FFrmBackImage := nil;
bBackImage := false;
end;
FbackMapRect := backPicRect;
DArea.StretchDraw(fbackmaprect, FFrmBackImage);
第二步,在一个背景上画一个区域也可以,写上你要的文字。
代码:
if ishave = true then
myResourceName := 'roomhave'
else
myResourceName := 'room';
MapGraph.LoadFromResourceName(Hinstance, myResourceName);
if bmppict then
begin
if pictname <> '0' then
begin
try
MapGraph.LoadFromFile(MainForm.GetInstallDir + '../images/' + pictname);
myRect.right := myrect.Left + 27;
myRect.bottom := myrect.top + 27;
except
end;
end
else
begin
myWidth := MapGraph.Width;
myHeight := MapGraph.Height;
myRect.right := myrect.Left + myWidth - 2;
myRect.bottom := myrect.top + myHeight - 4;
end;
end;
with myCanvas do
begin
oldColor := brush.color;
OldPenColor := pen.color;
OldPenWidth := pen.width;
oldPenStyle := pen.style;
OldSty := brush.style;
oldFontColor := font.color;
if myCaption <> '' then
begin
TextOut(captionPoint.x, captionPoint.y, myCaption);
end;
brush.style := bsSolid;
pen.Color := PenColor;
pen.width := PenWidth;
brush.color := myColor;
FillRect(myRect);
StretchDraw(myRect, mapGraph);
if IsSelected then
begin
GetMySeleRect;
DrawClickRect(myRect, bSelectChanged);
end;
//恢复以前的数据
brush.color := oldColor;
brush.style := OldSty;
pen.color := OldPenColor;
pen.style := oldPenStyle;
pen.width := OldPenWidth;
font.color := oldFontColor;
end;
第三步,还要处理闪烁,移动的时候,用鼠标按下判断是否选中。然后移动。