مشاركة عبر


تعريف أحداث في نماذج Windows عناصر التحكم

للحصول على التفاصيل حول تعريف مخصص الأحداث، راجع رفع حدث. إذا قمت بتعريف حدث ما لم يكن أية بيانات مقترنة استخدم نوع قاعدة بيانات الأحداث, EventArgs، و استخدم EventHandlerكمفوض الحدث. يبقى كل إلى هل هو إلى تعريف أعضاء بحدث وعلى محمية OnEventName الطريقة التي رفع حدث.

يلي تعليمات برمجية قم بتقسيم يبين كيفية FlashTrackBarتعريف عنصر تحكم مخصص حدث مخصص، ValueChanged. لكاملة تعليمات برمجية ل FlashTrackBarنموذج، انظر كيفية القيام بما يلي: إنشاء عنصر تحكم Windows Forms الذي يعرض التقدم.

Option Explicit
Option Strict

Imports System
Imports System.Windows.Forms
Imports System.Drawing

Public Class FlashTrackBar
   Inherits Control
   
   ' The event does not have any data, so EventHandler is adequate 
   ' as the event delegate.        
   ' Define the event member using the event keyword.
   ' In this case, for efficiency, the event is defined 
   ' using the event property construct.
   Public Event ValueChanged As EventHandler
   ' The protected method that raises the ValueChanged 
   ' event when the value has actually 
   ' changed. Derived controls can override this method.  
   Protected Overridable Sub OnValueChanged(e As EventArgs)
      RaiseEvent ValueChanged(Me, e)
   End Sub
End Class
using System;
using System.Windows.Forms;
using System.Drawing;

public class FlashTrackBar : Control {
   // The event does not have any data, so EventHandler is adequate 
   // as the event delegate.
   private EventHandler onValueChanged;
   // Define the event member using the event keyword.
   // In this case, for efficiency, the event is defined 
   // using the event property construct.
   public event EventHandler ValueChanged {
            add {
                onValueChanged += value;
            }
            remove {
                onValueChanged -= value;
            }
        }
   // The protected method that raises the ValueChanged
   // event when the value has actually 
   // changed. Derived controls can override this method.  
   protected virtual void OnValueChanged(EventArgs e) {
      if (ValueChanged != null) {
         ValueChanged(this, e);
      }
   }
}

راجع أيضًا:

المبادئ

الأحداث في عناصر التحكم Windows Forms

رفع حدث

موارد أخرى

معالجة و إظهار الأحداث