I'm needing some assistance with what I can tell a vendor developing a form in an application I don't have the source to. We've found a bug with one of their large Winforms where if it's opened in an RDP session at 1024x768, the bottom 250px or so of the form which is ~1000px high is unreachable.
They're being difficult about saying there's no solution which I know to be nonsense, but I don't have a Visual Studio environment presently set up to build a proof of concept to test for myself and then show them otherwise.
From what I can tell from other StackOverflow questions and MSDN documentation pages, something like the following should resolve the problem so the form will auto-size to the maximum displayable height then put a vertical scrollbar in to allow viewing the bottom part of the form. Will the following achieve my goal?
public MyTallForm()
{
InitializeComponent();
this.AutoScroll = true
this.AutoSize = true
}
AutoSize responds to change in controls inside the form by growing & shrinking the form as needed.
AutoScroll responds to change in controls inside the form by displaying/hiding the scrollbars.
Thus, AutoScroll won't be activated if AutoSize is active since the form is always large enough. If the problem is from too small display resolution, you'll want AutoScroll.
If the form kept open between RDP sessions, you might need to subscribe to DisplaySettingsChanged to be aware of resolution changes, and either simply Maximize (not sure if it's already maximized, toggling to Minimized and back to Maximized perhaps?) or use GetWorkingArea if you need detailed size.
Set AutoScroll = True and AutoScaleMode to Dpi In Form Properties
Hope it helps.
Related
I have a problem and I couldn't find the answer anywhere on the internet. I am working on a project which its forms should be fixedsingle borderstyle. I don't want anyone to maximize or minimize the forms. So the real question is that I have two monitors and I'm working on the bigger one. When I start the program and slide the form to the smaller monitor, it looks exactly the same heigth and width. But I want the form to look smaller as the screen gets small or to look bigger if the screen gets bigger. Can you please help me?
You need to specify the Form.MinimumSize and Form.MaximumSize properties according to your needs. If you want to adjust the form dynamically at run time, you can hook the Form.Move event and set those properties relative to the screen's resolution minus the space used by the taskbar using Screen.WorkingArea. For a better user experience if the form is smaller than the screen size, I recommend disabling the maximize form button by setting Form.MaximizeBox to false.
I have a Windows Form where I can dynamically add/remove Controls (in rows).
Everything works as intended, until the Windows Form's max size has been reached.
After that happens the Control's locations won't update correctly anymore.
Here's an example: https://i.imgur.com/xADXb4L.png
It might be useful to know that the Windows Form has AutoSize = true and AutoSizeMode = GorwAndShrink.
Thanks in advance.
If anyone is interested, found the answer on a 9 year old discussion: https://www.daniweb.com/programming/software-development/threads/270543/control-added-on-the-fly-is-added-to-the-wrong-location-of-an-auto-scroll-panel
TL;DR Setting a Control's location when the Control is invisible doesn't work correctly. Making the Controls visible before I set their locations fixed all my problems.
Here's my problem: I have a winform with controls on it. Many of these controls have their Anchor property set to Top|Right. The size of the form in the designer is set to 1680x1050. If my resolution is set to 1680x1050 then it always comes up correctly.
If I change to a smaller resolution(say 1600x900) and the form is set to open as Maximized, then none of my controls move themselves to maintain their distance from the right edge. The controls on the right edge are all sticking out off the form a little. But, if I then unmaximize the window, and I can resize the window and all the controls will maintain their current, incorrect distance from the right edge.
If I set the form to start as normal(not maximized) then it opens up with all the controls in the right place, and everything stays in the right place if I resize the form.
This has been a very frustrating problem. Do any of you kind souls have advice for me?
Id recommend just using my proposed solution of:
theForm.WindowState = FormWindowState.Maximized;
My guess is that the property "Maximized" that is set during the initialization call of the form and may be causing the problems. (It's hard to say without seeing the project code). The Load even gets called after some of the more important events, so if there is some sort of existing problem with that property, it is avoided using the FormWindowState.Maximized code.
If you wish to post the actual code of what you think may be causing the problems, I'll edit this answer to help.
-J
I Solve my problem by:
Set the Control AutoSize property to false.
private void Form_Load(object sender, EventArgs e)
{
dataGridView1.AutoSize = false; //true;
}
Put all controls in SplitContainer and set Dock property of splitcontainer and control such as datagridview = Fill
I have a TableLayoutPanel that has several TableLayoutPanels inside it. The amount changes dynamically and will almost always be too many to be able to fit inside the form.I need it to have a scroll bar so I can view the entire component.
I have tried setting the autoscroll property on the main panel to true and docking it and/or setting a maximum size. What the controler does instead, is to try and fit ALL of the Panel inside the form therefore changing the size of its inside components and squeezing them all together instead of creating a scroll bar to scroll through my Panel.
Do you guys know what I might be doing wrong?
Thanks.
Jose
PS: I am using VS 2010
I had the same issue one day and found out that the problem was that I had a "MinimumSize" set to the TableLayoutPanel. That caused the control to keep a minimum height no matter what the Dock and/or Anchor constraints, preventing the AutoScroll feature to work properly. Since that feature is based on a simple check on the Y coordinates of all children controls of a control against that control's height, the scrollbar was not appearing despite the fact the the TableLayoutPanel's child controls were "disapearing" out of sight due to its parent control clip area.
So in other words, check the MinimumSize property of TableLayoutPanel and make sure it's empty.
Maybe this will help.
if it still doesn't work, try put a panel and then put the tableLayoutPanel into that panel. Set to true the autoScroll property of the panel.
I had the same thing happen on my project. All my controls were squished inside the TableLayoutPanel. In my case, I was rendering many of the controls as ColumnStyle.Percent. Switching this to ColumnStyle.Autosize was the fix I needed.
I assume you've set these properties as well, but just in case my TableLayoutPanels also use the following settings:
AutoSize = true;
AutoSizeMode = AutoSizeMode.GrowAndShrink;
AutoScroll = true;
Late answer, but I've been fighting with a complex layout recently and was looking for a solution to get my scrolling working on a screen with far too many fields. Honestly, better design should avoid this problem 99% of the time but sometimes your hands are just tied.
The Problem
The problem seems to be that if you're nested too deeply with multiple grids, groups, and panels they stop reporting properly to parent controls that their contents have overflown the size of the current screen. Actually, the problem is probably that the controls are all set to dock fill and do fit within their parent control, so the top level control doesn't know that the contents of its great-great-great-great-grandchild controls don't fit.
Solution
The trick to fix this seems to be manually forcing the top most panel to scroll at a certain minimum size:
MainPanel.AutoSize = true;
MainPanel.AutoScrollMinSize = new Size(400, 500);
TableLayoutPanel scrolling is full of bugs.
The solution to make it work correctly is here.
I'm trying to get scrollbars working with the web browser control. However, as I'll be using it to display a message for a custom messagebox, I don't want the scrollbar to appear even if its not needed - as it seems to do by default. To circumvent this I decided to disable scrollbars on the control and instead use scrollbars on another control like a Panel. This way they'll only appear when the contents of the browser page is too big to fit.
This hasn't worked out too well, though I've read quite a few posts, even on StackOverflow, where this seems to be a valid solution. One example is when I tried using the solution here:
Scrolling problem with a WebBrowser control contained in a Panel control
It seems as though if Scrollbars are disabled for the web browser, it won't let the panel use scrollbars either. This seemed to be the case when testing in design mode. To overcome this I tried adding a picture box behind the web browser inside the panel; it worked when in design mode (resizing the picture box and web browser would cause the panel to enable its scrollbars), but didn't work during runtime (I added code to have the picture box change to the size of the web browser control - which itself is always resized to fit the size of the scrollable contents).
I also tried programmatically enabling and disabling the web browser's scrollbars based on if the ScrollableRectangle size was bigger than the size of the control. This theoretically would be fine, except it seems to clear all text within the control any time the ScrollbarsEnabled property is changed - and thus is changed back to having no scrollbars.
I'm doing this with the following code, called effectively whenever a key is pressed in the control:
if (Output.Document.Body != null)
{
if (Output.Document.Body.ScrollRectangle.Size.Height > Output.Size.Height
|| Output.Document.Body.ScrollRectangle.Size.Width > Output.Size.Width)
Output.ScrollBarsEnabled = true;
else
Output.ScrollBarsEnabled = false;
}
else
Output.ScrollBarsEnabled = false;
It's also important to note that I also need a solution for the HTML editor which will be used within the app, so ideally any solution would not rely on a page load event etc... as these do not seem to trigger when the web browser has design mode set to on (which is needed for it to work as an HTML editor). However, in this particular situation I can fall back on enabling the default scrollbars if there's no better solution.
EDIT: To be clear, I am not talking about any scrollbars within the HTML content - that is of no concern as the HTML is simply being used to allow for flexible formatting of text. I'm talking only about the scrollbar of the browser control itself.
Any help much appreciated. Thanks!
I ended up finding a solution to this some time ago now, but forgot to post here. Basically what I did was first enable the scrollbars by default so they will work, although always appear. Then I created a panel control and sized it over the top of the inactive scrollbar that appears on the right of the web browser control.
Next I changed the anchors of the scroll bar panel so that the top, bottom, and right sides would always snap into the size of the form, and hence the size of the browser control as all edges of it too are anchored.
Then I added some code that checked the ScrollRectangle size and compared it with that of the browser, if it turned out to be larger in height or width, I then made the cover panel not visible, but otherwise left it in place.
Here's the relevant code snippets:
//If still bigger, set scrollbars:
if ((Output.Document.Body.ScrollRectangle.Size.Height > Output.Size.Height) ||
Output.Document.Body.ScrollRectangle.Size.Width > Output.Size.Width)
{
ScrollPanel.Visible = false;
ScrollPanel.Enabled = false;
}
Hope this helps someone else in future, took a few different methods before I found one that worked well enough.
I've decided to up Sheng's answer (when I get enough reputation) as, firstly he was the only person to response, and secondly, his information helped me when I was contemplating the use of some kind of invocation to try and enable the scrollbars during runtime. Though I found my solution simpler and just as effective.
That's too late. IDocHostUIHandler.GetHostInfo is called when the webbrowser is created, and the WebBrowser's implementation sets DOCHOSTUIFLAG_SCROLL_NO or the DOCHOSTUIFLAG_FLAT_SCROLLBAR flag based on the value of its ScrollBarsEnabled property.
I suggest you to set ScrollBarsEnabled to false before creating the Webbrowser control's window.
If you don't want the scrollbar of a particular element, such as body, div or textarea, to appear, you can set their styles to overflow='hidden' or use scrolling properties specific to the elements such as doc.Body.SetAttribute("scroll","no").