PowerTools PlusPak for Windows Forms 8.0J
SideButtonBase クラス
メンバ  使用例 

サイドボタンクラスに共通の基本機能を実装します。
構文
Public Class SideButtonBase 
   Inherits System.ComponentModel.Component
public class SideButtonBase : System.ComponentModel.Component 
解説

SideButtonBaseクラスは、各種サイドボタンクラスの共通機能の実装を提供します。Positionは、サイドボタンを関連付けられたピッカーコントロールのどこに揃えるかを示します。Visibleは、サイドボタンをいつどのように表示するかを決定します。Enabledプロパティを設定してサイドボタンを有効または無効にすることもできます。さらに、各サイドボタンのNameを指定し、ButtonWidthプロパティを使用してサイドボタンの幅を設定できます。BackColorは、サイドボタンの背景色を指定します。FlatAppearanceは、サイドボタンのフラットスタイルがフラットである場合のサイドボタンの外観を指定します。

SideButtonBaseクラスにはClickMouseUpMouseDownPropertyChangedの各イベントが用意されており、これらを使用して独自のイベントハンドラを追加できます。また、Paintイベントにイベントハンドラを関連付けて、必要なものを描画することもできます。

このクラスはインスタンス化できないので、ユーザーがこのクラスから継承して独自のサイドボタンを実装することはできません。

使用例

次のサンプルコードは、SideButtonBaseの派生クラスであるSideButtonを使用して、SideButtonBaseクラスのプロパティとイベントの使用方法を示します。この例では、サイドボタンをクリックすると、listBox1という名前のSystem.Windows.Forms.ListBoxコントロールに新しい項目が追加されます。

このサンプルコードは、GrapeCity.Win.Containers.GcComboFrameクラスの概要に示されている詳細なコード例の一部を抜粋したものです。その元の例では、最初にcomboBox1からSideButton項目を選択してgcComboFrame1にSideButtonを表示できます。次に、gcComboFrame1のテキストエディタにテキストを入力してSideButtonをクリックすると、新しい項目がlistBox1に追加されます。

// Returns a SideButton instance for gcComboFrame1.
private SideButtonBase CreateSideButton()
{
    SideButton sideButton = new SideButton();

    // Specify a unique name for this button.
    sideButton.Name = "SideButton";

    // Set button text.
    sideButton.Text = "Add a item";

    // Set button's width.
    sideButton.ButtonWidth = 70;

    // Set this side button not to show in GcComboFrame.
    sideButton.Visible = ButtonVisibility.NotShown;

    // Set this side button to position at outside of GcComboFrame's right border.
    sideButton.Position = ButtonPosition.RightOutside;

    // Set the fat appearance for this button, and these settings will take effect when 
    // its associated GcComboFrame's FlatStyle is Flat.
    sideButton.FlatAppearance.BorderColor = Color.Red;
    sideButton.FlatAppearance.BorderSize = 2;
    sideButton.FlatAppearance.CheckedBackColor = Color.Blue;
    sideButton.FlatAppearance.MouseDownBackColor = Color.Yellow;
    sideButton.FlatAppearance.MouseOverBackColor = Color.Green;

    sideButton.Click += new EventHandler(SideButton_Click);

    return sideButton;
}

// Add a item into listBox1 when SideButton is clicked.
private void SideButton_Click(object sender, EventArgs e)
{
    if (this.textBox1.Text != string.Empty)
    {
        this.listBox1.Items.Add(this.textBox1.Text);
        this.textBox1.Clear();
    }
    else
    {
        MessageBox.Show("You must input a string first !");
    }
}
' Returns a SideButton instance for gcComboFrame1.
Private Function CreateSideButton() As SideButtonBase
    Dim sideButton As New SideButton()

    ' Specify a unique name for this button.
    sideButton.Name = "SideButton"

    ' Set button text.
    sideButton.Text = "Add a item"

    ' Set button's width.
    sideButton.ButtonWidth = 70

    ' Set this side button not to show in GcComboFrame.
    sideButton.Visible = ButtonVisibility.NotShown

    ' Set this side button to position at outside of GcComboFrame's right border.
    sideButton.Position = ButtonPosition.RightOutside

    ' Set the fat appearance for this button, and these settings will take effect when 
    ' its associated GcComboFrame's FlatStyle is Flat.
    sideButton.FlatAppearance.BorderColor = Color.Red
    sideButton.FlatAppearance.BorderSize = 2
    sideButton.FlatAppearance.CheckedBackColor = Color.Blue
    sideButton.FlatAppearance.MouseDownBackColor = Color.Yellow
    sideButton.FlatAppearance.MouseOverBackColor = Color.Green

    AddHandler sideButton.Click, AddressOf SideButton_Click

    Return sideButton
End Function

' Add a item into listBox1 when SideButton is clicked.
Private Sub SideButton_Click(ByVal sender As Object, ByVal e As EventArgs)
    If Me.textBox1.Text <> String.Empty Then
        Me.listBox1.Items.Add(Me.textBox1.Text)
        Me.textBox1.Clear()
    Else
        MessageBox.Show("You must input a string first !")
    End If
End Sub
継承階層

System.Object
   System.MarshalByRefObject
      System.ComponentModel.Component
         GrapeCity.Win.Common.SideButtonBase
            GrapeCity.Win.Common.ColorPickerButton
            GrapeCity.Win.Common.DropDownButton
            GrapeCity.Win.Common.SideButton
            GrapeCity.Win.Common.SpinButton
            GrapeCity.Win.Common.SymbolButton

プラットフォーム

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

参照

SideButtonBase メンバ
GrapeCity.Win.Common 名前空間
SideButton クラス
SpinButton クラス
SymbolButton クラス
DropDownButton クラス
ColorPickerButton クラス

Send Feedback