2012-08-14 74 views
2

我喜歡在may main(MDIParent)窗體上放置一個反饋按鈕,以模擬網頁中的反饋按鈕。模擬網頁反饋按鈕

像鼠標移過去一樣長大。就像網絡一樣。 有問題和發送數據的表單,我真的不需要它,只是視覺的東西。

有沒有這樣的組件? 我不認爲這很難做到,但如果它已經存在,它會讓我有一段時間。

感謝

+0

你能發佈一個鏈接到某個頁面有反饋按鈕嗎?我不是100%確定你的意思...... – TLama 2012-08-14 18:30:51

+0

@TLama問題不在於它是什麼樣子,它只是關於當鼠標移動到另一個元素上時如何顯示浮動面板 – 2012-08-14 18:32:16

+0

@Juan,那麼我可能當鼠標移過它時錯過了*部分,因爲這聽起來像是某種動畫。 – TLama 2012-08-14 18:34:26

回答

5

爲了使動畫幻燈片面板,您可以使用類似的代碼如下:

unit Unit1; 

interface 

uses 
    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 
    Dialogs, StdCtrls, ExtCtrls; 

type 
    TForm1 = class(TForm) 
    procedure FormCreate(Sender: TObject); 
    private 
    FFeedbackBtn: TPanel; 
    FFeedbackPanel: TPanel; 
    procedure OnFeedbackBtnMouseEnter(Sender: TObject); 
    procedure OnFeedbackPanelMouseLeave(Sender: TObject); 
    public 
    { Public declarations } 
    end; 

var 
    Form1: TForm1; 

implementation 

{$R *.dfm} 

procedure TForm1.FormCreate(Sender: TObject); 
begin 
    FFeedbackBtn := TPanel.Create(Self); 
    FFeedbackBtn.Parent := Self; 
    FFeedbackBtn.Anchors := [akLeft, akTop, akBottom]; 
    FFeedbackBtn.Caption := ''; 
    FFeedbackBtn.SetBounds(0, 0, 40, ClientHeight); 
    FFeedbackBtn.OnMouseEnter := OnFeedbackBtnMouseEnter; 

    FFeedbackPanel := TPanel.Create(Self); 
    FFeedbackPanel.Parent := Self; 
    FFeedbackPanel.Anchors := [akLeft, akTop, akBottom]; 
    FFeedbackPanel.Caption := 'Feedback panel'; 
    FFeedbackPanel.Visible := False; 
    FFeedbackPanel.SetBounds(0, 0, 250, ClientHeight); 
    FFeedbackPanel.OnMouseLeave := OnFeedbackPanelMouseLeave; 
end; 

procedure TForm1.OnFeedbackBtnMouseEnter(Sender: TObject); 
begin 
    AnimateWindow(FFeedbackPanel.Handle, 150, AW_ACTIVATE or AW_SLIDE or 
    AW_HOR_POSITIVE); 
end; 

procedure TForm1.OnFeedbackPanelMouseLeave(Sender: TObject); 
begin 
    AnimateWindow(FFeedbackPanel.Handle, 150, AW_HIDE or AW_SLIDE or 
    AW_HOR_NEGATIVE); 
end; 

end. 

更新:

這裏是上面的另一個版本,目前已與像這樣的垂直文字的典型反饋按鈕已經在渲染上的顏料盒上展開了b utton面板:

unit Unit1; 

interface 

uses 
    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 
    Dialogs, StdCtrls, ExtCtrls; 

type 
    TForm1 = class(TForm) 
    procedure FormCreate(Sender: TObject); 
    private 
    FFeedbackBtn: TPanel; 
    FFeedbackBtnOverlay: TPaintBox; 
    FFeedbackPanel: TPanel; 
    procedure OnFeedbackBtnMouseEnter(Sender: TObject); 
    procedure OnFeedbackPanelMouseLeave(Sender: TObject); 
    procedure OnFeedbackBtnOverlayPaint(Sender: TObject); 
    public 
    { Public declarations } 
    end; 

var 
    Form1: TForm1; 

implementation 

{$R *.dfm} 

procedure TForm1.FormCreate(Sender: TObject); 
begin 
    FFeedbackBtn := TPanel.Create(Self); 
    FFeedbackBtn.Parent := Self; 
    FFeedbackBtn.Anchors := [akLeft, akTop, akBottom]; 
    FFeedbackBtn.Caption := ''; 
    FFeedbackBtn.Color := $0000B3FF; 
    FFeedbackBtn.ParentBackground := False; 
    FFeedbackBtn.SetBounds(0, 0, 40, ClientHeight); 

    FFeedbackBtnOverlay := TPaintBox.Create(Self); 
    FFeedbackBtnOverlay.Parent := FFeedbackBtn; 
    FFeedbackBtnOverlay.Align := alClient; 
    FFeedbackBtnOverlay.OnPaint := OnFeedbackBtnOverlayPaint; 
    FFeedbackBtnOverlay.OnMouseEnter := OnFeedbackBtnMouseEnter; 

    FFeedbackPanel := TPanel.Create(Self); 
    FFeedbackPanel.Parent := Self; 
    FFeedbackPanel.Anchors := [akLeft, akTop, akBottom]; 
    FFeedbackPanel.Caption := 'Feedback panel'; 
    FFeedbackPanel.Color := $0000F9FF; 
    FFeedbackPanel.ParentBackground := False; 
    FFeedbackPanel.Visible := False; 
    FFeedbackPanel.SetBounds(0, 0, 250, ClientHeight); 
    FFeedbackPanel.OnMouseLeave := OnFeedbackPanelMouseLeave; 
end; 

procedure TForm1.OnFeedbackBtnMouseEnter(Sender: TObject); 
begin 
    AnimateWindow(FFeedbackPanel.Handle, 150, AW_ACTIVATE or AW_SLIDE or 
    AW_HOR_POSITIVE); 
end; 

procedure TForm1.OnFeedbackPanelMouseLeave(Sender: TObject); 
begin 
    AnimateWindow(FFeedbackPanel.Handle, 150, AW_HIDE or AW_SLIDE or 
    AW_HOR_NEGATIVE); 
end; 

procedure TForm1.OnFeedbackBtnOverlayPaint(Sender: TObject); 
var 
    S: string; 
    X, Y: Integer; 
begin 
    S := 'Feedback...'; 
    with FFeedbackBtnOverlay do 
    begin 
    Canvas.Brush.Color := $0000B3FF; 
    Canvas.FillRect(ClientRect); 
    Canvas.Font.Orientation := 900; 
    X := (ClientWidth - Canvas.TextHeight(S)) div 2; 
    Y := ClientHeight - (ClientHeight - Canvas.TextWidth(S)) div 2; 
    Canvas.TextOut(X, Y, S); 
    end; 
end; 

end. 

而結果:

Result

你也應該執行一些邏輯,以防止用戶隱藏在實際將填充領域的反饋面板,但它是一個天生的弱點這種反饋形式。

+0

是的。瞭解AnimateWindow。謝謝 – Jlouro 2012-08-14 20:59:22

+1

不客氣!但這只是一個猜測。我將擴展這個答案,並嘗試添加一個動畫效果的gif(如果我得到正確的應用程序來做到這一點)。 – TLama 2012-08-14 21:03:19

+3

@TLama - 很有猜測! – 2012-08-14 21:17:09