ConvertEventArgs 클래스

정의

FormatParse 이벤트에 대한 데이터를 제공합니다.

public ref class ConvertEventArgs : EventArgs
public class ConvertEventArgs : EventArgs
type ConvertEventArgs = class
    inherit EventArgs
Public Class ConvertEventArgs
Inherits EventArgs
상속
ConvertEventArgs
파생

예제

다음 코드 예제에서는 Binding, 추가 ConvertEventHandler 둘 다에 대리자를 ParseFormat 이벤트를 사용 하 여는 DataBindings 추가할 속성을 BindingBindingsCollectionTextBox 컨트롤입니다. 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 서식을 지정 하 고를 통해 데이터에 바인딩되는 Windows Forms 컨트롤에서 표시 되는 값에 서식을 지정 하거나 해제 하는 데 사용 되는 Binding 개체입니다. 합니다 Format 컨트롤 속성 값에 바인딩되어 때마다 이벤트가 발생 하며 Parse 바인딩된 값이 변경 될 때마다 이벤트가 발생 합니다.

합니다 FormatParse 이벤트를 통해 데이터를 표시 하기 위한 사용자 지정 형식을 만들 수 있습니다. 예를 들어, 테이블의 데이터 형식인 경우 Decimal는 데이터에에서 표시할지 현지 통화 형식으로 설정 하 여 지정할 수 있습니다를 Value 의 속성을 ConvertEventArgs 의 서식이 지정 된 값에 Format 이벤트. 에 표시 된 값을 때는 결과적으로 해야 합니다는 Parse 이벤트입니다.

이벤트 처리에 대한 자세한 내용은 이벤트 처리 및 발생 을 참조하십시오.

생성자

ConvertEventArgs(Object, Type)

ConvertEventArgs 클래스의 새 인스턴스를 초기화합니다.

속성

DesiredType

원하는 값의 데이터 형식을 가져옵니다.

Value

ConvertEventArgs의 값을 가져오거나 설정합니다.

메서드

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

적용 대상

추가 정보