全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:1312
推到 Plurk!
推到 Facebook!

拖动控件边框改变大小

答題得分者是:st33chen
wq236589
一般會員


發表:21
回覆:37
積分:16
註冊:2008-08-27

發送簡訊給我
#1 引用回覆 回覆 發表時間:2008-10-28 13:31:46 IP:123.181.xxx.xxx 訂閱
怎么实现运行程序以后能像“编辑程序”时一样,拖动“控件”边框来改变控件的大小啊!
st33chen
尊榮會員


發表:15
回覆:591
積分:1201
註冊:2005-09-30

發送簡訊給我
#2 引用回覆 回覆 發表時間:2008-10-28 21:34:55 IP:122.116.xxx.xxx 未訂閱
您好,

這問題蠻有趣的, 記得好像有元件可以做到, 但可能要再花時間 google 一下.
剛剛用自己的想法測了一下 tedit, 雖然不是拖动边框, 而是按住元件內任何一點,
來托拉增減元件寛度.
我知道這絶對不是您要的解答, 但頗好玩的
參考一下

var
ox, ii : integer;
procedure TForm1.Edit1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if ox=0 then begin
ox := x;
ii := 1;
end;
end;
procedure TForm1.Edit1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
ox :=0;
ii :=0;
end;
procedure TForm1.Edit1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if ii=1 then begin
if ox =0 then
ox :=x
else begin
edit1.Width := edit1.Width x-ox;
ox := 0;
end;
end;
end;

===================引 用 wq236589 文 章===================
怎么实现运行程序以后能像“编辑程序”时一样,拖动“控件”边框来改变控件的大小啊!
------
IS IT WHAT IT IS
我是 李慕白 請倒著唸.
又想把老話拿出來說, 請用台語發音 : 專家專家全是ROBOT CAR (滷肉腳啦);
都已接手這麼久了, 績效還是那麼爛, 講話還那麼大聲.
hagar
版主


發表:143
回覆:4056
積分:4445
註冊:2002-04-14

發送簡訊給我
#3 引用回覆 回覆 發表時間:2008-10-28 22:22:57 IP:220.137.xxx.xxx 未訂閱
可參考 Justmade 大大的發表: http://delphi.ktop.com.tw/board.php?cid=31&fid=79&tid=31513

現成的元件小弟知道的有 TStretchHandle 可用
st33chen
尊榮會員


發表:15
回覆:591
積分:1201
註冊:2005-09-30

發送簡訊給我
#4 引用回覆 回覆 發表時間:2008-10-29 09:07:07 IP:122.116.xxx.xxx 未訂閱
您好,

果然就有大大提供現成的元件. 謝謝啦.

雖然我的工作中好像用不這這個功能, 為了好玩,
剛剛再改了一下我的測試, 可行耶, 也請參考一下這個 diy 版本.

unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
procedure Edit1StartDrag(Sender: TObject; var DragObject: TDragObject);
procedure Edit1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
procedure Edit1StartDock(Sender: TObject; var DragObject: TDragDockObject);
procedure Edit1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
procedure Edit1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
ox, oy : integer;
in_drag, in_drag_x, in_move, in_drag_y : boolean;
implementation
{$R *.dfm}
procedure TForm1.Edit1StartDrag(Sender: TObject;
var DragObject: TDragObject);
begin
ox := 0;
oy := 0;
end;
procedure TForm1.Edit1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
begin
if (edit1.Width-x<10) and (edit1.Height-y<10) then edit1.cursor := crsizenwse
else if edit1.Width-x<10 then edit1.cursor := crsizewe
else if edit1.Height-y<10 then edit1.cursor := crsizens
else edit1.Cursor := crdefault;
if in_drag_x then begin
if ox =0 then
ox := x
else begin
edit1.Width := edit1.Width x-ox;
ox := 0;
end;
end;
if in_drag_y then begin
if oy =0 then
oy := y
else begin
edit1.height := edit1.Height y-oy;
oy :=0;
end;
end;
if in_move then begin
if ox =0 then begin
ox := x;
oy := y;
end
else begin
edit1.left := edit1.left x-ox;
edit1.top := edit1.top y-oy;
ox := 0;
oy :=0;
end;
end;
end;
procedure TForm1.Edit1StartDock(Sender: TObject; var DragObject: TDragDockObject);
begin
ox := 0;
oy := 0;
end;
procedure TForm1.Edit1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if not in_drag then begin
if edit1.Width-x<10 then begin
in_drag_x := true;
edit1.cursor := crsizewe;
end;
if edit1.Height-y<10 then begin
in_drag_y := true;
edit1.cursor := crsizens;
end;
if in_drag_x and in_drag_y then edit1.cursor := crsizenwse;
if in_drag_x or in_drag_y then
in_move := false
else begin
in_move := true;
edit1.Cursor := crsizeall;
end;
end;
ox := x;
oy := y;
end;
procedure TForm1.Edit1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
in_drag := false;
in_drag_x := false;
in_drag_y := false;
in_move := false;
edit1.cursor := crdefault;
end;
end.
------
IS IT WHAT IT IS
我是 李慕白 請倒著唸.
又想把老話拿出來說, 請用台語發音 : 專家專家全是ROBOT CAR (滷肉腳啦);
都已接手這麼久了, 績效還是那麼爛, 講話還那麼大聲.
wq236589
一般會員


發表:21
回覆:37
積分:16
註冊:2008-08-27

發送簡訊給我
#5 引用回覆 回覆 發表時間:2008-10-30 10:19:49 IP:124.237.xxx.xxx 訂閱
谢谢 st33chen 大大的耐心分给你了,版主也不会在乎那点的
系統時間:2024-05-07 17:20:07
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!