リボン関連

複数の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. Office関連

    [VBA]CommandBars(“○○”).Controls.Addでメニ…

    Officeのユーザインタフェースがリボンに変わってから、下記のように…

  2. Office関連

    Office XP Developer Toolsでリボン対応のCOMアドインを作成する。

    「Visual Basic 6でリボン対応のアドインを作成する」ではV…

  3. リボン関連

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

    「リボンのトグルボタン」で回答したコードです(下に記載しているコードは…

  4. リボン関連

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

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

コメント

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

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

Time limit is exhausted. Please reload CAPTCHA.

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

Translate

最近の記事

アーカイブ

PAGE TOP