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

請問 Toolbar 旁邊的">>"功能

尚未結案
pesrty
一般會員


發表:2
回覆:1
積分:0
註冊:2005-03-09

發送簡訊給我
#1 引用回覆 回覆 發表時間:2008-07-11 11:07:40 IP:218.210.xxx.xxx 訂閱
請問一下 Toolbar 旁邊的">>"功能 如何做到
附加檔案:4876ce7c2bca0_2.jpg
編輯記錄
pesrty 重新編輯於 2008-07-11 11:08:41, 註解 無‧
xbx
一般會員


發表:0
回覆:10
積分:12
註冊:2003-08-03

發送簡訊給我
#2 引用回覆 回覆 發表時間:2008-09-18 08:57:26 IP:218.13.xxx.xxx 訂閱
我试过了,但没成功。。。。。
[code delphi]
#171:How can I display the chevron for toolbar and open dropdowned popup menu with invisible buttons?
Hello, today I want to continue the previous tip and describe how to open the popup menu with invisible buttons of toolbar by click in chevron button. Drop the TPopupMenu component on your form and change the Name property to PopupMenuForToolbar. Now we must add the handler for WM_NOTIFY message in declaration of our form:
type 
   TForm1 = class(TForm) 
   private 
     { Private declarations } 
     procedure WMNotify(var Message: TMessage); message WM_NOTIFY; 
   end;
And use the next code as body of handler:
procedure TForm1.WMNotify(var Message: TMessage); 
type 
    PNMREBARCHEVRON = ^TNMREBARCHEVRON; 
    TNMREBARCHEVRON = packed record 
     hdr: TNMHdr; 
     uBand: Integer; 
     wID: Integer; 
     lParam: LPARAM; 
     rc: TRect; 
     lParamNM: LPARAM; 
    end;     const 
   RBN_CHEVRONPUSHED = RBN_FIRST - 10;     var 
   i: Integer; 
   j: Integer; 
   R: TRect; 
   P: TPoint; 
   tb: TToolbar; 
   tbtn: TToolButton; 
   mi: TMenuItem; 
begin 
   inherited;        case PNMHDR(Message.lParam)^.Code of 
     RBN_CHEVRONPUSHED: 
       begin 
         with PNMREBARCHEVRON(Message.lParam)^ do 
         begin 
           tb := yourCoolBar.Bands[uBand].Control as TToolbar; 
           R := tb.ClientRect;                {find first invisible button in toolbar} 
           j := 0; 
           for i := 1 to tb.ButtonCount do 
           begin 
             tbtn := tb.Buttons[i-1]; 
             if (tbtn.Left   tbtn.Width) > R.Right then 
             begin 
               j := i; 
               break; 
             end 
           end;                if j <> 0 then 
           begin 
             {delete all existing items} 
             for i := PopupMenuForToolbar.Items.Count-1 downto 0 do 
             begin 
               mi := PopupMenuForToolbar.Items[i]; 
               PopupMenuForToolbar.Items.Delete(i); 
               mi.Free; 
             end;                  {add all invisible buttons as menu items} 
             for i := j to tb.ButtonCount do 
             begin 
               mi := TMenuItem.Create(Self);                    tbtn := tb.Buttons[i-1]; 
               if (tbtn.Style = tbsSeparator) then 
                 mi.Caption := '-' 
               else 
               begin 
                 mi.Caption := tbtn.Caption; 
                 mi.Hint := tbtn.Hint; 
                 mi.Tag := tbtn.Tag; 
                 mi.OnClick := tbtn.OnClick; 
               end; 
               PopupMenuForToolbar.Items.Add(mi); 
             end;                  {show popup menu} 
             P := tb.ClientToScreen(Point(rc.Left, rc.Bottom)); 
             PopupMenuForToolbar.Popup(P.X 2, P.Y 2); 
           end; 
         end; 
       end; 
   end; 
end;
As you see from comments in code, all what we need is to process the RBN_CHEVRONPUSHED code and add all invisible buttons from toolbar to our popupmenu. It's all - run the project and you'll get nice feature for standard controls with compartibility with future versions of MS Windows. And you don't need pay for third-party components with same functionality. Buy the beer for saved money:-)



[/code]
系統時間:2024-04-26 11:35:15
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!