リボン関連

複数のtoggleButton要素の中から1つだけしかオンにできないようにする(2)

複数のtoggleButton要素の中から1つだけしかオンにできないようにする」の関連記事です。

前回はtoggleButton要素getPressed属性を使いましたが、今回はgetEnabled属性を使って有効・無効を切り替えてみます。

[リボンXML]

<?xml version="1.0" encoding="utf-8"?>
<customUI onLoad="tglSample_onLoad" xmlns="http://schemas.microsoft.com/office/2006/01/customui">
  <ribbon>
    <tabs>
      <tab id="tabSample" label="Sample Tab">
        <group id="grpSample" label="Sample Group">
          <toggleButton id="tglSample1" label="tgl1" size="normal" getEnabled="tglSample_getEnabled" onAction="tglSample_onAction" />
          <toggleButton id="tglSample2" label="tgl2" size="normal" getEnabled="tglSample_getEnabled" onAction="tglSample_onAction" />
          <toggleButton id="tglSample3" label="tgl3" size="normal" getEnabled="tglSample_getEnabled" onAction="tglSample_onAction" />
          <toggleButton id="tglSample4" label="tgl4" size="normal" getEnabled="tglSample_getEnabled" onAction="tglSample_onAction" />
          <toggleButton id="tglSample5" label="tgl5" size="normal" getEnabled="tglSample_getEnabled" onAction="tglSample_onAction" />
          <toggleButton id="tglSample6" label="tgl6" size="normal" getEnabled="tglSample_getEnabled" onAction="tglSample_onAction" />
        </group>
      </tab>
    </tabs>
  </ribbon>
</customUI>

[標準モジュール]

Option Explicit

Private myRibbon As IRibbonUI
Private flgTgl As Long

Private Sub tglSample_onLoad(ribbon As IRibbonUI)
  Set myRibbon = ribbon
  flgTgl = 0 '初期化
End Sub

Private Sub tglSample_getEnabled(control As IRibbonControl, ByRef returnedVal)
  Select Case flgTgl
    Case 0
      returnedVal = True
    Case Else
      If Right$(control.ID, 1&) = CStr(flgTgl) Then
        returnedVal = True
      Else
        returnedVal = False
      End If
  End Select
End Sub

Private Sub tglSample_onAction(control As IRibbonControl, pressed As Boolean)
  If pressed Then
    flgTgl = CLng(Right$(control.ID, 1&))
  Else
    flgTgl = 0
  End If
  myRibbon.Invalidate
End Sub

上記コードを設定したファイルを開くと、”Sample Tab“タブとその中に6個のtoggleButton要素が表示されます。

tgl5」をクリックすると、

tgl5」以外のtoggleButton要素が無効になり、もう一度tgl5をクリックしてオフにすると、すべてのtoggleButton要素が有効になります。

複数のtoggleButton要素の中から1つだけしかオンにできないようにする前のページ

Windowsのバージョン情報を取得する次のページ

関連記事

  1. リボン関連

    リボンのコールバック関数の構文集

    今回は、リボンの各要素のonAction属性やgetImage…

  2. リボン関連

    menu内にあるbuttonの数を増やす

    「外部のXMLファイルを読み込み、ユーザー名に応じてmenu内容を変更…

  3. Office関連

    [リボン・カスタマイズ]splitButton要素で大量にある項目を使いやすくまとめる。

    「既存の機能の代わりにマクロを実行する」でコメント(下記)をいただきま…

  4. リボン関連

    続・Office Ribbon Editorがダウンロード出来ない?

    「Office Ribbon Editorがダウンロード出来ない?」で…

  5. Office関連

    既存の機能の代わりにマクロを実行する方法をまとめてみました。

    「既存の機能の代わりにマクロを実行する」の関連になりますが、Offic…

コメント

  1. この記事へのコメントはありません。

  1. この記事へのトラックバックはありません。

Time limit is exhausted. Please reload CAPTCHA.

※本ページはプロモーションが含まれています。

Translate

最近の記事

アーカイブ

PAGE TOP