Looking for some examples, either huge, or an installation component or something, I asked for it to work. Really look for examples to change the trouble, just made a. In fact, the implementation is quite simple, that is, a panel or a picture or a mouse walk on the line.
Here the panel can add a background map or a direct map of the line. To demonstrate clearly, there is a scrollbar control that makes comparisons with the custom synchronization.
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Windows.Forms;namespacecustomscroll{ Public Partial classForm1:form {intLIMT, set_x;//scroll position maximum and fixed left and right position BOOLMouse_press =false;//mouse button down BOOLMouse_wheel =false;//whether the pulley rollsPoint Mouseoff;//hold the current mouse position PublicForm1 () {InitializeComponent (); //populate a panel with a bunch of content for(inti =0; I < -; i++) {Panel Num_panel=NewPanel (); Label Num=NewLabel (); Num. Text= i +"."; Num. ForeColor= Color.FromArgb (255,255,255); Num. Width= -; Num. Dock=DockStyle.Left; //set the mouse wheel event, the Mouse_wheel value is true, in the move, the following, there is no writing here//Num. MouseWheel + = new MouseEventHandler (onmousewheel);Num_panel. Name="Panel_"+i; Num_panel. Height= *; Num_panel. Margin=NewPadding (0,0,0,0); Num_panel. BackColor=Color.steelblue; Num_panel. BorderStyle=Borderstyle.fixed3d; Num_panel. Dock=Dockstyle.top; Num_panel. BorderStyle=System.Windows.Forms.BorderStyle.None; Num_panel. Controls.Add (num); //set the mouse wheel event, the Mouse_wheel value is true, in the move, the following, there is no writing here//Num_panel. MouseWheel + = new MouseEventHandler (onmousewheel);Content_panel. Controls.Add (Num_panel);//load content into//set the mouse wheel event, the Mouse_wheel value is true, in the move, the following, there is no writing here//Content_panel. MouseWheel + = new MouseEventHandler (onmousewheel); } //Loading Contents panel Auto SizeContent_panel. AutoSize =true; Set_x= Scrollhard_panel. location.x;//fixed left and right position as current positionLIMT = Scrollbar_panel. Height-scrollhard_panel. Height;//Max Scroll HeightScrollhard_panel. Location =NewPoint (Set_x,0) ;//first set the position to the topVscrollbar1.maximum = LIMT;//set up a VScrollBar component, demo, and custom Sync//Mouse Wheel EventScrollbar_panel. MouseWheel + =NewMouseEventHandler (OnMouseWheel); Scrollhard_panel. MouseWheel+=NewMouseEventHandler (OnMouseWheel); Vscrollbar1.mousewheel+=NewMouseEventHandler (OnMouseWheel); } //Mouse Wheel Event Private voidOnMouseWheel (Objectsender, System.Windows.Forms.MouseEventArgs e) { intSet_y =0; if(Mouse_wheel)//whether to judge the mouse wheel { if(E.delta >0)//pulley up{set_y= Scrollhard_panel. LOCATION.Y-Ten;//every time you move the ten if(Set_y <0) {set_y =0; }//Super Range } if(E.delta <0)//Pulley down{set_y= Scrollhard_panel. LOCATION.Y +Ten;//every time you move the ten if(Set_y > LIMT) {set_y = LIMT;}//Super Range} scrollhard_panel. Location=NewPoint (set_x, set_y);//positioning of the scroll blockVscrollbar1.value = set_y;//scroll bars for presentation, and custom synchronizationContent_panel. Top=-set_y;//Panel Scrolling display of the loaded content } } //Custom Scrolling "block" box Mouse press Private voidScrollhard_panel_mousedown (Objectsender, MouseEventArgs e) { if(E.button = = MouseButtons.Left)//left mouse button{mouseoff.y= E.y;//take the current positionMouse_press =true;//mouse button down } } //Custom Scrolling "block" mouse release Private voidScrollhard_panel_mouseup (Objectsender, MouseEventArgs e) {mouse_press=false;//Mouse Release } //Custom Scrolling "block" mouse out of range Private voidScrollhard_panel_mouseleave (Objectsender, EventArgs e) {Mouse_wheel=false;//Pulley Not available } ////Custom Scrolling "block" mouse in the range Private voidScrollhard_panel_mousemove (Objectsender, MouseEventArgs e) {Mouse_wheel=true;//can use pulleys if(mouse_press)//Mouse down State { intSet_y = Scrollhard_panel. Top + e.y-mouseoff.y;//Calculate current longitudinal coordinates if(Set_y <0) {set_y =0; }//Super Range Else if(Set_y > LIMT) {set_y = LIMT;}//Super Range Else{Scrollhard_panel. Location =NewPoint (set_x, set_y); }//positioning of the scroll blockVscrollbar1.value = set_y;//Demo scroll bars and custom synchronizationsContent_panel. Top =-set_y;//Panel Scrolling display of the loaded content } } //within the range of the scroll box Private voidScrollbar_panel_mousemove (Objectsender, MouseEventArgs e) {Mouse_wheel=true;//can use pulleys } //Leave the scroll "box" Private voidScrollbar_panel_mouseleave (Objectsender, EventArgs e) {Mouse_wheel=false;//Do not use pulleys } //Custom scrolling "box" mouse release Private voidScrollbar_panel_mouseup (Objectsender, MouseEventArgs e) { if(E.button = = MouseButtons.Left)//left mouse button { intset_y = e.y;//Current Ordinate if(Set_y > LIMT) {set_y = LIMT;}//Super RangeScrollhard_panel. Location =NewPoint (set_x, set_y);//Scroll block positioningVscrollbar1.value = set_y;//presentation of scroll bars, and custom synchronizationContent_panel. Top =-set_y;//Panel Scrolling display of the loaded contentMouse_press =false;//the mouse is the release state } } //the VSCROLLBAR1 component of the demo can also control the Panel scrolling display of the loaded content Private voidVscrollbar1_scroll (Objectsender, ScrollEventArgs e) {Content_panel. Top= -Vscrollbar1.value; } }}
Beginner C #-Learning Note (v) Winfrom custom scroll bar