Aracılığıyla paylaş


ConvertEventArgs Sınıf

Tanım

Format ve Parse olayları için veri sağlar.

public ref class ConvertEventArgs : EventArgs
public class ConvertEventArgs : EventArgs
type ConvertEventArgs = class
    inherit EventArgs
Public Class ConvertEventArgs
Inherits EventArgs
Devralma
ConvertEventArgs
Türetilmiş

Örnekler

Aşağıdaki kod örneği, Bindinghem ve Format olaylarına bir ConvertEventHandler temsilci oluşturur hem de Parse özelliğini kullanarak DataBindings öğesini denetimine BindingsCollectionTextBox eklerBinding. Olaya DecimalToCurrencyString eklenen Format olay temsilcisi, ilişkili değeri (bir Decimal tür) para birimi olarak biçimlendirmek için yöntemini kullanırToString. Olaya CurrencyStringToDecimal eklenen Parse olay temsilcisi, denetim tarafından görüntülenen değeri türüne Decimal geri dönüştürür.

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

Açıklamalar

, ConvertEventArgs bir nesne aracılığıyla Binding verilere bağlı bir Windows Forms denetimi tarafından görüntülenen değerleri biçimlendirmek ve biçimlendirmek için kullanılır. Olay Format , bir denetim özelliği bir değere bağlı olduğunda gerçekleşir ve Parse ilişkili değer her değiştiğinde olay gerçekleşir.

Format ve Parse olayları, verileri görüntülemek için özel biçimler oluşturmanıza olanak sağlar. Örneğin, tablodaki veriler türündeyseDecimal, öğesinin özelliğini ConvertEventArgs olaydaki biçimlendirilmiş değere Format ayarlayarak Value verilerin yerel para birimi biçiminde görüntülenmesini belirtebilirsiniz. Sonuç olarak olayda Parse görüntülenen değerin biçimini kaldırmanız gerekir.

Olayları işleme hakkında daha fazla bilgi için bkz . Olayları İşleme ve Oluşturma.

Oluşturucular

Name Description
ConvertEventArgs(Object, Type)

ConvertEventArgs sınıfının yeni bir örneğini başlatır.

Özellikler

Name Description
DesiredType

İstenen değerin veri türünü alır.

Value

değerini ConvertEventArgsalır veya ayarlar.

Yöntemler

Name Description
Equals(Object)

Belirtilen nesnenin geçerli nesneye eşit olup olmadığını belirler.

(Devralındığı yer: Object)
GetHashCode()

Varsayılan karma işlevi işlevi görür.

(Devralındığı yer: Object)
GetType()

Geçerli örneğin Type alır.

(Devralındığı yer: Object)
MemberwiseClone()

Geçerli Objectbasit bir kopyasını oluşturur.

(Devralındığı yer: Object)
ToString()

Geçerli nesneyi temsil eden bir dize döndürür.

(Devralındığı yer: Object)

Şunlara uygulanır

Ayrıca bkz.