Vertical & Horizontal scrollbars in a panel
Scenario:
- Put a panel on a form.
- Set the panel's BorderStyle to FixedSingle. (Just so you can see it when you run it.)
- Set the panel's AutoScroll=True
- Set the panel's Anchor to Top, Left, Bottom, Right
- Inside the panel, place any sizable control (button, picturebox or whatever).
- Adjust the control's bottom edge to be just a few pixels above the bottom of the panel.
- Adjust the control's right edge should be a few pixels more narrow than the panel MINUS the width of a vertical scrollbar. (That is, it should be just narrow enough to leave room for a vertical scrollbar to may appear.)
Now run it, and vertically resize the form a little shorter so that you'd expect a VERTICAL scrollbar to appear.
Problem: BOTH scrollbars appear, because the very existence of the vertical scrollbar reduces the width of the client area, thus forcing a horizontal scrollbar to appear.
Apparently .NET evaluates whether a vertical scrollbar is necessary first, then evaluates whether the horizontal should appear, which is dependent upon whether the client size is reduced by the presence of a vertical scxrollbar. (i.e. the same experiment doesn't cause unnecessary VERTICAL scrollbars to appear... only horizontal ones.)
I'm using VB2008 Express but I'm guessing this carries over to later versions.
THE SOLUTION I NEED: I need either of: A) A "vertical autoscroll only" panel. B) I need a way to tell the panel to "rethink" whether the horizontal scrollbar is actually necessary. (Refreshes don't seem to do it.)
vb.net scrollbar panels
add a comment |
Scenario:
- Put a panel on a form.
- Set the panel's BorderStyle to FixedSingle. (Just so you can see it when you run it.)
- Set the panel's AutoScroll=True
- Set the panel's Anchor to Top, Left, Bottom, Right
- Inside the panel, place any sizable control (button, picturebox or whatever).
- Adjust the control's bottom edge to be just a few pixels above the bottom of the panel.
- Adjust the control's right edge should be a few pixels more narrow than the panel MINUS the width of a vertical scrollbar. (That is, it should be just narrow enough to leave room for a vertical scrollbar to may appear.)
Now run it, and vertically resize the form a little shorter so that you'd expect a VERTICAL scrollbar to appear.
Problem: BOTH scrollbars appear, because the very existence of the vertical scrollbar reduces the width of the client area, thus forcing a horizontal scrollbar to appear.
Apparently .NET evaluates whether a vertical scrollbar is necessary first, then evaluates whether the horizontal should appear, which is dependent upon whether the client size is reduced by the presence of a vertical scxrollbar. (i.e. the same experiment doesn't cause unnecessary VERTICAL scrollbars to appear... only horizontal ones.)
I'm using VB2008 Express but I'm guessing this carries over to later versions.
THE SOLUTION I NEED: I need either of: A) A "vertical autoscroll only" panel. B) I need a way to tell the panel to "rethink" whether the horizontal scrollbar is actually necessary. (Refreshes don't seem to do it.)
vb.net scrollbar panels
No comments ('till now). No upvotes (or downvotes -apparently-). No accepted answer (come on!). 1731 views. What?
– Anonymous Pi
Mar 2 '14 at 2:06
add a comment |
Scenario:
- Put a panel on a form.
- Set the panel's BorderStyle to FixedSingle. (Just so you can see it when you run it.)
- Set the panel's AutoScroll=True
- Set the panel's Anchor to Top, Left, Bottom, Right
- Inside the panel, place any sizable control (button, picturebox or whatever).
- Adjust the control's bottom edge to be just a few pixels above the bottom of the panel.
- Adjust the control's right edge should be a few pixels more narrow than the panel MINUS the width of a vertical scrollbar. (That is, it should be just narrow enough to leave room for a vertical scrollbar to may appear.)
Now run it, and vertically resize the form a little shorter so that you'd expect a VERTICAL scrollbar to appear.
Problem: BOTH scrollbars appear, because the very existence of the vertical scrollbar reduces the width of the client area, thus forcing a horizontal scrollbar to appear.
Apparently .NET evaluates whether a vertical scrollbar is necessary first, then evaluates whether the horizontal should appear, which is dependent upon whether the client size is reduced by the presence of a vertical scxrollbar. (i.e. the same experiment doesn't cause unnecessary VERTICAL scrollbars to appear... only horizontal ones.)
I'm using VB2008 Express but I'm guessing this carries over to later versions.
THE SOLUTION I NEED: I need either of: A) A "vertical autoscroll only" panel. B) I need a way to tell the panel to "rethink" whether the horizontal scrollbar is actually necessary. (Refreshes don't seem to do it.)
vb.net scrollbar panels
Scenario:
- Put a panel on a form.
- Set the panel's BorderStyle to FixedSingle. (Just so you can see it when you run it.)
- Set the panel's AutoScroll=True
- Set the panel's Anchor to Top, Left, Bottom, Right
- Inside the panel, place any sizable control (button, picturebox or whatever).
- Adjust the control's bottom edge to be just a few pixels above the bottom of the panel.
- Adjust the control's right edge should be a few pixels more narrow than the panel MINUS the width of a vertical scrollbar. (That is, it should be just narrow enough to leave room for a vertical scrollbar to may appear.)
Now run it, and vertically resize the form a little shorter so that you'd expect a VERTICAL scrollbar to appear.
Problem: BOTH scrollbars appear, because the very existence of the vertical scrollbar reduces the width of the client area, thus forcing a horizontal scrollbar to appear.
Apparently .NET evaluates whether a vertical scrollbar is necessary first, then evaluates whether the horizontal should appear, which is dependent upon whether the client size is reduced by the presence of a vertical scxrollbar. (i.e. the same experiment doesn't cause unnecessary VERTICAL scrollbars to appear... only horizontal ones.)
I'm using VB2008 Express but I'm guessing this carries over to later versions.
THE SOLUTION I NEED: I need either of: A) A "vertical autoscroll only" panel. B) I need a way to tell the panel to "rethink" whether the horizontal scrollbar is actually necessary. (Refreshes don't seem to do it.)
vb.net scrollbar panels
vb.net scrollbar panels
edited Feb 28 '14 at 15:59
Tshepang
6,1751772114
6,1751772114
asked Oct 6 '13 at 16:10
PaulOTron2000PaulOTron2000
6891916
6891916
No comments ('till now). No upvotes (or downvotes -apparently-). No accepted answer (come on!). 1731 views. What?
– Anonymous Pi
Mar 2 '14 at 2:06
add a comment |
No comments ('till now). No upvotes (or downvotes -apparently-). No accepted answer (come on!). 1731 views. What?
– Anonymous Pi
Mar 2 '14 at 2:06
No comments ('till now). No upvotes (or downvotes -apparently-). No accepted answer (come on!). 1731 views. What?
– Anonymous Pi
Mar 2 '14 at 2:06
No comments ('till now). No upvotes (or downvotes -apparently-). No accepted answer (come on!). 1731 views. What?
– Anonymous Pi
Mar 2 '14 at 2:06
add a comment |
3 Answers
3
active
oldest
votes
I ran into something that sounds like what you describe. I wanted just a Vertical scroll because it was going to contain many many things eventually, but not a Horizontal scroll. I used a table layout panel; set the Panel's Vertical size so that the VScroll shows; set the width to accommodate what will go in there plus whatever margin or gutter your code will use.
Then, in the TableLayoutPanel
set the width of the scrolling panel's to absolute (I used 2 pixels more than the panel.width). If/when the user resizes, all the extra size gets distributed to everything else. Basically dont let the scrolling panel's width change. Might have to/want to set a minimum form size too.
The things I was adding were all the same width, if yours vary, you might have to set it to accommodate the widest.
Not sure if you are encountering the same thing, but sure sounds like it.
add a comment |
In order to use panel autoscroll property I do that:
- panel.AutoScroll = False (is inverse I know :D)
- panel.VerticalScroll.Visible = False or panel.HorizontalScroll.Visible = False
In order to know the dimensions of the scroolbars use
SystemInformation.HorizontalScrollBarHeight
SystemInformation.VerticalScrollBarWidth
So you can change the dimension of the panel when the scroolbar is shown.
add a comment |
The AutoScroll
property does not allow you to have too much control on the scrollbars (even though you have VerticalScroll
and HorizontalScroll
properties).
Out of the proposed alternatives, I go for option A; the marked answer in this post gives a quite effective solution to an equivalent problem. Converted & adapted code (where Panel1
is the panel referred in your question):
Private Declare Function ShowScrollBar Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal wBar As Integer, ByVal bShow As Boolean) As Boolean
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
Try
ShowScrollBar(Panel1.Handle, 0, False)
Catch ex As Exception
End Try
MyBase.WndProc(m)
End Sub
If you set the AutoScroll
property of your panel to true and add this code, you would get what you are looking for.
NOTE: the proposed code works but at certain price: I personally intend to avoid Protected Overrides Sub WndProc
codes as much as possible. If getting exactly this functionality is important for you, rely on the proposed methodology; otherwise, you might have to consider other alternatives (e.g., AutoScroll = False
and adding a VScrollBar
to the panel, which will always be there).
Worked for me, THANKS! I couldn't find anything till you!
– Anonymous Pi
Mar 5 '14 at 16:58
@AnonymousPi Thanks to you for having let me know that this has helped someone :)
– varocarbas
Mar 5 '14 at 17:05
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f19210946%2fvertical-horizontal-scrollbars-in-a-panel%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
I ran into something that sounds like what you describe. I wanted just a Vertical scroll because it was going to contain many many things eventually, but not a Horizontal scroll. I used a table layout panel; set the Panel's Vertical size so that the VScroll shows; set the width to accommodate what will go in there plus whatever margin or gutter your code will use.
Then, in the TableLayoutPanel
set the width of the scrolling panel's to absolute (I used 2 pixels more than the panel.width). If/when the user resizes, all the extra size gets distributed to everything else. Basically dont let the scrolling panel's width change. Might have to/want to set a minimum form size too.
The things I was adding were all the same width, if yours vary, you might have to set it to accommodate the widest.
Not sure if you are encountering the same thing, but sure sounds like it.
add a comment |
I ran into something that sounds like what you describe. I wanted just a Vertical scroll because it was going to contain many many things eventually, but not a Horizontal scroll. I used a table layout panel; set the Panel's Vertical size so that the VScroll shows; set the width to accommodate what will go in there plus whatever margin or gutter your code will use.
Then, in the TableLayoutPanel
set the width of the scrolling panel's to absolute (I used 2 pixels more than the panel.width). If/when the user resizes, all the extra size gets distributed to everything else. Basically dont let the scrolling panel's width change. Might have to/want to set a minimum form size too.
The things I was adding were all the same width, if yours vary, you might have to set it to accommodate the widest.
Not sure if you are encountering the same thing, but sure sounds like it.
add a comment |
I ran into something that sounds like what you describe. I wanted just a Vertical scroll because it was going to contain many many things eventually, but not a Horizontal scroll. I used a table layout panel; set the Panel's Vertical size so that the VScroll shows; set the width to accommodate what will go in there plus whatever margin or gutter your code will use.
Then, in the TableLayoutPanel
set the width of the scrolling panel's to absolute (I used 2 pixels more than the panel.width). If/when the user resizes, all the extra size gets distributed to everything else. Basically dont let the scrolling panel's width change. Might have to/want to set a minimum form size too.
The things I was adding were all the same width, if yours vary, you might have to set it to accommodate the widest.
Not sure if you are encountering the same thing, but sure sounds like it.
I ran into something that sounds like what you describe. I wanted just a Vertical scroll because it was going to contain many many things eventually, but not a Horizontal scroll. I used a table layout panel; set the Panel's Vertical size so that the VScroll shows; set the width to accommodate what will go in there plus whatever margin or gutter your code will use.
Then, in the TableLayoutPanel
set the width of the scrolling panel's to absolute (I used 2 pixels more than the panel.width). If/when the user resizes, all the extra size gets distributed to everything else. Basically dont let the scrolling panel's width change. Might have to/want to set a minimum form size too.
The things I was adding were all the same width, if yours vary, you might have to set it to accommodate the widest.
Not sure if you are encountering the same thing, but sure sounds like it.
edited Oct 6 '13 at 16:57
answered Oct 6 '13 at 16:38
Make StackOverflow Good AgainMake StackOverflow Good Again
35.5k1140101
35.5k1140101
add a comment |
add a comment |
In order to use panel autoscroll property I do that:
- panel.AutoScroll = False (is inverse I know :D)
- panel.VerticalScroll.Visible = False or panel.HorizontalScroll.Visible = False
In order to know the dimensions of the scroolbars use
SystemInformation.HorizontalScrollBarHeight
SystemInformation.VerticalScrollBarWidth
So you can change the dimension of the panel when the scroolbar is shown.
add a comment |
In order to use panel autoscroll property I do that:
- panel.AutoScroll = False (is inverse I know :D)
- panel.VerticalScroll.Visible = False or panel.HorizontalScroll.Visible = False
In order to know the dimensions of the scroolbars use
SystemInformation.HorizontalScrollBarHeight
SystemInformation.VerticalScrollBarWidth
So you can change the dimension of the panel when the scroolbar is shown.
add a comment |
In order to use panel autoscroll property I do that:
- panel.AutoScroll = False (is inverse I know :D)
- panel.VerticalScroll.Visible = False or panel.HorizontalScroll.Visible = False
In order to know the dimensions of the scroolbars use
SystemInformation.HorizontalScrollBarHeight
SystemInformation.VerticalScrollBarWidth
So you can change the dimension of the panel when the scroolbar is shown.
In order to use panel autoscroll property I do that:
- panel.AutoScroll = False (is inverse I know :D)
- panel.VerticalScroll.Visible = False or panel.HorizontalScroll.Visible = False
In order to know the dimensions of the scroolbars use
SystemInformation.HorizontalScrollBarHeight
SystemInformation.VerticalScrollBarWidth
So you can change the dimension of the panel when the scroolbar is shown.
answered Jan 21 '14 at 9:51
BossOzBossOz
629
629
add a comment |
add a comment |
The AutoScroll
property does not allow you to have too much control on the scrollbars (even though you have VerticalScroll
and HorizontalScroll
properties).
Out of the proposed alternatives, I go for option A; the marked answer in this post gives a quite effective solution to an equivalent problem. Converted & adapted code (where Panel1
is the panel referred in your question):
Private Declare Function ShowScrollBar Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal wBar As Integer, ByVal bShow As Boolean) As Boolean
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
Try
ShowScrollBar(Panel1.Handle, 0, False)
Catch ex As Exception
End Try
MyBase.WndProc(m)
End Sub
If you set the AutoScroll
property of your panel to true and add this code, you would get what you are looking for.
NOTE: the proposed code works but at certain price: I personally intend to avoid Protected Overrides Sub WndProc
codes as much as possible. If getting exactly this functionality is important for you, rely on the proposed methodology; otherwise, you might have to consider other alternatives (e.g., AutoScroll = False
and adding a VScrollBar
to the panel, which will always be there).
Worked for me, THANKS! I couldn't find anything till you!
– Anonymous Pi
Mar 5 '14 at 16:58
@AnonymousPi Thanks to you for having let me know that this has helped someone :)
– varocarbas
Mar 5 '14 at 17:05
add a comment |
The AutoScroll
property does not allow you to have too much control on the scrollbars (even though you have VerticalScroll
and HorizontalScroll
properties).
Out of the proposed alternatives, I go for option A; the marked answer in this post gives a quite effective solution to an equivalent problem. Converted & adapted code (where Panel1
is the panel referred in your question):
Private Declare Function ShowScrollBar Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal wBar As Integer, ByVal bShow As Boolean) As Boolean
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
Try
ShowScrollBar(Panel1.Handle, 0, False)
Catch ex As Exception
End Try
MyBase.WndProc(m)
End Sub
If you set the AutoScroll
property of your panel to true and add this code, you would get what you are looking for.
NOTE: the proposed code works but at certain price: I personally intend to avoid Protected Overrides Sub WndProc
codes as much as possible. If getting exactly this functionality is important for you, rely on the proposed methodology; otherwise, you might have to consider other alternatives (e.g., AutoScroll = False
and adding a VScrollBar
to the panel, which will always be there).
Worked for me, THANKS! I couldn't find anything till you!
– Anonymous Pi
Mar 5 '14 at 16:58
@AnonymousPi Thanks to you for having let me know that this has helped someone :)
– varocarbas
Mar 5 '14 at 17:05
add a comment |
The AutoScroll
property does not allow you to have too much control on the scrollbars (even though you have VerticalScroll
and HorizontalScroll
properties).
Out of the proposed alternatives, I go for option A; the marked answer in this post gives a quite effective solution to an equivalent problem. Converted & adapted code (where Panel1
is the panel referred in your question):
Private Declare Function ShowScrollBar Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal wBar As Integer, ByVal bShow As Boolean) As Boolean
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
Try
ShowScrollBar(Panel1.Handle, 0, False)
Catch ex As Exception
End Try
MyBase.WndProc(m)
End Sub
If you set the AutoScroll
property of your panel to true and add this code, you would get what you are looking for.
NOTE: the proposed code works but at certain price: I personally intend to avoid Protected Overrides Sub WndProc
codes as much as possible. If getting exactly this functionality is important for you, rely on the proposed methodology; otherwise, you might have to consider other alternatives (e.g., AutoScroll = False
and adding a VScrollBar
to the panel, which will always be there).
The AutoScroll
property does not allow you to have too much control on the scrollbars (even though you have VerticalScroll
and HorizontalScroll
properties).
Out of the proposed alternatives, I go for option A; the marked answer in this post gives a quite effective solution to an equivalent problem. Converted & adapted code (where Panel1
is the panel referred in your question):
Private Declare Function ShowScrollBar Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal wBar As Integer, ByVal bShow As Boolean) As Boolean
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
Try
ShowScrollBar(Panel1.Handle, 0, False)
Catch ex As Exception
End Try
MyBase.WndProc(m)
End Sub
If you set the AutoScroll
property of your panel to true and add this code, you would get what you are looking for.
NOTE: the proposed code works but at certain price: I personally intend to avoid Protected Overrides Sub WndProc
codes as much as possible. If getting exactly this functionality is important for you, rely on the proposed methodology; otherwise, you might have to consider other alternatives (e.g., AutoScroll = False
and adding a VScrollBar
to the panel, which will always be there).
edited May 23 '17 at 12:23
Community♦
11
11
answered Oct 6 '13 at 17:21
varocarbasvarocarbas
11.9k31934
11.9k31934
Worked for me, THANKS! I couldn't find anything till you!
– Anonymous Pi
Mar 5 '14 at 16:58
@AnonymousPi Thanks to you for having let me know that this has helped someone :)
– varocarbas
Mar 5 '14 at 17:05
add a comment |
Worked for me, THANKS! I couldn't find anything till you!
– Anonymous Pi
Mar 5 '14 at 16:58
@AnonymousPi Thanks to you for having let me know that this has helped someone :)
– varocarbas
Mar 5 '14 at 17:05
Worked for me, THANKS! I couldn't find anything till you!
– Anonymous Pi
Mar 5 '14 at 16:58
Worked for me, THANKS! I couldn't find anything till you!
– Anonymous Pi
Mar 5 '14 at 16:58
@AnonymousPi Thanks to you for having let me know that this has helped someone :)
– varocarbas
Mar 5 '14 at 17:05
@AnonymousPi Thanks to you for having let me know that this has helped someone :)
– varocarbas
Mar 5 '14 at 17:05
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f19210946%2fvertical-horizontal-scrollbars-in-a-panel%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
No comments ('till now). No upvotes (or downvotes -apparently-). No accepted answer (come on!). 1731 views. What?
– Anonymous Pi
Mar 2 '14 at 2:06