リボン関連

複数の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. Excel

    Office 2016で“ヤツ”を召喚してみた。

    4月1日にMicrosoft Office公式アカウント、MSOffi…

  2. リボン関連

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

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

  3. Office関連

    Office 2013のコントロールIDリストが更新されました。

    「コントロールID 一覧(Office 2013)」でも紹介しているO…

  4. リボン関連

    Office Ribbon Editorはウィルス?

    私のHP「Office Ribbon Editorの紹介」でも紹介して…

  5. リボン関連

    PowerShellからリボンUIを呼ぶ方法

    下記記事で簡易的なUIとして手軽なHTAを使いました。…

  6. Office関連

    右クリックから図形の配置 for Office 2013

    HPの掲示板に"右クリックから「配置」を実行できないか?"という質問が…

コメント

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

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

Time limit is exhausted. Please reload CAPTCHA.

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

Translate

最近の記事

アーカイブ

PAGE TOP