I've got a C# Forms.RichTextBox that autoscrolls to bottom as new lines get added. However; resizing the box leaves the bottom lines in the dust during and after the resizing.
I've tried hooking OnLayout to scroll to bottom if the last frame reported it was at the bottom, but this only works when sizing larger and cuts off the last line beneath the scrollbar, and still leaves the bottom in the dust while sizing smaller. I've got WM_VSCROLL and other user32 stuff hooked up, but I'm not sure how to deal with resizing..
It seems like I should get a ResizeStart to mark whether it was scrolled to bottom, and then a Resize event that should try to keep it there, but there is no ResizeStart. From what I can tell Resize just gets called at every frame with nothing helpful in its eventargs. Help!
I'm open to hosting a WPF control if this would be easier.
Related
Here is the problem. If you dynamically place controls in a panel, it works fine, but only until the vertical scrollbar appears. Once there is enough content for this to happen, it starts positioning controls nonsensically.
In my window, you can click a button to add another row of controls inside the panel, which represent options for an item in a list. If you scroll the vertical scrollbar on the panel all the way down and click the button again, the new row of controls will be positioned below the bottom edge of the panel out of view. If you scroll down, there is a huge gap between the new row and the previous row of controls. This should not happen. The positioning code is working flawlessly, as proven by debug output. As far as I can tell, the problem is the stupid anchoring system, however disabling anchoring on these controls does not fix the problem as one might expect. Instead, it just makes it position them wrong in a different manner. This makes no sense at all, and is super annoying!
I tried disabling Autoscroll in code before controls are added to the panel. No change. So I modified that code to disable both the vertical scroll bar and Autoscroll and set the scrollbar to not visible before controls are added. No change again, except that the now disabled vertical scrollbar still manages to appear usable when there is enough content in the panel in spite of it being disabled and set not visible!? That's not supposed to happen when I disabled and made it invisible! With anchoring disabled on the controls being added to the panel and once the vertical scrollbar has appeared, clicking the button to add a few more rows of controls now causes them to be indented a bit for no reason and positioned overlapping each other a bit vertically! It's as if the coordinate system in the panel has somehow arbitrarily changed, because of the presence of a vertical scrollbar and anchoring being disabled on the controls? The debug code shows that the controls are all being placed at correct coordinates, yet they appear positioned very wrongly. So my code is working perfectly, and therefore something else is the problem here.
Everything behaves exactly as expected up until the vertical scrollbar appears. This is so bizarre. Does anyone have any idea what on earth is going on with this stuff? Apparently it is far easier to make it do stupid stuff than to get it working properly.
Thanks again! I got it working. I went with TaW's solution first since it seemed like the simplest solution. Incidentally, I already tried TaW's approach days ago when I was fighting with it, but I had naturally subtracted the AutoScrollPosition value rather than add it, because I didn't expect it to be a negative value!
It seems very odd that control positioning is relative to the current AutoScrollPosition, as absolute coordinates seems like a much more natural, intuitive approach than having negative numbers. I guess that would make it slightly harder to place a control in the currently visible area, but I suppose that's not a big deal as most scrollable interfaces are probably initialized ahead of time and don't need to do that anyway.
There appears to be a bug in the Win32 edit control that WinForms.TextBox wraps:
Open Notepad.
Make sure that the bottom scrollbar is visible (you may have to turn off word wrapping).
Enter a long line, so that the bottom scrollbar activates.
Delete some of this text, so that the line becomes much smaller.
Now the bottom scrollbar doesn't update to reflect the fact that the line is now much smaller.
In fact, even if you resize the window, the scrollbar still seems to think that we have a huge line. The only work-around seems to be enabling and disabling word wrapping.
Can anyone suggest a way to fix this from a WinForms .NET app?
Another workaround is when the additional text is deleted .. cut the remaining text and then paste it again. That makes scroll bar disappear.
You can hit CTRL+A to select all text then CTRL+X to cut and CTRL+V to paste.
Just an idea.
I'm totally new to Win Forms. I see that the vertical scroll bar on the right hand side for someone else's code does not reach the bottom right corner. You'd think I'd be able to just grab it and resize it. However, I'm not able to do it. I don't see a two-sided arrow that usually indicates resize. There is a vertical spacer on top of it if that makes a difference. Also in the properties window, I cannot change the height to make it longer. Is it locked somehow that I'm unaware of and cannot make the changes? Thanks.
It is likely that the panel or control that has the scrollbar is not sized, anchored or docked correctly. This would result in it existing underneath the bounds of a maximised form and therefore inaccessible.
Try making sure that in the designer its bounds are correctly within the form and the anchoring and docking values are logical. Otherwise, consider viewing its .Size and .Location properties in the debugger to see if it is too far "south".
I have an application that displays wrapped text in a ScrollViewer that takes up a fixed height of the page. I set the HorizontalScrollBarVisibility to Disabled, and the VerticalScrollBarVisibility to Auto.
The usability problems I'm having are as follows:
Despite being set to Auto, if the content is smaller than the ScrollViewer, then the content can still scroll up and down, either scrolling past the end or hiding a portion of the text. I would like the ScrollViewer not to allow scrolling when the entire content fits inside its bounds. At the very least it should always snap the content back into view when you over-scroll.
Secondly, when the content does scroll, it sometimes gets stuck past the end and won't "snap back" from the over-scroll. For example, if the content fits fully in the ScrollViewer, and you drag your finger up or down on the text, the text will be obscured by the top or bottom of the ScrollViewer, and won't snap back. If however you drag your finger up starting from outside of the content of the ScrollViewer, it will snap back when you scroll past either end. I would like the "snap back" behavior to happen whether you drag on the content or outside of the content. Is that possible?
First issue: If your content isn't large enough to warrant the need for a scroll viewer don't put it in one. If the size of the content changes only enable the scrollbar when the volume of content warrants it.
Can you provide a way of reproducing the second issue.
C#. I'm filling a panel with controls such that a scrollbar comes up. When the scrollbar shows up, I would like the controls (anchored top|left|right) to resize so they aren't covered by the scrollbar. If I make the form bigger and then smaller again, they resize properly, but I don't know how to make them do this sizing when the scrollbar shows up.
There doesn't seem to be an event for this. However, you could override the form's virtual AdjustFormScrollbars method in order to detect if a change has occurred.