ConvertEventHandler デリゲートとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > ConvertEventHandler デリゲートの意味・解説 

ConvertEventHandler デリゲート

Binding の Parse イベントおよび Format イベント処理するメソッド表します

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

Public Delegate Sub ConvertEventHandler
 ( _
    sender As Object, _
    e As ConvertEventArgs _
)
Dim instance As New ConvertEventHandler(AddressOf
 HandlerMethod)
public delegate void ConvertEventHandler (
    Object sender,
    ConvertEventArgs e
)
public delegate void ConvertEventHandler (
    Object^ sender, 
    ConvertEventArgs^ e
)
/** @delegate */
public delegate void ConvertEventHandler (
    Object sender, 
    ConvertEventArgs e
)
JScript では、デリゲート使用できますが、新規に宣言することはできません。

パラメータ

sender

イベントソース

e

イベント データ格納している ConvertEventArgs。

解説解説
使用例使用例

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

Private Sub DecimalToCurrency(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 CurrencyToDecimal(sender As
 Object, cevent As ConvertEventArgs)
    ' The method converts only to decimal type. 
    If Not cevent.DesiredType Is
 GetType(Decimal) Then
        Return
    End If 
    ' Converts the string back to decimal using the static ToDecimal
 method.
    cevent.Value = Convert.ToDecimal(cevent.Value.ToString())
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 DecimalToCurrency
    AddHandler b.Parse, AddressOf CurrencyToDecimal
    text1.DataBindings.Add(b)
End Sub 
private void DecimalToCurrency(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 CurrencyToDecimal(object sender,
 ConvertEventArgs cevent)
{
   // ' The method converts only to decimal type. 
   if (cevent.DesiredType != typeof(decimal)) return;

   // Converts the string back to decimal using the static ToDecimal
 method.
   cevent.Value = Convert.ToDecimal(cevent.Value.ToString());
}

private void BindControl()
{
   // Creates the binding first. The OrderAmount is typed as Decimal.
   Binding b = new Binding
      ("Text", ds, "customers.custToOrders.OrderAmount");
   // Add the delegates to the events.
   b.Format += new ConvertEventHandler(DecimalToCurrency);
   b.Parse += new ConvertEventHandler(CurrencyToDecimal);
   text1.DataBindings.Add(b);
}

private:
   void DecimalToCurrency( 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 CurrencyToDecimal( Object^ /*sender*/, ConvertEventArgs^
 cevent )
   {
      // ' The method converts only to decimal type. 
      if ( cevent->DesiredType != Decimal::typeid )
      {
         return;
      }

      // Converts the string back to decimal using the static ToDecimal
 method.
      cevent->Value = Convert::ToDecimal( cevent->Value->ToString() );
   }

   void BindControl()
   {
      // Creates the binding first. The OrderAmount is typed as Decimal.
      Binding^ b = gcnew Binding(
         "Text",ds,"customers.custToOrders.OrderAmount" );
      
      // Add the delegates to the events.
      b->Format += gcnew ConvertEventHandler(
         this, &Form1::DecimalToCurrency );
      b->Parse += gcnew ConvertEventHandler(
         this, &Form1::CurrencyToDecimal );
      text1->DataBindings->Add( b );
   }
private void DecimalToCurrency(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"));
} //DecimalToCurrency

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

private void BindControl()
{
    // Creates the binding first. The OrderAmount is typed as Decimal.
    Binding b = new Binding("Text", ds, 
        "customers.custToOrders.OrderAmount");
    // Add the delegates to the events.
    b.add_Format(new ConvertEventHandler(DecimalToCurrency));
    b.add_Parse(new ConvertEventHandler(CurrencyToDecimal));
    text1.get_DataBindings().Add(b);
} //BindControl
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照


このページでは「.NET Framework クラス ライブラリ リファレンス」からConvertEventHandler デリゲートを検索した結果を表示しています。
Weblioに収録されているすべての辞書からConvertEventHandler デリゲートを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からConvertEventHandler デリゲート を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「ConvertEventHandler デリゲート」の関連用語

ConvertEventHandler デリゲートのお隣キーワード
検索ランキング

   

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



ConvertEventHandler デリゲートのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2025 GRAS Group, Inc.RSS