ConvertEventArgs クラス
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
public ref class ConvertEventArgs : EventArgs
public class ConvertEventArgs : EventArgs
type ConvertEventArgs = class
inherit EventArgs
Public Class ConvertEventArgs
Inherits EventArgs
- 継承
- 派生
例
次のコード例では、デリゲートをBinding作成し、イベントとFormatイベントの両方にデリゲートをParse追加ConvertEventHandlerし、プロパティをDataBindings使用してコントロールのTextBoxプロパティをBindingsCollection追加Bindingします。 イベントデリゲートは DecimalToCurrencyString 、イベントに Format 追加され、メソッドを ToString 使用して、バインドされた値 (型) を Decimal 通貨として書式設定します。 イベント デリゲートは CurrencyStringToDecimal 、イベントに Parse 追加され、コントロールによって表示される値を型に Decimal 変換します。
private:
void DecimalToCurrencyString( Object^ /*sender*/, ConvertEventArgs^ cevent )
{
// The method converts only to string type. Test this using the DesiredType.
if ( cevent->DesiredType != String::typeid )
{
return;
}
// Use the ToString method to format the value as currency ("c").
cevent->Value = ( (Decimal^)(cevent->Value) )->ToString( "c" );
}
void CurrencyStringToDecimal( Object^ /*sender*/, ConvertEventArgs^ cevent )
{
// The method converts back to decimal type only.
if ( cevent->DesiredType != Decimal::typeid )
{
return;
}
// Converts the string back to decimal using the static Parse method.
cevent->Value = Decimal::Parse( cevent->Value->ToString(),
NumberStyles::Currency, nullptr );
}
void BindControl()
{
// Creates the binding first. The OrderAmount is typed as Decimal.
Binding^ b = gcnew Binding(
"Text",ds,"customers.custToOrders.OrderAmount" );
// Adds the delegates to the events.
b->Format += gcnew ConvertEventHandler(
this, &Form1::DecimalToCurrencyString );
b->Parse += gcnew ConvertEventHandler(
this, &Form1::CurrencyStringToDecimal );
text1->DataBindings->Add( b );
}
private void DecimalToCurrencyString(object sender, ConvertEventArgs cevent)
{
// The method converts only to string type. Test this using the DesiredType.
if(cevent.DesiredType != typeof(string)) return;
// Use the ToString method to format the value as currency ("c").
cevent.Value = ((decimal) cevent.Value).ToString("c");
}
private void CurrencyStringToDecimal(object sender, ConvertEventArgs cevent)
{
// The method converts back to decimal type only.
if(cevent.DesiredType != typeof(decimal)) return;
// Converts the string back to decimal using the static Parse method.
cevent.Value = Decimal.Parse(cevent.Value.ToString(),
NumberStyles.Currency, null);
}
private void BindControl()
{
// Creates the binding first. The OrderAmount is typed as Decimal.
Binding b = new Binding
("Text", ds, "customers.custToOrders.OrderAmount");
// Adds the delegates to the events.
b.Format += new ConvertEventHandler(DecimalToCurrencyString);
b.Parse += new ConvertEventHandler(CurrencyStringToDecimal);
text1.DataBindings.Add(b);
}
Private Sub DecimalToCurrencyString(sender As Object, cevent As ConvertEventArgs)
' The method converts only to string type. Test this using the DesiredType.
If Not cevent.DesiredType Is GetType(String) Then
Return
End If
' Use the ToString method to format the value as currency ("c").
cevent.Value = CDec(cevent.Value).ToString("c")
End Sub
Private Sub CurrencyStringToDecimal(sender As Object, cevent As ConvertEventArgs)
' The method converts back to decimal type only.
If Not cevent.DesiredType Is GetType(Decimal) Then
Return
End If
' Converts the string back to decimal using the shared Parse method.
cevent.Value = Decimal.Parse(cevent.Value.ToString, _
NumberStyles.Currency, nothing)
End Sub
Private Sub BindControl()
' Creates the binding first. The OrderAmount is typed as Decimal.
Dim b As New Binding("Text", ds, "customers.custToOrders.OrderAmount")
' Adds the delegates to the events.
AddHandler b.Format, AddressOf DecimalToCurrencyString
AddHandler b.Parse, AddressOf CurrencyStringToDecimal
text1.DataBindings.Add(b)
End Sub
注釈
オブジェクトConvertEventArgsを介BindingしてデータにバインドされているWindows フォーム コントロールによって表示される値の書式設定と書式設定解除に使用されます。 このイベントは Format 、コントロール プロパティが値にバインドされ、バインドされた値が Parse 変更されるたびにイベントが発生するたびに発生します。
イベント Format を Parse 使用すると、データを表示するためのカスタム形式を作成できます。 たとえば、テーブル内のデータが型Decimalの場合は、イベントの書式設定された値にプロパティConvertEventArgsを設定Valueすることで、データを現地通貨形式でFormat表示するように指定できます。 その結果、イベントに表示される値の書式を解除する Parse 必要があります。
イベントの処理の詳細については、「処理とイベントの発生」を参照してください。
コンストラクター
| ConvertEventArgs(Object, Type) |
ConvertEventArgs クラスの新しいインスタンスを初期化します。 |
プロパティ
| DesiredType |
必要な値のデータ型を取得します。 |
| Value |
ConvertEventArgs の値を取得します。値の設定も可能です。 |
メソッド
| Equals(Object) |
指定されたオブジェクトが現在のオブジェクトと等しいかどうかを判断します。 (継承元 Object) |
| GetHashCode() |
既定のハッシュ関数として機能します。 (継承元 Object) |
| GetType() |
現在のインスタンスの Type を取得します。 (継承元 Object) |
| MemberwiseClone() |
現在の Object の簡易コピーを作成します。 (継承元 Object) |
| ToString() |
現在のオブジェクトを表す文字列を返します。 (継承元 Object) |