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.
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.
Whenever I write line to TextBox that is wider than width of textbox the scrollbar moves with appended text. The problem is I want to have scrollbar maximally moved to the left (at the beginning of the line). Can be moved at the end of writing or just fixed and then moved manually by scrollbar.
My question can be duplicate, because I don't even know how to name this issue.
Maybe screenshots can easier introduce my problem. On the left there is a position of a text in TextBox automatically moved and on the right side is position of thet text in TextBox manually moved by me with scrollbar.
I use FastColoredTextBox in my project and I just found method my_text_box.ScrollLeft(); and works fine. Whenever text appends on textbox it moves to the left, no flickering etc.
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.
I have been working for months on a project in c# in Visual Studio 2010 (it interfaces with a camera, power supplies, and motion control). There is a form with many controls on it (radio buttons, buttons, text boxes, bitmap displays...). Now I would like to put all of that on a tab so i can have another tab. This is so that the second tab can have all the default settings on it (e.g, portnumber, baud rate, integration times, pathname...).
Is this doable? Is there a way to cut and paste or click and drag?
Update:
I created a form, put a button on it that when clicked displays a message box with "Hello World". Then i added a tab control to the form, and dragged the button onto the first tab. The button still functions in the same way, displaying the message box when clicked.
So on my big form, i added a tabcontrol. Without resizing it, i did a select all, then unselected the tabcontrol, then dragged everything onto the tab. I then moved the tab control and resized it, then iteratively resized the tab window and moved all the controls. this worked, except the picturebox controls somehow got resized so they were larger than a screen width. Resized the pictureboxes and everything works. (perhaps i just needed the encouragement to give it a try...sorry if not the best question:).
To do this in code, in Form1.Designer.cs can add:
this.tabPage1.Controls.Add(this.button1);
However, I would have to do this for every single control (about 200 of them in Designer.cs).
This can usually be done with some editing of the .Designer.cs file. First, make sure you make a backup in case it all goes horribly wrong. Place the tab control and add a single control (a button or anything) to it. Then examine the .Designer.cs file. As you point out yourself, you will see a line like this:
this.tabPage1.Controls.Add(this.button1);
As for the existing controls on the form, there will be a bunch of lines like this:
this.Controls.Add(this.meErrorReport);
this.Controls.Add(this.peWarningSign);
this.Controls.Add(this.meHeaderText);
this.Controls.Add(this.btnClose);
So what you do is to cut these lines (not including the one for the tab control!), and paste them just following the line shown above, and do a find-and-replace to change them so they match the first one:
this.tabPage1.Controls.Add(this.meErrorReport);
this.tabPage1.Controls.Add(this.peWarningSign);
this.tabPage1.Controls.Add(this.meHeaderText);
this.tabPage1.Controls.Add(this.btnClose);
This should usually do the trick. The controls may be positioned wrong, and most will be hidden until you increase the size of the tab control, but these are minor problems that can be fixed.
PS. I know you've already fixed your problem, but I'm posting this answer in case it can help you, or someone else, in the future.
I've searched but couldn't find the answer or even a hint about this problem I'm having. The right side of a textbox truncates the text. The textbox is set to be multiline and wrap text. The odd thing is, if I highlight the text and then copy/paste into Notepad ++, the 'missing' text is actually there.
This leads me to believe that it is a visual issue. I've tried everything I can possibly think of. The textbox's right border is showing 0.0in and the row in which it sits is set at 10.5in.
The only thing I was able to do to make it work was to make the row longer than 10.5in but that creates an issue with printing.
Does anyone happen to have any more suggestions?