Infinite Vertical Scrolling - c#

I have a WinForms application and a Panel Control. The panel control has a VScrollBar control for vertical scrolling. Everything works fine except right now I have my VScrollBar maximum value set to 100. The problem is, I need the Maximum property to be about 4 billion, however, since Maximum is only an Integer, I can't set it to the proper value. So, my question is, how do I get around this? I know there are text editors and file viewers that claim to view more then 4 gigs of data, so how would a scrollbar in an application like that work?

A scrollbar is a GUI control. Innately, the number of steps it can display is limited to the number of vertical pixels on your screen. Therefore, you could consider setting the maximum value to anything above that to be simply for developer convenience, to make the math easier.
How do applications deal with scrollbars? In theory, you'd want to parse the file first, to find out how many lines are in the file, and use that as your logical maximum. In reality, reading 4 GB of data when the file is opened would kill performance, so that wouldn't work.
If I were implementing this, I would set the scrollbar maximum is set to a large value, say 10,000. When the scrollbar is used, the scrollbar value is divided by 10,000 to get a percentage, and the editor shows that section of the file.
Don't think of things in terms of scrolling down so many lines. Instead, think of it as jumping to that percentage offset of the file, reading the data there, and displaying that.

Well, you could just set Maximum to int.MaxValue and scale the retrieved value to your real maximum value. This should be enough precision to avoid loading too much data.

You use a percentage. There is no need to set it to the same as the number of lines.

Related

DataGridView anchors

I have a Windows Form with 2 DatagridViews placed side by side, but when I maximise the form they either remain with their original sizes or one overlaps another, depending on how I've set the anchors.
Is there a way I can limit how much those controls can grow to each direction?
Yes, you can.
Use MaxiumSize.Width, MaxiumSize.Height to set the maximum size of your control. You'll need to set minimum size as well using MinimumSize.Width and MinimumSize.Height properties.

Text rendering: resizing text to fit inside a box?

I'm working on a text rendering system and I'm trying to implement a mechanism for automatically scaling down the text size to fit inside a specified box.
With word wrapping disabled, the task is nice and simple. All I have to do is check whether the width or height is proportionally larger, then scale the text down by that same ratio.
Unfortunately, with word wrapping enabled, the task gets much more complicated. If the text is larger than the box and I scale it down, the smaller text size might be able to fit more words onto each line, which might change the overall bounding box so that a different scale makes it fit the box better. Then applying that different scale might again mean there's a better way to word wrap it, and so on.
Most of the other solutions I've been able to find are basically:
while (isTooBig) { DecrementFontSize(); }
That would work, but could be very inefficient, so I was wondering if anyone knows of any lower level algorithms that deal directly with the text parsing? Failing that, do you know of any open source programs which include this feature so I can get their source code and see how they do it?
Edit: I'm doing this in Unity3D, but that doesn't really have any bearing on my problem since I'm implementing my own text rendering system.

Alignment of text when column width is changed from GUI in winform application

I have developed a winform application. It has a listview with multiple columns having different texts. Initially, I have set the column width = -2 to take the size of longest text in the column.
The issue is that sometime text overshoots the laptop screen and a horizontal scroll bar appeared in the list view.
To fit all the columns in a screen, I manually modified the columns widths using column boundaries in the GUI. When I modify the column width, the column text starts disappearing from right. I want it to disappeared from left.
I have searched goggle a lot but did not find the answer.
Question might look weird or may be I have not explained it properly. Please let me know if more information is needed.
Thanks in advance.
The Listbox columns in Windows Forms are not exactly a high level control, I've used it some times but just for simple lists, It certainly has not a builtin function to make what you want, to obtain it you probably need to subclass the control, create a new class for the item managed in the list and write some code to perform what you need.
I think you can find some hints on how to achieve all this in Charles Petzold book about windows forms where he shows how to measure a string and how to draw directly on your control.

WPF Wrapping content into maximum 2 columns. Evenly distributed

I am attempting to insert a panel into my WPF application that would have a few very specific behaviours:
1.) Wraps content evenly. Starting from the top left corner and running downward, before moving to the next column.
2.) Allows me to define a maximum number of columns to wrap to. For my purposes, this number would be between 1 and 3.
3.) Allows me to set an initial height, but it will also grow to accommodate additional items. (Only setting an initial height because my content won't wrap without it. If I leave it auto, it all comes out in a single column regardless of whether it fits on screen or not)
At this point, I have concluded that what I'm attempting do will require a custom panel, but I'd like to ensure before I begin that process (and learning how to do so) that I'm not missing a much simpler answer.
A WrapPanel can be set to wrap vertically, but you have no control over the number of columns.
A UniformGrid would offer you control over the number of columns, but wraps horizontally not vertically.
In short: you need a custom panel. The built-in ones do not offer the combination of features that you want.
UniformGrid has a LayoutTransform property, which can be used to transform it in order to change the position/rotation of the elements inside. But it will also transform the content.
Some more tricks involving Setters on the types of the items inside your UniformGrid and the content can be transformed again to retain the desired "original" orientation.
You can learn more in this tutorial.
Alternatively, it seems that the Extended WPF Toolkit contains its own implementation of UniformGrid, with an Orientation property, the only problem being that it won't grow to accomodate the number of items; instead, it will obey to an arbitrary Columns property.
Then again, you may be able to change the value of this property each time you add a new item/resize your UniformGrid, but it will be some more manual work and may potentially lead to code behind, which could be seen as an issue if you're working in MVVM.

C# problem with scrolling to end of UserControl with large amount of content

I've created UserControl that contains bunch of other controls that are placed also outer area of visible part of my control to cause vertical scrollbar to appear, as expected and required behaviour.
Everything works as it should untill size, amount and location of controls doesn't exceed some value. I say some cause i couldn't determine which value i exceed and by that I cause my control work not quite well.
Amount of controls inside my UserControl can vary from few to few thousands, depending on circumstances. Controls are same size, displayed in rows/columns. Number of rows, and columns that user see in visible part of UserControl depends on size of controls inside. As far as i know it should be possible for me to operate on values of location as big as max value of int. But it seems that im doing something wrong, cause while tests things doesn't work as it should.
While the Location.Y value of control at the bottom of my UserControl is for example 49150 scrolling of control doesn't bring me nowhere near that value VScrollBar.maximum no matter how much controls i put and how far their Y location would be never go bigger than 32896.
When i change size of my UserControl or size of controls inside, so the Location.Y of last control isn't too far, everything works great.
Is there any way that i can fix VScrollBar, or do anything else to get my control work exactly as I need it, or anything else that could cause such problem?
MTH
It looks like that is the size limit based on when winforms was originally created back when everything was 16 bit.

Categories

Resources