Custom scrolling in Winforms c# - c#

I am developing an application that will use touch screens to navigate for use in a warehouse environment.
There is a need to present a list to the users and because this list could be quite long, the user will at some point need to scroll down the list.
As you all know the system scroll bars for panels and textboxes etc is quite small and I would like to know if I can either resize the controls that make up the scroll bar (the little arrows at the top and bottom, and the place holder bar in the scroll bar itself), or if I can create a couple of buttons that can scroll up and down my control for me?
Thanks,
Karl

Answer pulled from this post.
Check this out:
Winforms - Adjust width of vertical scrollbar on CheckedListBox
Worth mentioning too:
.NET Compact framework - make scrollbars wider
More of the same, but this time with a better solution through the use of the scrollbar control:
Change the width of a scrollbar
Another one in which the guy teaches how to create your own scrollbar control (interesting):
Set the Scrollbar width of a DataGridView
The last one (worth trying):
Is there a way to get the scrollbar height and width for a ListView control

You can add your own scroll buttons and programatically scroll like so:
myPanel.VerticalScroll.Value++;

Related

Cannot find C# DataGridView HorizontalScrollBar property

I use Visual Studio 2015 for a Windows Form project and want to hide the horizontal scroll bar, but not frozen. The reference of DataGridView shows a property "HorizontalScrollBar"
https://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview(v=vs.110).aspx
But I cannot find this property when I code with intellisense. I use 4.5.2 .Net Framework. If I set "ScrollBars = vertical", there is still blank area in the bottom, which I want to remove. Did anyone meet this problem before?
HorizontalScrollBar is a protected property which is why it does not show in intellisense. You configure the scroll bars with the ScrollBars enumeration:
dataGridView1.ScrollBars = ScrollBars.Vertical; // or Horizontal, etc.
The blank area at the bottom is unrelated to horizontal scrolling.
Do you have enough items in the DataGridView such that the vertical scroll bar is active? I'm wondering if the blank area at the bottom is the background of the control when there isn't enough items to fill all the the grid. Could you add a screenshot to give a better idea of what you are talking about? I would have expected Scrollbars set to Vertical to be the solution.

Custom Scrolling with ListView

I've been tasked at work with creating a UserControl containing a ListView and ComboBox's for sorting the ListView data. Sorting with the Combobox's s the easy part; the part with which I'm having difficulty is implementing a method of scrolling. In the end, the control should have an Excel-like feel to it. However, sometimes the ListView is too tall or wide for where it is placed. Therefore, there two be two scrollbars somewhere on the control. One vertically moves of the ListView only, and the other moves both the ListView and ComboBox filters horizontally.
Please note in the image above that the ComboBox's do adjust themselves according to column width, but the code for that is not enabled at the moment.
What I've tried: In the control, the filter boxes are in their own panel, and the ListView has had its own panel at times. I've tried using various combinations of the HScroll/VScroll and HorizontalScroll/VerticalScroll properties and the native function ShowScrollBar() for all the controls, but nothing has worked. The only way I've gotten scrollbars to appear is by settings AutoScroll (Scrollable for the ListView) to true. Of course, the scroll bars come in pairs and work only on the same control. I also attempted to programmatically move the scroll bars, but I haven't been able to accomplish that, either.
I've got to be doing something wrong, but I'm not sure what it is. Any help is appreciated!
I think I'd go for a different solution.
If you put the ComboBoxes in a AutoSrcoll panel with the same Anchors as the ListView you would give your users the freedom to scroll the two independently.
Yes, a ScrollBar would appear and take space but I would still happily sell that as a feature, not a bug ;-)
As for handling the Scroll event of a ListView: It is hidden and you'll have to subclass it to get access to it. See here

C#: How to draw very large controls in a scrollable, zoomable panel?

Imagine a bar graph with horizontal bars that may be very wide. I have a Panel on a Form where I want to display these bars and scroll and zoom them. The Form, and thus the Panel, can be resized. The bars are dynamically created from a database. Each time the user zooms in or out, all bars have to be created anew to adjust their sizes on the Panel.
I use Label controls to create these bars, but the problem applies to all other controls as well: If I zoom in far enough, my bars will eventually exceed the magic 16 bit border of control sizes (>65536 pixels). This makes it impossible to simply create all the controls on the panel at start and let the panel handle the scrolling.
My idea: Clear the Panel of all bar controls and create only the ones that are visible in the current view window, according to the current position of the scroll bars and the zoom level. The bars exceeding far from the visible view will be cut short just outside the Panel, so their maximum size is limited by the Panel size.
My questions:
At which Panel event(s) should this clear/create process take place best?
There could be thousands of controls, so it should be as seldom as possible.
Is there a better way to handle this? Maybe I got it all wrong from the start.
This problem arises not only with huge controls but also when smaller controls are very far apart (>65536 pixels) on a Panel, so I think a good solution may be helpful for many projects.
I wouldn't like to have to create / destroy controls, or hide / resize controls just for their click events. It's quite easy to create a UserControl and override the OnPaint method to draw the bars, and override the OnClick or OnMouseXxx events.
Since you already know the positions of the bars in "virtual space", it's easy to map the location of the mouse cursor to a bar (or a click outside a bar).
I know you said winforms is Mandatory, but I really think you should look into the wpf viewbox. You can host a wpf element in winforms. So everything else can be forms related, and you have a panel that hosts and displays your controls. I could write up a quick example that might demonstrate this for you, but if you have no intent of going this way I really don't want to waste my time.
You could create a metafile (vector graphics), show that in an image control, and manually determine which logical element is clicked.

WPF datagrid scrolling issue

there is a search View ( app is a MVP - PRISM WPF ) which had some issue with scrolling. it took hell of a long time to scroll when you click the scroll bar buttons. Click and dragging the scroll bar was even worse!!
considering i like anomalies, i picked it and started looking into what was going wrong. I suspected many things, but evidently the issue with the datagrid scroll was due to "ScrollViewer.CanContentScroll=True" i removed it and the scrolling was a pleasant experience compared with earlier.
Now i was wondering why my developers had put that property as true, with in couple of mins i found Doing a Page down was scrolling more than a page with out the CanContentScroll property marked true!
Now i need the scrolling to be faster AND i also need page down and page up to scroll as expected! Can some one tell me What I am missing here?? thanks!
I had similar issues with my datagrid : slow scrolling, and also randomly size changing scrollbar.
I did the following:
simplify the templates of the cells (no more nested borders and multiple colors, ToggleButtons instead of CheckBoxes)
in code use frozen colors.
this helped speed things up but did not solve the issue.
Then i set the row / cells templates height and also the RowHeight property, and then it was ok : i had both smooth scrolling and normal scrollbar. So i guess that the DataGrid was unable to compute the size of what remained to be displayed that made both the scroll slow and the scrollbar having changing size.
(Yet the rows / cells were all having same actual height in their templates since they were defined with same controls but Height property was not set...)
Hope that can help.

Auto scrolling control (WinAPI)?

In C# (.Net) you can create a panel and set autoscroll to true. you can then add controls into it, including beyond it's size, then it will scroll.
I was wondering if when using the real WinAPI in c++ (not .net) how one could acheive the same result.
Must I keep track of the controls inside and move them all when I scroll or is there an easier way like in C#.
Thanks
For an edit control (textbox), you can supply ES_AUTOVSCROLL when creating it via CreateWindow or CreateWindowEx. For adding a scrollbar for multiple controls in a window, I believe you have to do it manually. Write a function to sum the vertical height of all the child controls + spacing between them and if it's smaller than the window, add a vertical scroll bar, if it's larger, remove the vertical scroll bar (if it exists). Be sure to call this after adding/removing child controls and on window resize.

Categories