ConvertEventArgsとは? わかりやすく解説

ConvertEventArgs クラス

Format イベントと Parse イベントのデータを提供します。

名前空間: System.Windows.Forms
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)
構文構文

Public Class ConvertEventArgs
    Inherits EventArgs
Dim instance As ConvertEventArgs
public class ConvertEventArgs : EventArgs
public ref class ConvertEventArgs : public
 EventArgs
public class ConvertEventArgs extends EventArgs
public class ConvertEventArgs extends
 EventArgs
解説解説
使用例使用例

Binding を作成し、ConvertEventHandler デリゲートを Parse イベントと Format イベントの両方に追加するコード例を次に示します。さらにこの例では、DataBindings プロパティを使用して、Binding を TextBox コントロールの BindingsCollection に追加します。DecimalToCurrencyString イベント デリゲートは Format イベントに追加され、ToString メソッドを使用して、バインドされた値 (Decimal 型) を通貨として書式設定します。CurrencyStringToDecimal イベント デリゲートは Parse イベントに追加され、コントロールによって表示される値を Decimal 型に変換します。

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 'DecimalToCurrencyString
 
 
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 'CurrencyStringToDecimal
 
 
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 'BindControl
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:
   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.get_DesiredType().Equals(String.class.ToType())))
 {
        return ;
    }
    // Use the ToString method to format the value as currency ("c").
    cevent.set_Value(((System.Decimal)cevent.get_Value()).ToString("c"));
} //DecimalToCurrencyString

private void CurrencyStringToDecimal(Object
 sender, ConvertEventArgs cevent)
{
    // The method converts back to decimal type only. 
    if (!(cevent.get_DesiredType().Equals(System.Decimal.class.ToType())))
 {
        return ;
    }
    // Converts the string back to decimal using the static Parse method.
    cevent.set_Value(Decimal.Parse(cevent.get_Value().ToString(), 
        NumberStyles.Currency, null));
} //CurrencyStringToDecimal

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.add_Format(new ConvertEventHandler(DecimalToCurrencyString));
    b.add_Parse(new ConvertEventHandler(CurrencyStringToDecimal));
    text1.get_DataBindings().Add(b);
} //BindControl
継承階層継承階層
System.Object
   System.EventArgs
    System.Windows.Forms.ConvertEventArgs
       System.Windows.Forms.DataGridViewCellFormattingEventArgs
       System.Windows.Forms.DataGridViewCellParsingEventArgs
       System.Windows.Forms.ListControlConvertEventArgs
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
ConvertEventArgs メンバ
System.Windows.Forms 名前空間
Binding クラス
BindingManagerBase クラス
BindingsCollection クラス
Control.DataBindings プロパティ

ConvertEventArgs コンストラクタ

ConvertEventArgs クラスの新しいインスタンスを初期化します。

名前空間: System.Windows.Forms
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)
構文構文

Public Sub New ( _
    value As Object, _
    desiredType As Type _
)
Dim value As Object
Dim desiredType As Type

Dim instance As New ConvertEventArgs(value,
 desiredType)
public ConvertEventArgs (
    Object value,
    Type desiredType
)
public:
ConvertEventArgs (
    Object^ value, 
    Type^ desiredType
)
public ConvertEventArgs (
    Object value, 
    Type desiredType
)
public function ConvertEventArgs (
    value : Object, 
    desiredType : Type
)

パラメータ

value

現在のプロパティの値を格納する Object。

desiredType

値の Type。

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

ConvertEventArgs プロパティ


パブリック プロパティパブリック プロパティ

  名前 説明
パブリック プロパティ Value ConvertEventArgs の値を取得または設定します。
参照参照

関連項目

ConvertEventArgs クラス
System.Windows.Forms 名前空間
Binding クラス
BindingManagerBase クラス
BindingsCollection クラス
Control.DataBindings プロパティ

ConvertEventArgs メソッド


ConvertEventArgs メンバ

Format イベントと Parse イベントのデータを提供します。

ConvertEventArgs データ型で公開されるメンバを以下の表に示します。


パブリック コンストラクタパブリック コンストラクタ
  名前 説明
パブリック メソッド ConvertEventArgs ConvertEventArgs クラスの新しいインスタンスを初期化します。
パブリック プロパティパブリック プロパティ
  名前 説明
パブリック プロパティ Value ConvertEventArgs の値を取得または設定します。
パブリック メソッドパブリック メソッド
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

ConvertEventArgs クラス
System.Windows.Forms 名前空間
Binding クラス
BindingManagerBase クラス
BindingsCollection クラス
Control.DataBindings プロパティ



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

「ConvertEventArgs」の関連用語

ConvertEventArgsのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



ConvertEventArgsのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS