void SetupMinButtonProperties(RenderElement container) { ScrollBarButton min_button; if (this.ScrollBarType == ScrollBarType.Horizontal) { min_button = new ScrollBarButton(minmax_boxHeight, this.Height, this); } else { min_button = new ScrollBarButton(this.Width, minmax_boxHeight, this); } min_button.BackColor = KnownColors.FromKnownColor(KnownColor.Green); min_button.MouseUp += (s, e) => this.StepSmallToMin(); container.AddChild(min_button); this.minButton = min_button; }
void SetupMaxButtonProperties(RenderElement container) { ScrollBarButton max_button; if (this.ScrollBarType == ScrollBarType.Horizontal) { max_button = new ScrollBarButton(minmax_boxHeight, this.Height, this); max_button.SetLocation(this.Width - minmax_boxHeight, 0); } else { max_button = new ScrollBarButton(this.Width, minmax_boxHeight, this); max_button.SetLocation(0, this.Height - minmax_boxHeight); } max_button.BackColor = KnownColors.FromKnownColor(KnownColor.Yellow); max_button.MouseUp += (s, e) => this.StepSmallToMax(); container.AddChild(max_button); this.maxButton = max_button; }
void SetupHorizontalScrollButtonProperties(RenderElement container) { var scroll_button = new ScrollBarButton(10, this.Height, this); //create with default value scroll_button.BackColor = KnownColors.FromKnownColor(KnownColor.DarkBlue); int thumbPosX = CalculateThumbPosition() + minmax_boxHeight; scroll_button.SetLocation(thumbPosX, 0); container.AddChild(scroll_button); this.scrollButton = scroll_button; //---------------------------- EvaluateHorizontalScrollBarProperties(); //---------------------------- //3. drag scroll_button.MouseDrag += (s, e) => { //---------------------------------- //dragging ... //find x-diff Point pos = scroll_button.Position; //if vscroll bar then move only y axis int newXPos = (int)(pos.X + e.DiffCapturedX); //clamp! if (newXPos >= this.Width - (minmax_boxHeight + scrollButton.Width)) { newXPos = this.Width - (minmax_boxHeight + scrollButton.Width); } else if (newXPos < minmax_boxHeight) { newXPos = minmax_boxHeight; } //calculate value from position int currentMarkAt = (newXPos - minmax_boxHeight); this.scrollValue = (float)(onePixelFor * currentMarkAt); newXPos = CalculateThumbPosition() + minmax_boxHeight; scroll_button.SetLocation(newXPos, pos.Y); if (this.UserScroll != null) { this.UserScroll(this, EventArgs.Empty); } e.StopPropagation(); }; //------------------------------------------- //4. scroll_button.MouseLeave += (s, e) => { if (e.IsDragging) { Point pos = scroll_button.Position; //if vscroll bar then move only y axis int newXPos = (int)(pos.X + e.XDiff); //clamp! if (newXPos >= this.Width - (minmax_boxHeight + scrollButton.Width)) { newXPos = this.Width - (minmax_boxHeight + scrollButton.Width); } else if (newXPos < minmax_boxHeight) { newXPos = minmax_boxHeight; } //calculate value from position int currentMarkAt = (newXPos - minmax_boxHeight); this.scrollValue = (float)(onePixelFor * currentMarkAt); newXPos = CalculateThumbPosition() + minmax_boxHeight; scroll_button.SetLocation(newXPos, pos.Y); if (this.UserScroll != null) { this.UserScroll(this, EventArgs.Empty); } e.StopPropagation(); } }; }