作成日: 2020/01/09 最終更新日: 2020/01/09
文書種別
使用方法
詳細
リボングループ上に配置したコンボボックスにリスト項目を追加し、一部の項目のVisibleをFalseに設定してプルダウンすると、ドロップダウンの高さは、その時点の表示項目数に基づいて固定されます。そのため、この後で表示項目のVisible=Trueに変更すると、増えた項目を表示するために縦スクロールバーが表示されます。
この動作を避け、実際の表示項目数に合わせてドロップダウンの高さが自動調整されるようにするには、コンボボックスコントロールのVisibleをいったんFalse→Trueと設定し直した後、リスト項目のVisibleを変更します。
以下に、コンボボックスに表示するリスト項目を2個から3個に変更する例を記載します。
◎サンプルコード(VB)
この動作を避け、実際の表示項目数に合わせてドロップダウンの高さが自動調整されるようにするには、コンボボックスコントロールのVisibleをいったんFalse→Trueと設定し直した後、リスト項目のVisibleを変更します。
以下に、コンボボックスに表示するリスト項目を2個から3個に変更する例を記載します。
◎サンプルコード(VB)
Imports C1.Win.Ribbon
Public Class Form1
Dim RibbonComboBox1 As RibbonComboBox
Dim RibbonButton1, RibbonButton2, RibbonButton3, RibbonButton4, RibbonButton5 As RibbonButton
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
' リボングループにComboBoxを追加し、その項目としてRibbonButtonを設定
RibbonComboBox1 = New RibbonComboBox()
RibbonComboBox1.Label = "コンボボックス"
RibbonComboBox1.TextAreaWidth = 100
RibbonButton1 = New RibbonButton("ボタン1")
RibbonButton2 = New RibbonButton("ボタン2")
RibbonButton3 = New RibbonButton("ボタン3")
RibbonButton4 = New RibbonButton("ボタン4")
RibbonButton5 = New RibbonButton("ボタン5")
RibbonComboBox1.Items.Add(RibbonButton1)
RibbonComboBox1.Items.Add(RibbonButton2)
RibbonComboBox1.Items.Add(RibbonButton3)
RibbonComboBox1.Items.Add(RibbonButton4)
RibbonComboBox1.Items.Add(RibbonButton5)
RibbonGroup1.Items.Add(RibbonComboBox1)
' コンボボックスの3項目以降を非表示に設定
RibbonComboBox1.Items(2).Visible = False
RibbonComboBox1.Items(3).Visible = False
RibbonComboBox1.Items(4).Visible = False
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
' コンボボックスの表示を内部的に更新
RibbonComboBox1.Visible = False
RibbonComboBox1.Visible = True
' コンボボックス項目のVisibleを変更
RibbonComboBox1.Items(0).Visible = Not RibbonComboBox1.Items(0).Visible
RibbonComboBox1.Items(1).Visible = Not RibbonComboBox1.Items(1).Visible
RibbonComboBox1.Items(2).Visible = Not RibbonComboBox1.Items(2).Visible
RibbonComboBox1.Items(3).Visible = Not RibbonComboBox1.Items(3).Visible
RibbonComboBox1.Items(4).Visible = Not RibbonComboBox1.Items(4).Visible
End Sub
End Class
◎サンプルコード(C#)using C1.Win.Ribbon;
namespace prj_Ribbon_DropDown
{
public partial class Form1 : Form
{
RibbonComboBox ribbonComboBox1;
RibbonButton ribbonButton1, ribbonButton2, ribbonButton3, ribbonButton4, ribbonButton5;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// リボングループにComboBoxを追加し、その項目としてRibbonButtonを設定
ribbonComboBox1 = new RibbonComboBox();
ribbonComboBox1.Label = "コンボボックス";
ribbonComboBox1.TextAreaWidth = 100;
ribbonButton1 = new RibbonButton("ボタン1");
ribbonButton2 = new RibbonButton("ボタン2");
ribbonButton3 = new RibbonButton("ボタン3");
ribbonButton4 = new RibbonButton("ボタン4");
ribbonButton5 = new RibbonButton("ボタン5");
ribbonComboBox1.Items.Add(ribbonButton1);
ribbonComboBox1.Items.Add(ribbonButton2);
ribbonComboBox1.Items.Add(ribbonButton3);
ribbonComboBox1.Items.Add(ribbonButton4);
ribbonComboBox1.Items.Add(ribbonButton5);
ribbonGroup1.Items.Add(ribbonComboBox1);
// コンボボックスの3項目以降を非表示に設定
ribbonComboBox1.Items[2].Visible = false;
ribbonComboBox1.Items[3].Visible = false;
ribbonComboBox1.Items[4].Visible = false;
}
private void button1_Click(object sender, EventArgs e)
{
// コンボボックスの表示を内部的に更新
ribbonComboBox1.Visible = false;
ribbonComboBox1.Visible = true;
// コンボボックス項目のVisibleを変更
ribbonComboBox1.Items[0].Visible = !ribbonComboBox1.Items[0].Visible;
ribbonComboBox1.Items[1].Visible = !ribbonComboBox1.Items[1].Visible;
ribbonComboBox1.Items[2].Visible = !ribbonComboBox1.Items[2].Visible;
ribbonComboBox1.Items[3].Visible = !ribbonComboBox1.Items[3].Visible;
ribbonComboBox1.Items[4].Visible = !ribbonComboBox1.Items[4].Visible;
}
}
}
旧文書番号
84831