線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:1786
推到 Plurk!
推到 Facebook!

點選image產生的虛線和拉大拉小的功能怎麼作?(付圖)

尚未結案
harktrip
一般會員


發表:30
回覆:30
積分:12
註冊:2007-04-11

發送簡訊給我
#1 引用回覆 回覆 發表時間:2007-11-29 16:54:07 IP:61.221.xxx.xxx 訂閱
請教各位老大,
如圖,


1.滑鼠點選該image物件時,會出現八個小方塊和虛線
--->這是不是應該有現成的可以用(該不會得自己一條線一條線去劃,那麼變態吧?)

2.滑鼠經過那八個小方塊時可以拉大縮小,有沒有比較正常的方法?

這些問題自己摸索很久了,沒結果,各位老大幫個忙,感恩啦
附加檔案:474e7e2f6a4c5_ZOON.gif
編輯記錄
harktrip 重新編輯於 2007-11-29 16:54:45, 註解 無‧
jow
尊榮會員


發表:66
回覆:751
積分:1253
註冊:2002-03-13

發送簡訊給我
#2 引用回覆 回覆 發表時間:2007-11-30 02:09:48 IP:123.193.xxx.xxx 訂閱
嘿, 給個變態的做法, 在Form上選擇一個TControl...

NOTE: 只能選取物件而已, 僅供參考...

[code delphi]
unit fMain;

interface

uses
Windows, Forms, Classes, Controls, Graphics, Messages, ExtCtrls, StdCtrls;

type

TForm1 = class;

TSelectMark = class(TPersistent)
private
function GetSelectedControl: TControl;
protected
FOwner: TForm1;
public
constructor Create(AOwner: TForm1);
procedure Draw;
property SelectedControl: TControl read GetSelectedControl;
end;

TForm1 = class(TForm)
Panel1: TPanel;
Panel2: TPanel;
Panel3: TPanel;
procedure FormCreate(Sender: TObject);
procedure FormPaint(Sender: TObject);
private
FSelectMark: TSelectMark;
FSelectedControl: TControl;
procedure SetSelectedControl(const Value: TControl);
procedure DO_OnMessage(var Msg: TMsg; var Handled: Boolean);
public
property SelectedControl: TControl read FSelectedControl write SetSelectedControl;
end;

var
Form1: TForm1;

implementation

uses SysUtils;

{$R *.dfm}

{ TSelectMark }

constructor TSelectMark.Create(AOwner: TForm1);
begin
inherited Create;
FOwner := AOwner;
end;

procedure TSelectMark.Draw;
var
p: TPen;
r: TRect;
c: TCanvas;
begin
if Assigned(SelectedControl) then
begin
r := SelectedControl.BoundsRect;
Dec(r.Right);
Dec(r.Bottom);
InflateRect(r,2,2);

c := FOwner.Canvas;
c.Lock;
try
p := TPen.Create;
try
p.Assign(c.Pen);
c.Pen.Color := clRed xor (not FOwner.Color);
c.Pen.Width := 2;
c.Pen.Style := psSolid;
c.Pen.Mode := pmXor;
c.Polyline([Point(r.Left , r.Top),
Point(r.Right , r.Top),
Point(r.Right , r.Bottom),
Point(r.Left , r.Bottom),
Point(r.Left , r.Top-1)]);
FOwner.Canvas.Pen.Assign(p);
finally
FreeAndNil(p);
end;
finally
FOwner.Canvas.Unlock;
end;
end;
end;

function TSelectMark.GetSelectedControl: TControl;
begin
Result := FOwner.SelectedControl;
end;

{ TForm1 }

procedure TForm1.SetSelectedControl(const Value: TControl);
begin
if Value <> FSelectedControl then
begin
FSelectMark.Draw;
FSelectedControl := Value;
FSelectMark.Draw;
end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
Application.OnMessage := DO_OnMessage;
FSelectMark := TSelectMark.Create(Self);
SelectedControl := Panel1;
end;

procedure TForm1.FormPaint(Sender: TObject);
begin
if Assigned(FSelectMark) then
begin
FSelectMark.Draw;
end;
end;

procedure TForm1.DO_OnMessage(var Msg: TMsg; var Handled: Boolean);
var
I: Integer;
P: TPoint;
N: TControl;
begin
if Msg.message = WM_LBUTTONDOWN then
begin
GetCursorPos(P);
P := ScreenToClient(P);
N := nil;
for I := 0 to ControlCount-1 do
if PtInRect(Controls[I].BoundsRect, P) then
begin
N := Controls[I];
Break;
end;
Handled := SelectedControl <> N;
SelectedControl := N;
end;
end;

end.
[/code]
harktrip
一般會員


發表:30
回覆:30
積分:12
註冊:2007-04-11

發送簡訊給我
#3 引用回覆 回覆 發表時間:2007-11-30 08:46:06 IP:61.221.xxx.xxx 訂閱
感恩 ...研究中...

(有沒有BUILDER C 板的)
jow
尊榮會員


發表:66
回覆:751
積分:1253
註冊:2002-03-13

發送簡訊給我
#4 引用回覆 回覆 發表時間:2007-11-30 23:37:28 IP:123.193.xxx.xxx 訂閱
閒閒沒事, 寫寫程式...
[code cpp]
//---------------------------------------------------------------------------
#ifndef fMainH
#define fMainH
//---------------------------------------------------------------------------
#include
#include
#include
#include <Forms.hpp><br />#include
//---------------------------------------------------------------------------
class TForm1;
//---------------------------------------------------------------------------
class TSelectMark : TPersistent
{
private:
TControl* __fastcall GetSelectedControl();
protected:
TForm1* FOwner;
public:
__fastcall TSelectMark(TForm1 *AOwner);
void __fastcall Draw();
__property TControl* SelectedControl={read=GetSelectedControl};
};
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published:
TPanel *Panel1;
TPanel *Panel2;
TPanel *Panel3;
void __fastcall FormPaint(TObject *Sender);
protected:
TSelectMark* FSelectMark;
TControl* FSelectedControl;
void __fastcall SetSelectedControl(TControl* Value);
void __fastcall DO_OnMessage(tagMSG &Msg, bool &Handled);
public:
__fastcall TForm1(TComponent* Owner);
__fastcall ~TForm1();
__property TControl* SelectedControl={read=FSelectedControl,write=SetSelectedControl};
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
[/code]

[code cpp]
//---------------------------------------------------------------------------
#include
#pragma hdrstop
#include "fMain.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TSelectMark::TSelectMark(TForm1 *AOwner): TPersistent()
{
FOwner = AOwner;
}
//---------------------------------------------------------------------------
TControl* __fastcall TSelectMark::GetSelectedControl()
{
return FOwner->SelectedControl;
}
//---------------------------------------------------------------------------
void __fastcall TSelectMark::Draw()
{
if(SelectedControl){
TRect r = SelectedControl->BoundsRect;
r.Right--;
r.Bottom--;
InflateRect(&r,2,2);
TCanvas* c = FOwner->Canvas;
c->Lock();
try{
TPen* p = new TPen();
try{
p->Assign(c->Pen);
c->Pen->Color = clRed^(!FOwner->Color);
c->Pen->Width = 2;
c->Pen->Style = psSolid;
c->Pen->Mode = pmXor;
TPoint *pt = new TPoint[5];
try{
pt[0] = Point(r.Left , r.Top );
pt[1] = Point(r.Right, r.Top );
pt[2] = Point(r.Right, r.Bottom );
pt[3] = Point(r.Left , r.Bottom );
pt[4] = Point(r.Left , r.Top-1 );
c->Polyline(pt, 4);
}
__finally{
delete [] pt;
}
c->Pen->Assign(p);
}
__finally{
delete p;
}
}
__finally{
c->Unlock();
}
}
}
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner): TForm(Owner)
{
Application->OnMessage = DO_OnMessage;
FSelectMark = new TSelectMark(this);
SelectedControl = Panel1;
}
//---------------------------------------------------------------------------
__fastcall TForm1::~TForm1()
{
delete FSelectMark;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormPaint(TObject *Sender)
{
if(FSelectMark)FSelectMark->Draw();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::SetSelectedControl(TControl* Value)
{
if(Value != FSelectedControl){
FSelectMark->Draw();
FSelectedControl = Value;
FSelectMark->Draw();
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::DO_OnMessage(tagMSG &Msg, bool &Handled)
{
TPoint P;
if(Msg.message ==WM_LBUTTONDOWN){
GetCursorPos(&P);
P = ScreenToClient(P);
TControl *N = NULL;
for(int i=0; i if(PtInRect(Controls[i]->BoundsRect, P)){
N = Controls[i];
break;
}
}
Handled = SelectedControl != N;
SelectedControl = N;
}
}
//---------------------------------------------------------------------------
[/code]

===================引 用 harktrip 文 章===================
感恩 ...研究中...

(有沒有BUILDER C 板的)
harktrip
一般會員


發表:30
回覆:30
積分:12
註冊:2007-04-11

發送簡訊給我
#5 引用回覆 回覆 發表時間:2007-12-01 08:19:40 IP:61.221.xxx.xxx 訂閱
我先試試~~~
系統時間:2024-11-26 3:55:56
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!