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

ピッカーコントロールに表示されるピッカーボタンを表します。
構文
Public Class ColorPickerButton 
   Inherits SideButtonBase
public class ColorPickerButton : SideButtonBase 
解説
ColorPickerButtonはピッカーコントロールのサイドボタンの1つです。ColorPickerButton.IsDefaultBehaviorプロパティがtrueの場合、このボタンを使用して画面から色を採取できます。
使用例

次のサンプルコードは、ColorPickerButtonを作成し、ボタンの一般的なプロパティを設定して、色の採取に関連付けられたイベントを処理します。この例では、色の採取中にColorPickerButtonSideButtonBase.BackColorImageが変更され、採取操作が終わると元の値に戻ります。

このサンプルコードは、GrapeCity.Win.Containers.GcComboFrameクラスの概要に示されている詳細なコード例の一部を抜粋したものです。その元の例では、最初にcomboBox1からColorPickerButton項目を選択してgcComboFrame1にColorPickerButtonを表示し、次にColorPickerButtonを使用して画面から色を採取できます。

// Use this field to record the image of ColorPickerButton during picking color.
private Image colorPickerImage = null;

// Returns a ColorPickerButton instance for gcComboFrame1.
private SideButtonBase CreateColorPickerButton()
{
    ColorPickerButton colorPickerButton = new ColorPickerButton();

    // Specify a unique name for this button.
    colorPickerButton.Name = "ColorPickerButton";

    // Set this button not be shown.
    colorPickerButton.Visible = ButtonVisibility.NotShown;

    // Set button's position
    colorPickerButton.Position = ButtonPosition.RightOutside;

    // Set button's width.
    colorPickerButton.ButtonWidth = 25;

    // Add event handlers for the events of this button.
    colorPickerButton.BeginPickColor += new EventHandler(ColorPickerButton_BeginPickColor);
    colorPickerButton.PickingColor += new EventHandler<PickingColorEventArgs>(ColorPickerButton_PickingColor);
    colorPickerButton.EndPickColor += new EventHandler<EndPickColorEventArgs>(ColorPickerButton_EndPickColor);

    return colorPickerButton;
}

private void ColorPickerButton_BeginPickColor(object sender, EventArgs e)
{
    // Clear the text of textBox1.
    this.textBox1.Clear();

    // Record the original image and set the Image property to null.
    ColorPickerButton colorPickerButton = sender as ColorPickerButton;
    colorPickerImage = colorPickerButton.Image;
    colorPickerButton.Image = null;
}

private void ColorPickerButton_PickingColor(object sender, PickingColorEventArgs e)
{
    // Set textBox1's Text property to the picking color.
    this.textBox1.Text = e.Color.ToString();

    // Set ColorPickerButton's background color to the picking color.
    (sender as ColorPickerButton).BackColor = e.Color;
}

private void ColorPickerButton_EndPickColor(object sender, EndPickColorEventArgs e)
{
    // Add the color into listBox1 if the picking of color is succussful.
    if (PickColorResult.OK == e.Result)
    {
        DialogResult result = MessageBox.Show("Do you want to add the color into list box ?", "Picking color successful", MessageBoxButtons.YesNo);
        if (DialogResult.Yes == result)
        {
            this.listBox1.Items.Add(e.Color.ToString());
        }
    }

    // Clear the text.
    this.textBox1.Clear();

    // Restore the displaying image of ColorPickerButton.
    ColorPickerButton colorPickerButton = sender as ColorPickerButton;
    colorPickerButton.Image = colorPickerImage;

    // Restore the background color of ColorPickerButton.
    colorPickerButton.BackColor = Color.Empty;
    colorPickerButton.UseVisualStyleBackColor = true;
}
' Use this field to record the image of ColorPickerButton during picking color.
Private colorPickerImage As Image = Nothing

' Returns a ColorPickerButton instance for gcComboFrame1.
Private Function CreateColorPickerButton() As SideButtonBase
    Dim colorPickerButton As New ColorPickerButton()

    ' Specify a unique name for this button.
    colorPickerButton.Name = "ColorPickerButton"

    ' Set this button not be shown.
    colorPickerButton.Visible = ButtonVisibility.NotShown

    ' Set button's position
    colorPickerButton.Position = ButtonPosition.RightOutside

    ' Set button's width.
    colorPickerButton.ButtonWidth = 25

    ' Add event handlers for the events of this button.
    AddHandler colorPickerButton.BeginPickColor, AddressOf ColorPickerButton_BeginPickColor
    AddHandler colorPickerButton.PickingColor, AddressOf ColorPickerButton_PickingColor
    AddHandler colorPickerButton.EndPickColor, AddressOf ColorPickerButton_EndPickColor

    Return colorPickerButton
End Function

Private Sub ColorPickerButton_BeginPickColor(ByVal sender As Object, ByVal e As EventArgs)
    ' Clear the text of textBox1.
    Me.textBox1.Clear()

    ' Record the original image and set the Image property to null.
    Dim colorPickerButton As ColorPickerButton = TryCast(sender, ColorPickerButton)
    colorPickerImage = colorPickerButton.Image
    colorPickerButton.Image = Nothing
End Sub

Private Sub ColorPickerButton_PickingColor(ByVal sender As Object, ByVal e As PickingColorEventArgs)
    ' Set textBox1's Text property to the picking color.
    Me.textBox1.Text = e.Color.ToString()

    ' Set ColorPickerButton's background color to the picking color.
    TryCast(sender, ColorPickerButton).BackColor = e.Color
End Sub

Private Sub ColorPickerButton_EndPickColor(ByVal sender As Object, ByVal e As EndPickColorEventArgs)
    ' Add the color into listBox1 if the picking of color is succussful.
    If PickColorResult.OK = e.Result Then
        Dim result As DialogResult = MessageBox.Show("Do you want to add the color into list box ?", "Picking color successful", MessageBoxButtons.YesNo)
        If DialogResult.Yes = result Then
            Me.listBox1.Items.Add(e.Color.ToString())
        End If
    End If

    ' Clear the text.
    Me.textBox1.Clear()

    ' Restore the displaying image of ColorPickerButton.
    Dim colorPickerButton As ColorPickerButton = TryCast(sender, ColorPickerButton)
    colorPickerButton.Image = colorPickerImage

    ' Restore the background color of ColorPickerButton.
    colorPickerButton.BackColor = Color.Empty
    colorPickerButton.UseVisualStyleBackColor = True
End Sub
継承階層

System.Object
   System.MarshalByRefObject
      System.ComponentModel.Component
         GrapeCity.Win.Common.SideButtonBase
            GrapeCity.Win.Common.ColorPickerButton

プラットフォーム

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

参照

ColorPickerButton メンバ
GrapeCity.Win.Common 名前空間

Send Feedback