ScrollBar.ValueChanged ScrollBar.ValueChanged ScrollBar.ValueChanged ScrollBar.ValueChanged Event

정의

발생 경우 합니다 Value 속성이 변경 될 여를 Scroll 이벤트 또는 프로그래밍 방식으로 합니다.Occurs when the Value property is changed, either by a Scroll event or programmatically.

public:
 event EventHandler ^ ValueChanged;
public event EventHandler ValueChanged;
member this.ValueChanged : EventHandler 
Public Custom Event ValueChanged As EventHandler 

예제

다음 코드 예제에서는 파생된 클래스인 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.

참고

Visual Studio에서이 예제를 실행 하는 방법에 대 한 지침은 방법: 컴파일 및 Visual Studio를 사용 하 여 전체 Windows Forms 코드 예제를 실행합니다.For instructions about how to run this example in Visual Studio, see How to: Compile and Run a Complete Windows Forms Code Example Using Visual Studio.

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

설명

이벤트를 처리 하는 방법에 대 한 자세한 내용은 참조 하세요. 이벤트 처리 및 발생합니다.For more information about how to handle events, see Handling and Raising Events.

적용 대상

추가 정보