在图像上放置文本(文本可以随意修改且可拖动)(300分)

  • 主题发起人 主题发起人 zeroyy
  • 开始时间 开始时间
Z

zeroyy

Unregistered / Unconfirmed
GUEST, unregistred user!
要求:Delphi5中可运行、操作无闪烁
 
没有括号里的东西,倒是很容易做到
抢的都是分啊!
 
procedure TForm1.Label1EndDrag(Sender, Target: TObject; X, Y: Integer);
var p:TPoint;
begin
GetCursorPos(p);
Label1.Left:=p.X-left-BorderWidth;
Label1.Top:=p.Y-top-Height+ClientHeight;
end;
设计时设定:TLabel->BringToFront,Transparent=true;DragMode=dmAutomatic,
DragKind=dkDrag
 
Transparent=true
 
我想要的效果就像画图中的一样,要能够框取后随意拖动。当然能做到像Photoshop那样的效果就更好了。呵呵
 
你需要在移动时把图像复制到一个区域内,然后文字贴上去,最后复制到当前显示界面上,并同文字拖动可在图像的onmousemove事件中处理。
 
可否给个示例?谢谢!
 
发给你一个例子了,虽然不一定一样,但是有很大的帮助
 
原来我写过,可惜我的机器换了。
procedure TForm1.ControlMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
downX:= X;
downY:= Y;
dragging := True;
TCracker(Sender).MouseCapture := True;
end;

procedure TForm1.ControlMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
If dragging Then with Sender As TControl Do Begin
Left := X-downX+Left;
Top := Y-downY+Top;
End;
end;

 
这个实现起来很难,但是可以给你思路,我就是做的这个东西,第一步,在一个窗体上画一个背景,代码有些地方不完整。自己分析一下,主要的在这里
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;
第三步,还要处理闪烁,移动的时候,用鼠标按下判断是否选中。然后移动。
 
好像挺难的,帮你顶顶,顺便接点分
 
我用了一个笨办法:用了N个Label,然后处理完其他操作后用Textout.
 
多人接受答案了。
 
后退
顶部