user1314391
user1314391

Reputation: 199

Enable scroll bars in windows forms

I'm developing a windows forms application. In my application I have anchored controls to forms such that forms can be maximized and controls will get arranged accordingly. This application should support different DPI values.

I have set the anchors of some controls to bottom, right, and bottom-right. The AutoScroll property of the forms is set to true. When the DPI value is on default (96) controls work as expected. But the problem is if the screen loads in higher DPI (like 120), even though form scroll bars enabled, controls which are anchored to bottom and bottom-right cannot be seen.

Could anybody please advise me on this issue?

regards, Eranga

Upvotes: 19

Views: 138626

Answers (5)

dalip
dalip

Reputation: 141

Create a Panel called panel1, then do the following:

panel1.AutoScroll  = true;
panel1.BorderStyle = BorderStyle.FixedSingle;

Use this method to set scroll width and height:

panel1.SetAutoScrollMargin(int x, int y);

Upvotes: 14

Ahmad Hamdy Hamdeen
Ahmad Hamdy Hamdeen

Reputation: 556

1. From "Form" properties 👉 Set AutoScroll = True: enter image description here 2. Move any control to the lower right corner: enter image description here

Upvotes: 0

Florian Ritter
Florian Ritter

Reputation: 11

I was reading through this page and i can say it provides an exact and easy solution to your problem!

I tested it and it worked well for me.

Instruction:

  1. Add a manifest file to your project (Project --> New Item --> Select the manifest type)
  2. Add the following XML into your app.manifest (may be another name):
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3" >
   <asmv3:application>
        <asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
             <dpiAware>true</dpiAware>
        </asmv3:windowsSettings>
   </asmv3:application>
</assembly>
  1. Add the following C# code into the class where you call the component initialize (InitializeComponent();)
[DllImport("shcore.dll")]
static extern int SetProcessDpiAwareness(_Process_DPI_Awareness value);

enum _Process_DPI_Awareness
{
    Process_DPI_Unaware = 0,
    Process_System_DPI_Aware = 1,
    Process_Per_Monitor_DPI_Aware = 2
}
  1. Now just add this code line above your initialize component method (by default InitializeComponent();)
SetProcessDpiAwareness(_Process_DPI_Awareness.Process_DPI_Unaware);

Upvotes: 0

violet313
violet313

Reputation: 1932

It's an old post but the issue is ongoing and related posts just keep on arriving on SO!

I'm doing the necro thing here rather than addressing a more recent question only because it comes top of my google search

The question is simple: "why won't the damn scrollbars appear on my ScrollableControl?"

But there can be no specific, definitive answer. Because the causes are legion. Because whether or not scrollbars appear on a control depends:

  • not only upon it's own properties settings
  • but also upon the state of it's parent control
  • and also the states of any child controls.

It's easy to fall into the trap of randomly twiddling prop-values until the cows come home. Or go on the i/webs &hope to find some SO foos. But oh dear. Here is a handful of related SO posts with an outstanding variety of proposed resolutions:

Horizontal Scrollbar is not visible on DataGridView

Horizontal scrollbar not showing on my textbox

How to set scroll bar in Windows form

How to make scrollbars appear in a resizable panel when the contained control is too big for it?

Scrollable Form in c#, AutoScroll=true doesn't work

How to get scrollbar in Panel in VB.Net?

There are screen-shots of VS-designer property pages (like here) & even some extreme code-based solutions... my favourites:

Add vertical scroll bar to panel in .NET

how to add Vscroll control to form in Visualbasic.net?

/sighs/


A general answer

..in the form of a minimal github solution in order to explore some of the .NET scrollbar voodoos:

https://github.com/violet313/TestWinForms/tree/Test1-Body-Panel

It's a Visual Studio 2015 solution using the .NET4.52 framework.

In the solution i am trying to create a form that responds to some dynamic text data that is to be displayed. here's the basic lay-out i am ultimately seeking:

--------------------------------------------------
|      fixed-size form header       |            | 
------------------------------------|   side     |
|                                   |   panel    |
|      dynamic content panel        |   stuff    |
|                                   |            |
--------------------------------------------------
|      fixed-size form trailer                   |               
--------------------------------------------------

I want the form to:

  • not be resizable by the user
  • respond to the dynamic content by:

    • shrinking as small as possible down to a pre-determined minimum form-size.
    • growing up to a pre-determined maximum form-size; and providing appropriate scroll-bars on the dynamic content panel thereafter.

Grab it, go thro each of the (only 9 starting from 95dccc5)commits and then test your requirements in a sane & incremental fashion. be sure to branch whenever you make a dubious state-change.

Irl: maybe i'm a thicky but it took me over an hour reading the MSDNs trying (&failing) to figure-out the .NET forms control property contingencies. doing structured trial-and-error this way took me only 20mins to get what i wanted.


y~bwc

i know this here is a yeaz ~but who cares? but i had to get if off my chest. heh :

grrr. having to unlurk &answer this question arises out of my need to profitably take on Microsoft contract work. paymasters can be relatively (from a developer pov) non-technical and, having read lots of stuff including the words: quick, simple, straight-forward, secure, etc, come away with the impression that things .NETish is a stroll in the park. My issue with this is that i would then have difficulty trying to reasonably explain why they might need to pay me for n-day's worth of work in order to get a simple scroll-bar to appear on a responsive form.

On this occasion, i never got that far. lol. i spent a few hours wading thro the MSDN blahs trying to make it happen. and then yawned, gave up, &moved on with a pragmatic implementation. which was accepted. but it's now the w/end and i am an ocd fool who cannot let things be.

Upvotes: 10

Elshan
Elshan

Reputation: 7693

Set AutoScroll = True In Form Properties

Set AutoScroll = true on form

Upvotes: 51

Related Questions