CommandBar介紹-工具欄_第1頁(yè)
CommandBar介紹-工具欄_第2頁(yè)
CommandBar介紹-工具欄_第3頁(yè)
CommandBar介紹-工具欄_第4頁(yè)
CommandBar介紹-工具欄_第5頁(yè)
已閱讀5頁(yè),還剩2頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、CommandBar 介紹 -工具欄CommandBar 介紹 -工具欄2009 年 2 月 21 日 評(píng)論 發(fā)表評(píng)論接著介紹 CommandBar 的三個(gè)類型之一,工 具欄。工具欄 法,除了需要指定 Name 屬性之外,可以接受其它所有的默 認(rèn)屬性值??梢酝ㄟ^(guò) Position 屬性指定工具欄顯示的位置。創(chuàng)建工具欄很簡(jiǎn)單,直接使用CommandBars 集合的 Add 方Position 屬性的值由 msoBarPosition 常數(shù)指定。msoBarLeft: 0 ,工具欄顯示在工作表左邊msoBarTop: 1 ,工具欄顯示在工作表上邊msoBarRight: 2 ,工具欄顯示在工作表右

2、邊msoBarBottom: 3 ,工具欄顯示在工作表下邊msoBarFloating: 4 ,工具欄浮動(dòng)顯示msoBarMenuBar: 5 ,這個(gè)常數(shù)表示創(chuàng)建菜單欄,不用于創(chuàng)建 工具欄msoBarPopup: 6,這個(gè)常數(shù)表示創(chuàng)建彈出菜單例如下面的代碼創(chuàng)建名稱為 “Custom Toolbar”的位于工作表區(qū)域上邊的工具欄。Set newTool = CommandBars.Add(Name:=Custom Toolbar,Position:=msoBarTop) 創(chuàng)建好 CommandBar 對(duì)象后,可以使用 它的 Controls 集合的 Add 方法添加控件,

3、 也就是工具命令欄??梢酝ㄟ^(guò) Add 方法參數(shù)中的 Type 屬性指定命令欄的類型。Type 屬性由 msoControlType 常數(shù)指定。msoControlButton : 1,普通按鈕類型 msoControlEdit : 2,編輯框類型 msoControlDropdown : 3,復(fù)合框類型,不能輸入新項(xiàng)目 msoControlComboBox :4,和 DropDown 一樣的復(fù)合框類型, 允許輸入新項(xiàng)目msoControlPopup : 10,彈出菜單如果在 Add 方法中指定 ID 屬性的值, 可以創(chuàng)建內(nèi)置命令欄, 例如設(shè)置 id:=3 則創(chuàng)建 “ 保存 R

4、21;命令欄,不需要知道 OnAction 屬性,點(diǎn)擊該命令欄將執(zhí)行默認(rèn)保存命令。還可以設(shè)置命令欄的Style屬性。Style屬性由msoButtonStyle或 msoComboStyle 常數(shù)指定。msoButtonStyle 常數(shù):msoButtonAutomatic : 0,默認(rèn)值,對(duì)于菜單欄,等于 msoButtonIconAndCaption ,對(duì)于工具欄, 等于 msoButtonIcon msoButtonCaption : 2,只顯示標(biāo)題,忽略圖標(biāo) msoButtonIcon : 1,在工具欄上只顯示圖標(biāo),在菜單欄上只顯示標(biāo)題msoButtonIconAndCaption :

5、 3,顯示圖標(biāo),并在圖標(biāo)右邊顯 示標(biāo)題msoButtonIconAndCaptionBelow : 7,對(duì)于菜單欄,等同于 msoButtonIconAndCaption ,對(duì)于工具欄,在圖標(biāo)下方顯示標(biāo)msoButtonWrapCaption :14 ,同 msoButtonCaption 類似,只 是如果標(biāo)題太長(zhǎng)時(shí)分行顯示msoComboStyle 常數(shù):msoComboLabel : 1,左邊有標(biāo)題 msoComboNormal :0,沒(méi)有標(biāo)題 如果命令欄的 Type 屬性設(shè)置為 msoControlComboBox ,該命 令欄可以使用 ComboBox 控件的各種方法和屬性,例如Add

6、Item 方法、 Clear 方法等。如果創(chuàng)建時(shí)設(shè)置了 Caption 屬 性為“請(qǐng)選擇 :” ,則可以使用 Controls(”請(qǐng)選擇:”) 來(lái)表示該復(fù)合框命令欄。例如下面的代碼:With CommandBars(Custom Toolbar).Controls( 請(qǐng)選擇 :)面是一個(gè)創(chuàng)建工具欄的完整例子。Sub CreateToolBar()Dim newTool As CommandBarDim i As Integer 如果發(fā)現(xiàn)有相同工具欄,刪除該工具欄On Error Resume NextCommandBars(Custom Tool

7、bar).DeleteOn Error GoTo 0添加名稱為 “Custom Toolbar” 的工具欄,并在 工作表上方顯示Set newTool = CommandBars.Add(Name:=CustomToolbar, Position:=msoBarTop)With newTool .Visible = TrueWith .Controls.Add(Type:=msoControlButton) .Caption = 復(fù)制 .Style = msoButtonIconAndCaption .TooltipText = 復(fù)制文件 .FaceId = 18 .O

8、nAction = HandleToolEnd WithWith .Controls.Add(Type:=msoControlButton, ID:=3) .Caption = 保存 .BeginGroup = True .Style = msoButtonIconEnd WithWith .Controls.Add(Type:=msoControlEdit) .Caption = 輸入:.BeginGroup = True .Style = msoButtonIcon .TooltipText = 在此輸入數(shù)據(jù) .OnAction = HandleTextEnd WithWith .Cont

9、rols.Add(Type:=msoControlComboBox) .Caption = 請(qǐng)選擇 : .BeginGroup = True .Style = msoComboLabel .TooltipText = 請(qǐng)選擇所需項(xiàng)目 .AddItem Apple .AddItem Banana .AddItem Orange .ListIndex = 1 .OnAction = HandleComboEnd WithEnd WithEnd SubSub ExecuateCombo()With CommandBars(Custom Toolbar).Controls( 請(qǐng)選擇 :)MsgBox

10、.ListCountIf .List(1) = Apple Then .ExecuteEnd IfEnd WithEnd SubSub HandleCombo()Dim sCall As String sCall = CommandBars.ActionControl.TextMsgBox 你選擇了 : & sCall, vbInformationEnd SubSub HandleText()Dim sCall As String sCall = CommandBars.ActionControl.TextMsgBox 你輸入了 : & sCall, vbInformationEnd SubSub HandleTool()Dim sCall As String sCall = CommandBars.ActionControl.CaptionMsgBox 你點(diǎn)擊了 : & sCall, vbInformationEnd SubSub RemoveToolBar()On Error Resume NextCommandBars(Custom Toolbar).DeleteEnd Sub運(yùn)行 CreateToolBar 過(guò)程,將在工作表上方創(chuàng)建一個(gè)自定義工 具欄,如下圖: 示例文

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論