Horizontally scroll a fixed header/footer - c#

I have a header that is set at a minimum width of 960px and is fixed to the top of the page. When the user shrinks the window to a size smaller than 960px, the horizontal scrollbar appears, as it should. However, when the user scrolls horizontally, since some of the header is cut off, I would like to be able to scroll the header at the same rate as the page... I pretty much want my header fixed vertically, but not horizontally.
I've looked at the following, but no help:
CSS: fixed position on x-axis but not y?
Centering a fixed element, but scroll it horizontally

I know this is a dated question and am not sure if you figured it out yet, but wanted to submit an answer in case someone else has the same problem.
When you set content to fixed in CSS with a minimum width, it is locked relative to the window on both axes. When the window is resized to less than minimum width, the excess header/footer is clipped and cannot be scrolled to. Unfortunately, there is no way to change this behavior in CSS alone. There is, however a simple jQuery fix for your problem (assuming you already have other content on the page that will create the horizontal scroll bar):
$(window).scroll(function ()
{
$("header,footer").css('margin-left', -($(window).scrollLeft()) + "px");
});
This will cause the header and footer (as appropriate) to move on the x axis in the opposite direction of the scroll, thus achieving your desired effect.

Related

How can I make left and right panels resize and center narrow panel stay centered with WinForms?

Mock-up
I am creating a WinForms application which is supposed to have three main vertical panels. The middle one (B) is narrow and centered. It is not to change in width, only in height as the form is resized, and it is always to stay in the horizontal center. The left (A) and right (C) panels are to resize to fill the rest of the available space.
I have tried the various docking and resizing options. But I haven't yet found the combination that will allow the left and right panels to fill the spaces on either side of the middle panel (which is to remain the same width.)
I'm still hoping that there is something that I'm missing, otherwise I will have to go the route of manual calculating the sizes and locations of the panels on the resizing event.
Even if I manually get B to remain in the center, I don't know of a way to get left and right to resize automatically without either covering or going behind the center panel.
Add the TableLayoutPanel to your Form and set its Dock property to Fill. Now edit the Rows/Columns. Remove the second row so there is only one row. Setup the Columns so they look like this:
Change the Absolute value of 50 to whatever width you want the middle to be.
The two Percent values can be anything, as long as they are the same number.
Now add the three Panels to each column and set the Dock property of each Panel to Fill.
Done.
Here's the result in action:

MonthCalendar Control not "obeying"? (CalendarDimensions)

The MonthCalendar's CandendarDimnesions is set to 1,1. But when run in large resolutions the dimensions Y increases. Screenshots are attached for better understanding.
How do I make sure it won't grow?
You have Anchor set to Top, Bottom, Right. If you don't want the Calendar size to change, don't anchor to Top and Bottom - only one or the other.

How to obtain visible borders of canvas placed on scrollviewer

I have canvas which is placed on scrollviewer in order to allow scrolling. Is it possible to get coordinates of visible part of canvas?
I was trying to calculate it that way
leftBorder = ScrollViewer1.HorizontalOffset;
rightBorder = ScrollViewer1.ViewportWidth - ScrollViewer1.HorizontalOffset;
topBorder = ScrollViewer1.VerticalOffset;
bottomBorder = ScrollViewer1.ViewportHeight - ScrollViewer1.VerticalOffset;
but it seems that it is not working.
The Horizontal and Vertical offset is the actual scroll value in that direction.
Besides that, if you want the size of the content without any scrollbars that might be visible.
You can search for the child named "PART_ScrollContentPresenter". This shows the actual content of the scrollviewer, and this content will be resized when the scrollbars needs more space.
Hope that helps.

WP7 ScrollViewer Snap-Back and Auto scrollbar visibility issues on windows phone

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.

Determine the width of the vertical scroll bar in a ScrollViewer

I'm using a ScrollViewer to display an Image. The Image has a ScaleTransform set as one of it's LayoutTransforms. I've got it setup to fit the width of the image into the ActualSize of the ScrollViewer. My problem is that if the image height requires the vertical scrollbar to be present (I have it set to Auto) then my image is scaled just a little bit to much. I know how to determine if the scrollbar would be present and how to get the correct scale, but I cannot figure out how to determine what the actual width of the scrollbar is. I guess I could just guess at it, but I'd like something that would work if I later add styles to my application that would result in the scrollbars being a different size. Additionally I'm also doing Fit to Height and would need to get the Height of the horizontal scrollbar when it would be visible (I'm assuming that the answer to getting the width of the vertical scrollbar would make getting the height of the horizontal scrollbar obvious).
You can use SystemParameters.ScrollWidth.
Using ViewableHeight and ViewableWidth instead of ActualHeight and ActualWidth in my scaling calculations along with setting the scroll bars Visibility to Visible instead of Auto works. However I'll accept another answer that allows the scroll bars to be set to Auto instead.
Edit:
OK, I've now got the scroll bars set to Visible. Then I do my calculation with the ViewableHeight and ViewableWidth. Then I set the scroll bars back to Auto. This seems to work even if it's not all that elegant.

Categories