ScrollBar.OnScroll(ScrollEventArgs) ScrollBar.OnScroll(ScrollEventArgs) ScrollBar.OnScroll(ScrollEventArgs) ScrollBar.OnScroll(ScrollEventArgs) Method

정의

Scroll 이벤트를 발생시킵니다.Raises the Scroll event.

protected:
 virtual void OnScroll(System::Windows::Forms::ScrollEventArgs ^ se);
protected virtual void OnScroll (System.Windows.Forms.ScrollEventArgs se);
abstract member OnScroll : System.Windows.Forms.ScrollEventArgs -> unit
override this.OnScroll : System.Windows.Forms.ScrollEventArgs -> unit
Protected Overridable Sub OnScroll (se As ScrollEventArgs)

매개 변수

se
ScrollEventArgs ScrollEventArgs ScrollEventArgs ScrollEventArgs

이벤트 데이터를 포함하는 ScrollEventArgs입니다.A ScrollEventArgs that contains the event data.

예제

다음 코드 예제에서는 파생된 클래스인 VScrollBar합니다.The following code example uses the derived class VScrollBar. 에 대 한 이벤트 처리기를 ScrollValueChanged 이벤트가 만들어집니다.Event handlers for the Scroll and ValueChanged events are created. 가정이 코드를 LabelButton 폼에서 생성 된, 그리고 단추에 대 한 이벤트 처리기는 Click 이벤트.This code assumes that a Label and Button have been created on a form and that the button has an event handler for the Click event. 단추를 클릭할 때는 Value 코드 조정 하는 스크롤 막대의 속성입니다.When the button is clicked, the Value property of the scroll bar is adjusted in code. 레이블을의 현재 값이 표시 됩니다는 Value 속성을 변경 하는 이벤트입니다.The label will display the current value of the Value property and the event that changed it. 단추의가 스크롤 값을 변경할 때 점을 확인할 수 있습니다 Click 이벤트에만 ValueChanged 이벤트가 발생 합니다.You will notice that when the scroll value is changed by the button's Click event, only the ValueChanged event is raised. 반면 때 스크롤 막대를 수동으로 스크롤하면를 Scroll 직후 이벤트가 발생 합니다 ValueChanged 이벤트입니다.In contrast, when the scroll bar is scrolled manually, the Scroll event is raised immediately after the ValueChanged event.

void AddMyScrollEventHandlers()
{
   // Create and initialize a VScrollBar.
   VScrollBar^ vScrollBar1 = gcnew VScrollBar;

   // Add event handlers for the OnScroll and OnValueChanged events.
   vScrollBar1->Scroll += gcnew ScrollEventHandler( this, &Form1::vScrollBar1_Scroll );
   vScrollBar1->ValueChanged += gcnew EventHandler( this, &Form1::vScrollBar1_ValueChanged );
}

// Create the ValueChanged event handler.
void vScrollBar1_ValueChanged( Object^ /*sender*/, EventArgs^ /*e*/ )
{
   // Display the new value in the label.
   label1->Text = String::Format( "vScrollBar Value:(OnValueChanged Event) {0}", vScrollBar1->Value );
}

// Create the Scroll event handler.
void vScrollBar1_Scroll( Object^ /*sender*/, ScrollEventArgs^ e )
{
   // Display the new value in the label.
   label1->Text = String::Format( "VScrollBar Value:(OnScroll Event) {0}", e->NewValue );
}

void button1_Click( Object^ /*sender*/, EventArgs^ /*e*/ )
{
   // Add 40 to the Value property if it will not exceed the Maximum value.
   if ( vScrollBar1->Value + 40 < vScrollBar1->Maximum )
   {
      vScrollBar1->Value = vScrollBar1->Value + 40;
   }
}
private void AddMyScrollEventHandlers()
 {
    // Create and initialize a VScrollBar.
    VScrollBar vScrollBar1 = new VScrollBar();
 
    // Add event handlers for the OnScroll and OnValueChanged events.
    vScrollBar1.Scroll += new ScrollEventHandler(
       this.vScrollBar1_Scroll);
    vScrollBar1.ValueChanged += new EventHandler(
       this.vScrollBar1_ValueChanged); 
 }
 
 // Create the ValueChanged event handler.
 private void vScrollBar1_ValueChanged(Object sender, 
                                       EventArgs e)
 {
     // Display the new value in the label.
     label1.Text = "vScrollBar Value:(OnValueChanged Event) " + vScrollBar1.Value.ToString();
 }
 
 // Create the Scroll event handler.
 private void vScrollBar1_Scroll(Object sender, 
                                 ScrollEventArgs e)
 {
     // Display the new value in the label.
     label1.Text = "VScrollBar Value:(OnScroll Event) " + e.NewValue.ToString();
 }
 
 private void button1_Click(Object sender, 
                           EventArgs e)
 {
    // Add 40 to the Value property if it will not exceed the Maximum value.
    if (vScrollBar1.Value + 40 < vScrollBar1.Maximum)
    {
        vScrollBar1.Value = vScrollBar1.Value + 40;
    }
 }
 
Private Sub AddMyScrollEventHandlers()
    ' Create and initialize a VScrollBar.
    Dim vScrollBar1 As New VScrollBar()
    
    ' Add event handlers for the OnScroll and OnValueChanged events.
    AddHandler vScrollBar1.Scroll, AddressOf Me.vScrollBar1_Scroll
    AddHandler vScrollBar1.ValueChanged, AddressOf Me.vScrollBar1_ValueChanged
End Sub    

' Create the ValueChanged event handler.
Private Sub vScrollBar1_ValueChanged(sender As Object, e As EventArgs)
    ' Display the new value in the label.
    label1.Text = "vScrollBar Value:(OnValueChanged Event) " & _
        vScrollBar1.Value.ToString()
End Sub    

' Create the Scroll event handler.
Private Sub vScrollBar1_Scroll(sender As Object, e As ScrollEventArgs)
    ' Display the new value in the label.
    label1.Text = "VScrollBar Value:(OnScroll Event) " & _
        e.NewValue.ToString()
End Sub    

Private Sub button1_Click(sender As Object, e As EventArgs)
    ' Add 40 to the Value property if it will not exceed the Maximum value.
    If vScrollBar1.Value + 40 < vScrollBar1.Maximum Then
        vScrollBar1.Value = vScrollBar1.Value + 40
    End If
End Sub

설명

이벤트가 발생하면 대리자를 통해 이벤트 처리기가 호출됩니다.Raising an event invokes the event handler through a delegate. 자세한 내용은 이벤트 처리 및 발생합니다.For more information, see Handling and Raising Events.

또한 OnScroll 메서드를 사용하면 파생 클래스가 대리자를 연결하지 않고도 이벤트를 처리할 수 있습니다.The OnScroll method also allows derived classes to handle the event without attaching a delegate. 이는 파생 클래스에서 이벤트를 처리하는 기본 방법입니다.This is the preferred technique for handling the event in a derived class.

상속자 참고

재정의 하는 경우 OnScroll(ScrollEventArgs) 파생된 클래스에서 호출 해야 기본 클래스 OnScroll(ScrollEventArgs) 메서드 등록 된 대리자가 이벤트를 받도록 합니다.When overriding OnScroll(ScrollEventArgs) in a derived class, be sure to call the base class' OnScroll(ScrollEventArgs) method so that registered delegates receive the event.

적용 대상

추가 정보