Hscrollbar is a horizontal scroll bar. Similar to vscrollbar, it is often used in Windows that do not have built-in support for page flip scrolling. However, it is not easy to reasonably control the use of hscrollbar. Hscroollbar has two events: hscrollbar1_scroll and hscrollbar1_valuechanged. There is a general generalization of the time to use these two events: Processing during the moving process is placed in the _ scroll event, and processing after moving is placed in the _ valuechanged event. This sentence is too general and not accurate to meet actual needs.
1. hscrollbar1_valuechanged (objectsender, eventargs e) event
This event is triggered when the value of hscrollbar1.value is changed. There are two ways to trigger the hscrollbar1_scroll event: A. Click and drag the scroll bar to trigger the hscrollbar1.value event. B. directly set the value of hscrollbar1.value, for example, hscrollbar1.value = 27.
2. hscrollbar1_scroll (objectsender, scrolleventargs e) event
The hscrollbar1_scroll event is triggered when you click the left and right arrows, flip pages, and drag the scroll bar. Note the attributes of the parameter E.
A> E. scrollorientation: Obtain the scroll rolling direction;
B> E. oldvalue obtains the old hscrollbar1.value value;
C> E. newvalue: obtain or set a new hscrollbar1.value;
D> E. type to obtain the type of a rolling event.
Public Enum scrolleventtype // E. Type
{
Smalldecrement = 0, // line feed, value changes the smallchange volume
Smallincrement = 1, // line feed, value changes the smallchange volume
Largedecrement = 2, // page flip, value changes the largechange volume
Largeincrement = 3, // click the next page, and the value changes the largechange volume.
Thumbposition = 4, // stop dragging in the scroll box
Thumbtrack = 5, // The scroll box is currently moving
First = 6, // The scroll box is moved to the minimum position-I have not found
Last = 7, // The scroll box is moved to the maximum position-I have not found
Endscroll = 8, // scroll to stop
}
3. Basic Attributes
Value // obtain or set the current location
Largechange // get or set the maximum volume of movement-one page
Smallchange // get or set the minimum volume of movement-one row
Maximum // get or set the maximum value
Minimum // get or set the minimum value
A> suppose the moving range is 100. If minimum = 0, maximum should be 99, not 100;
B> select an instance for the color value
This. hscrollbar1.smallchange = 1;
This. hscrollbar1.largechange = 16;
This. hscrollbar1.minimum = 0;
This. hscrollbar1.maximum = 255 + this. hscrollbar1.largechange-1;
Assume that the line feed span is 1, the page flip span is 16, and the minimum value is 0, the color value range is (0 ~ 255) how to set the maximum value? Note that the range of 255 plus the previous page is reduced by 1. Because the value is on the left of the page, and the maximum value is on the right of the page.
4. Integrated instance
A> click a button to change the value, trigger events, and sequence.
Private void btnchange_click (Object sender, eventargse)
{
This. hscrollbar1.value = 27;
}
Trigger only one event:
Valuechanged event -- value = 27
B> right-click and right-click the line feed to trigger events and sequence.
Three events are triggered. smallincrement event is triggered first, and the value is not changed. Then, valuechanged event and value are changed. Finally, endscroll even is triggered.
Smallincrement event -- value = 0
Valuechanged event -- value = 1
Endscroll event -- value = 1
C> drag the scroll box to trigger events and Sequence
As shown in the following figure, the thumbtrack event is continuously triggered during the drag process. Whenever the value changes, the valuechanged event is triggered. For example, the value of each drag operation may be greater than smallchange (1 here ), trigger the thumbposition event when the drag is stopped, and finally trigger the endscroll event.
Thumbtrack event -- value = 1
Thumbtrack event -- value = 1
Valuechanged event -- value = 4
Thumbtrack event -- value = 4
Valuechanged event -- value = 7
Thumbtrack event -- value = 7
Valuechanged event -- value = 11
Thumbtrack event -- value = 11
Valuechanged event -- value = 15
Thumbtrack event -- value = 15
Valuechanged event -- value = 20
Thumbtrack event -- value = 20
Valuechanged event -- value = 23
Thumbtrack event -- value = 23
Valuechanged event -- value = 26
Thumbtrack event -- value = 26
Valuechanged event -- value = 29
Thumbtrack event -- value = 29
Valuechanged event -- value = 30
Thumbtrack event -- value = 30
Valuechanged event -- value = 31
Thumbposition event -- value = 31
Endscroll event -- value = 31
D> right flip, trigger events and order
As shown below, like the next line feed, three events are triggered. First, largeincrementevent. At this time, the value is not changed, oldvalue is not changed, newvalue is changed, and then valuechanged event, value has changed; When endscroll even is finished, the value and oldvalue of the scoll function have been changed.
Enter scroll -- value = 3, oldvalue = 3, newvalue = 13
Largeincrement event -- value = 3, oldvalue = 3, newvalue = 13
Leave scroll -- value = 3, oldvalue = 3, newvalue = 13
Valuechanged event -- value = 13
Enter scroll -- value = 13, oldvalue = 13, newvalue = 13
Endscroll event -- value = 13, oldvalue = 13, newvalue = 13
Leave scroll -- value = 13, oldvalue = 13, newvalue = 13
5. Summary
A> If the responseCodeIn hscrollbar1_valuechanged, you cannot set the value randomly. Otherwise, excessive hscrollbar1_valuechanged events are triggered. If you do not need to modify the value dynamically, the following is a good choice.
Private int _ oldvalue = 0;
Private void btnchange_click (Object sender, eventargs E)
{
Myfunscrolllines (this. hscrollbar1.value-_ oldvalue );
_ Oldvalue = This. hscrollbar1.value;
}
B> the response code should not be put in the hscrollbar1_scroll in general sense. The scrolleventtype should be distinguished; otherwise, two hscrollbar1_scroll events will be triggered. Below is also a good line feed flip.
Private void hscrollbar_scroll (Object sender, scrolleventargs E)
{
If (E. newvalue! = E. oldvalue)
{
This. curvechart1.scrollline (E. newvalue-E. oldvalue );
}
// Switch (E. type)
//{
// Case scrolleventtype. largeincrement:
// Console. writeline ("largeincrement event -- value = {0}", hscrollbar1.value );
// Break;
// Case scrolleventtype. largedecrement:
// Console. writeline ("largedecrement event -- value = {0}", hscrollbar1.value );
// Break;
// Case scrolleventtype. smallincrement:
// Console. writeline ("smallincrement event -- value = {0}", hscrollbar1.value );
// Break;
//......
//}
}
C> maximum value = maximum-largechange + 1.