PowerTools MultiRow for Windows Forms 8.0J
OnClick メソッド (DropDownItem)
使用例 

イベントデータを含むSystem.EventArgsインスタンス。
Clickイベントを発生させます。
構文
Protected Overridable Sub OnClick( _
   ByVal e As EventArgs _
) 
protected virtual void OnClick( 
   EventArgs e
)

パラメータ

e
イベントデータを含むSystem.EventArgsインスタンス。
使用例
次のサンプルコードは、このメソッドを使用してドロップダウン項目のクリックロジックをカスタマイズする方法を示します。このサンプルコードは、DropDownListプロパティに示されている詳細なコード例の一部を抜粋したものです。
public class PopupFilterItem : DropDownCustomFilterItem
{
    public override string Text
    {
        get
        {
            if (this.Checked)
            {
                return min.ToString() + " to " + max.ToString();
            }
            return "(Custom)";
        }
        set { }
    }

    int max = -1;
    int min = -1;

    protected override bool Check(object value)
    {
        // check the value whether in specific range.
        int checkedValue = int.Parse(value.ToString());

        return (checkedValue >= min && checkedValue <= max);
    }

    protected override void OnClick(EventArgs e)
    {
        // Initialize pop up form.
        Form form = new Form();

        FlowLayoutPanel panel = new FlowLayoutPanel();
        panel.Height = form.Height;

        Label label1 = new Label();
        label1.Text = "Min Value:";

        Label label2 = new Label();
        label2.Text = "MaxValue:";

        NumericUpDown numericUpDown1 = new NumericUpDown();

        NumericUpDown numericUpDown2 = new NumericUpDown();
        numericUpDown2.Maximum = 1000;
        numericUpDown2.Value = 50;

        Button okButton = new Button();
        okButton.Text = "OK";
        okButton.DialogResult = DialogResult.OK;
        form.AcceptButton = okButton;

        form.Controls.Add(panel);
        panel.Controls.Add(label1);
        panel.Controls.Add(numericUpDown1);
        panel.Controls.Add(label2);
        panel.Controls.Add(numericUpDown2);
        panel.Controls.Add(okButton);

        DialogResult result = form.ShowDialog();

        // If input a range and click OK button. Update range.
        if (result == DialogResult.OK)
        {
            min = (int)(numericUpDown1.Value);
            max = (int)(numericUpDown2.Value);
        }
        else
        {
            min = int.MinValue;
            max = int.MaxValue;
        }

        base.OnClick(e);
    }
}
Public Class PopupFilterItem
    Inherits DropDownCustomFilterItem
    Public Overloads Overrides Property Text() As String
        Get
            If Me.Checked Then
                Return min.ToString() + " to " + max.ToString()
            End If
            Return "(Custom)"
        End Get
        Set(ByVal value As String)
        End Set
    End Property

    Private max As Integer = -1
    Private min As Integer = -1

    Protected Overloads Overrides Function Check(ByVal value As Object) As Boolean
        ' check the value whether in specific range.
        Dim checkedValue As Integer = Integer.Parse(value.ToString())

        Return (checkedValue >= min AndAlso checkedValue <= max)
    End Function

    Protected Overloads Overrides Sub OnClick(ByVal e As EventArgs)
        ' Initialize pop up form.
        Dim form As New Form()

        Dim panel As New FlowLayoutPanel()
        panel.Height = form.Height

        Dim label1 As New Label()
        label1.Text = "Min Value:"

        Dim label2 As New Label()
        label2.Text = "MaxValue:"

        Dim numericUpDown1 As New NumericUpDown()

        Dim numericUpDown2 As New NumericUpDown()
        numericUpDown2.Maximum = 1000
        numericUpDown2.Value = 50

        Dim okButton As New Button()
        okButton.Text = "OK"
        okButton.DialogResult = DialogResult.OK
        form.AcceptButton = okButton

        form.Controls.Add(panel)
        panel.Controls.Add(label1)
        panel.Controls.Add(numericUpDown1)
        panel.Controls.Add(label2)
        panel.Controls.Add(numericUpDown2)
        panel.Controls.Add(okButton)

        Dim result As DialogResult = form.ShowDialog()

        ' If input a range and click OK button. Update range.
        If result = DialogResult.OK Then
            min = CInt(numericUpDown1.Value)
            max = CInt(numericUpDown2.Value)
        Else
            min = Integer.MinValue
            max = Integer.MaxValue
        End If

        MyBase.OnClick(e)
    End Sub
End Class
参照

DropDownItem クラス
DropDownItem メンバ

 

 


© 2008-2015 GrapeCity inc. All rights reserved.