I have a control (a text editor control) that uses the default scrollbar to scroll the text. However, clicking the scrollbar only makes it scroll a few lines.
I want to handle the scrollbar left click on my own, and make it scroll page down / page up, depending on the click, if it's above the scrollbar thumb, then page up, if it's below the thumb, page down.
TL;DR I want to know how to handle a left click on a default scrollbar and whether the cursor is above/below the scrollbar thumb. I know there's the Scroll event but it occurs after the user has scrolled, I want something like Scrolling.
If by "default scrollbar" you mean the scrollbars that are part of any ScrollableControl (UserControl, etc.), there's no need to handle the click event. The VScrollProperties class already gives you control over this out of the box:
Use ScrollableControl.VerticalScroll.SmallChange to set the distance the scroll should move when the user clicks on the scrollbar buttons (arrows).
Use ScrollableControl.VerticalScroll.LargeChange to set the distance the scroll should move when the user clicks on an empty space on the scrollbar.
Demo:
Related
This question already has answers here:
How to capture mouse wheel on panel?
(5 answers)
Closed 4 years ago.
I've built a Windows Form, in Visual Studios 2013 using C#, that has one actual Form.cs. I have a single panel in the Form.cs that I am docking/filling with UserControl.cs files as needed. The UserControls are what I am using as the actual "user input forms" for the users to fill out controls/fields and submit the needed data. I have everything working fully/correctly except for scrolling with the mouse wheel.
Here is a typical scenario that I am trying to find a solution for; When the user first navigates to one of the UserControls, they can click on a blank portion of the window and it will allow scrolling with either the vertical scroll bar on the right or with the mouse wheel. However, when the user clicks into any control within the UserControl, a textbox, a listbox, a combobox, etc., the mouse scroll will no longer scroll the window. I have not been able to find how to allow mouse wheel scrolling by moving the focus off of the control/field and onto the UserControls background or other location to aloow the users mouse wheel to scroll the window.
One thing I must make clear is the UserControls do have the vertical scroll bar available so the user can click on the scroll bar to move the window up/down, so this portion is not an issue. I have just not been able to find a way to allow the user to scroll using the mouse wheel after they click on any control/field in the UserControl "form".
How can I move the focus off of any control/field and onto the UserControls background or other location to allow the mouse wheel to scroll the window/form/UserControl?
Edit: I have AutoScroll set to False on the Form.cs and the docked panel, however, I have AutoScroll set to True on each of the UserControls. This allows the right-hand scrollbar to render and be used however this does not seem to have any affect on the mouse-scrolling. I've tried every combination of setting the AutoScroll without success.
Edit(2):
*
* Form
- panel1
^ UserControl1.cs
^ UserControl2.cs
^ UserControl3.cs
^ UserControl4.cs
^ UserControl5.cs
Each UserControl gets applied to/rendered on panel1, based on user options. Each UserControl has the vertical scrollbar rendering on the right-hand side. Mouse-scrolling is not functioning after user clicks on/selects any control (textbox, listbox, combobox) to enter/select data. Whatever control is clicked and has focus, the focus is not moving to allow the mouse wheel to scroll the window.
This is not the most ideal answer I think but you could add Form.Focus(); to the Scroll event of every Control in your Form.
Using WinForms, C#...
I have a UserControl that contains a few panels.
When I programatically resize the panel, it causes the scroll bar to scroll to the top. I would like to prevent this as it is frustrating for the user to have the control scroll to the top.
I've tried to use "ScrollToControl()" after the resize bu this isnt practical as you still see the form jump and the once focused control is now at the bottom of the control.
Have tried to access the AutoScrollPosition but it returns 0. this.VerticalScroll.Value also returns 0 (where this is the user control before the resize event)
Any suggestions?
In my project i have the tabControl shown below and inside of it i have a richTextBox on which i enabled the Vertical ScrollBar...
In the richTextBox i have some "Assembly commands" and each time i highlight the instruction that is executed. My problem is when some of the last instructions i have in the textbox, must execute, those are not visible, so i have to drag manually the scrollbar.
What i'm trying to do is to set the scrollbar to move up/down by itself without any user interaction.
is there any possible solution for my problem? thanks
I'm having an issue where my scrollbar for a panel on a usercontrol always appears at the bottom.
If I hover the mouse over the tab and cause the control to slide out and be shown, the scrollbar is at the bottom. If I then move the scrollbar to the top and move the mouse off the control (which causes it to hide again) and then move the mouse back over the tab (which causes the control to slide back out) the scroll bar is back at the bottom!
Setting the VerticalScroll.Value property on my panel to 0 is not having any effect - the control still shows at the bottom. Can someone tell me what events might fire when a control slides back into view on an autohide tab or just tell what I could do to solve this issue! I assume that the Paint event is what fires when the control is shown but I'm not entirely sure.
I did notice that in the VS designer that the scrollbar by default is shown at the bottom. Not sure whether this may have anything to do with the issue?
Any suggestions appreciated!
Try this:
scrollingCtrl.VerticalScroll.Value = 0;
scrollingCtrl.PerformLayout();
Simple question, but I didn't know what's the keywords to Google.
Suppose we want to adjust the height of the taskbar on Windows. When u place the mouse cursor at the edge of it, the cursor will change to an up and down arrow meaning that the taskbar is resizable.
How do I get that cursor to come out in C#?
Is there a control for it? Or do I have to check if the mouse is on the edge of the control, if it is change cursor. On click resize according to the difference?
You would put a splitter control onto the form, set it to horizontal, then put the control you want to be sizeable (taskbar, whatever) inside the splitter, go into the dock settings and dock it to all sides.