請問如何改寫既有元件(以Panel為例) |
尚未結案
|
windheartalan
一般會員 發表:21 回覆:23 積分:8 註冊:2005-03-24 發送簡訊給我 |
不好意思請問各位前輩,
小弟在程式設計的過程中,覺得delphi所提供的元件, 有些如果能稍做修改,會更好用,但不知如何下手, 舉例來說,我希望能夠修改以Tpanel為基礎的元件, 讓滑鼠點到該Panel時,可以於框線加上不同顏色,如紅色,失焦時則框線顏色消失, 而在該panel按滑鼠右鍵時,能在該座標上popup出popupmenu來, 請問上述該如何實作呢? 有辦法做到嗎? 請各位前輩提供個方向,有範例就更好, 自訂元件的設計網路上有看了一些網站,但還是一知半解, 是否有修改視覺化元件資訊較完整的網站呢? 先謝謝前輩的幫忙了. |
inglong
初階會員 發表:28 回覆:27 積分:36 註冊:2004-08-13 發送簡訊給我 |
//開啟一個Package專案檔
//加入下面的MyPanel.pas //Compilier後 install //就可以使用了 //Popupmenu的功能我沒測試 unit MyPanel; interface uses SysUtils, Classes, Controls, Windows, Graphics, Menus, ExtCtrls, Messages; type TMyPanel = class(TPanel) private { Private declarations } procedure MyPaint(IsPaint :Boolean); protected { Protected declarations } procedure DoEnter; override; procedure DoExit; override; procedure Paint;override; procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override; public { Public declarations } constructor Create(AOwner : TComponent);override; destructor Destroy;override; published { Published declarations } end; procedure Register; implementation procedure Register; begin RegisterComponents('Samples', [TMyPanel]); end; { TMyPanel } constructor TMyPanel.Create(AOwner: TComponent); begin inherited; //Self.TabStop := True; end; destructor TMyPanel.destroy; begin inherited; end; procedure TMyPanel.DoEnter; begin inherited; MyPaint(True); //Self.Repaint; end; procedure TMyPanel.DoExit; begin inherited; MyPaint(False); end; procedure TMyPanel.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin inherited; if Self.Focused then begin if (Button = mbRight) then begin if Assigned(Self.PopupMenu) then Self.PopupMenu.Popup(X,Y); end else begin if Assigned(Self.PopupMenu) then Self.PopupMenu.Popup(-100,-100); end; end; MyPaint(True); end; procedure TMyPanel.MyPaint(IsPaint: Boolean); begin if IsPaint then begin Self.Canvas.Pen.Color := clRed; Self.Canvas.Pen.Width := 3; //Canvas.Brush.Style := bsClear; Self.Canvas.MoveTo(0,0); Self.Canvas.LineTo(0,Self.Height); Self.Canvas.MoveTo(0,Self.Height); Self.Canvas.LineTo(Self.Width,Self.Height); Self.Canvas.MoveTo(Self.Width,Self.Height); Self.Canvas.LineTo(Self.Width,0); Self.Canvas.MoveTo(Self.Width,0); Self.Canvas.LineTo(0,0); end else begin Self.Canvas.Pen.Color := Color; Self.Canvas.Pen.Width := 3; //Canvas.Brush.Style := bsClear; Self.Canvas.MoveTo(0,0); Self.Canvas.LineTo(0,Self.Height); Self.Canvas.MoveTo(0,Self.Height); Self.Canvas.LineTo(Self.Width,Self.Height); Self.Canvas.MoveTo(Self.Width,Self.Height); Self.Canvas.LineTo(Self.Width,0); Self.Canvas.MoveTo(Self.Width,0); Self.Canvas.LineTo(0,0); end; end; procedure TMyPanel.Paint; begin inherited; {if Self.Focused then begin MyPaint(True); end; } end; end.
------
何需Coding爭峰 千人指 萬人鋒 敢問Coding頂峰 三尺秋水塵不染 天下無雙
編輯記錄
inglong 重新編輯於 2010-07-20 14:31:32, 註解 無‧
|
hagar
版主 發表:143 回覆:4056 積分:4445 註冊:2002-04-14 發送簡訊給我 |
1.在底下網址中下載 AlPanel v.3.69 這個元件, 含 source
http://www.torry.net/pages.php?s=79 2.TPanel 有個 PopupMenu 的屬性, 指定一個 TPopupMenu 給這個屬性即可 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |