PowerTools PlusPak for Windows Forms 8.0J
PickColorResult 列挙体
使用例 使用例 

色採取の結果を指定します。
構文
Public Enum PickColorResult 
   Inherits System.Enum
public enum PickColorResult : System.Enum 
メンバ
メンバ解説
Cancel色採取操作がユーザーによってキャンセルされたことを指定します。
OK色採取操作が正常に完了したことを指定します。
解説
この列挙体はEndPickColorEventArgsクラスで使用され、色採取操作が正常に完了したかどうかをユーザーに知らせます。
使用例

次のサンプルコードは、この列挙体の使用方法を示します。この例では、ColorPickerButton.EndPickerColorイベントが発生するとイベントハンドラによってそれが報告されます。イベントハンドラでは、色採取が正常に完了した場合に採取された色をlistBox1に追加しています。

このサンプルコードは、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.ValueType
      System.Enum
         GrapeCity.Win.Common.PickColorResult

プラットフォーム

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

参照

GrapeCity.Win.Common 名前空間
Result プロパティ
Result プロパティ

Send Feedback