Use a specific viewport width in a WebBrowser component - c#

How do I limit the width of a webpage inside a WebBrowser component so that the content is displayed in a "mobile" format, no horizontal scrolling is required and the font is still readable?
I have a relatively small WebBrowser component that needs to display mainly text websites alongside the rest of the form's controls. I'd have to make it really wide so that the font is readable and the whole text line fits inside the control. If I could somehow limit the viewport, like it happens in most browsers when you simply zoom in (no horizontal scrolling needed, the site resizes itself, provided it is responsive to narrower screen resolutions). Changing the zoom in the WebBrowser control introduces scrollbars and doesn't change the way the entire page is rendered.

Related

Moving popup to back - C# UWP Universal Windows

Is there a way to move a popup to back, so it does not always display on the front of the application?
I have a canvas that displays many shapes, which are resizable. To get the resize box I am using a popup, because it was suggested that the best way would be to use adorners, but these are not used in UWP, so the alternative are popups. It works quite well, but when I have another element overlaying my canvas and resizing was enabled on a shape, the popup elements (resize thumbs/nodes) are displayed on top of the element that should be overlaying the canvas. Is there a way to tell the popup that it should not display on a "higher level" than my canvas?
A Popup control is intended to be displayed on top of all other content so it seems you're not using an appropriate control for what you are trying to achieve.
Without seeing more of your code and having a clearer idea of what you're doing (repro?) it's hard to suggest what you should do. However, I'd avoid resizing control that aren't on top of the viewable area or having multiple items in a resizable mode (or just with adorners displayed) at a time. Both of these should avoid what you're reporting.

Windows Forms: Resolution Issue

I am C++ programmer, and I am working on a migration project where I need to convert C++ code to C# and I have little knowledge on C#. Also, Clients want the application in .net 2.0
Issue:
When the screen resolution changes to low resolution, the form is adding a scroll bar to show all the controls in the screen. But, Client wants without any scroll bar such that all the controls should be visible.
Font applied to the controls should fit to the control dimension even if we change the resolution to high or low.
Any suggestions?
Use containers to house your controls. TableLayoutPanel would probably be a good choice. Set the TableLayoutPanels DockStyle to Fill. TableLayoutPanels only allow you to put one Control in each section, but Panels allow multiples so put a Panel in each section and set each Panels DockStyle to Fill. Arrange your controls in the panels and set each controls Anchor or DockStyle properties to keep them in location. Now, set your resolution to the lowest possible setting and build your form. If you follow the above steps, when you raise the resolution everything will be in the same relative location with the same relative size.
Why it works: Setting the tablelayoutpanels DockStyle to Fill makes it autosize with the parent form. Setting each panels DockStyle makes it autosize with the TableLayoutPanels sections. Anchoring/Docking controls inside the panels keeps the controls sizing and spacing relative to the panel.

How to set the background of webview transparent in winRT?

I have a web view which loads html content in a page.How its back ground can set to transparent.I set the html background transparent.
Try this:
<WebView DefaultBackgroundColor="Transparent"/>
To my knowledge that's not possible since this an actual HTML page you are rendering inside the Webview.
The webview does not derive from Control and because of this, it does not support the same templating possibilities as if you we using a control that derived from Control.
Also since browsers can't have a transparent website, the website will appear white per default.
This may not directly relate to your question however I think it's still important to know when using the Webview. There is some important remarks from the documentation on MSDN concerning UI and rendering:
WebView has the characteristic that other UI regions such as controls cannot be rendered on top of the WebView. This is because of how window regions are handled internally, particularly how input events are processed and how the screen draws. If you want to render HTML content and also place other UI elements on top of that HTML content, you should use WebViewBrush as the render area. The WebView still provides the HTML source information, and you reference that WebView through the SourceName property. WebViewBrush does not have this overlay limitation.
If you want to display an interactive WebView that only occasionally has overlapping content (such as a drop-down list or app bar), you can temporarily hide the WebView control when necessary, replacing it with an element using a WebViewBrush fill. Then, when the overlapping content is no longer present, you can display the original WebView again. For more info, see the WebView control sample.
For more information see the full documentation.
They have fixed it in Windows Universal App.
If you set DefaultBackgroundColor to Transparent
and
body, html {
background:transparent;
}
you will get what you want

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.

Maintaining the size of the control which is located on the form when form is resized

I have one form which size is (325,325) and on which one browser is there and the size of the browser is (321,298) means browser is in the middle of the form.And I want to maintain the size of the browser when form is resized like there should be the same difference of the size between form and browser as it was before resized.
Like the previous answers stated, you should Anchor the control.
You should set the Anchor property to Top, Left, Right, Bottom to let the browser grow/shrink when the form is resized, but maintaining the margins.
You should Anchor the control on the form.
Have a look at
Manage WinForm controls using the
Anchor and Dock properties
Control.Anchor Property
Manage WinForm controls using the
Anchor and Dock properties
Anchoring a control to its parent
ensures that the anchored edges remain
in the same position relative to the
edges of the parent container when the
parent container is resized.
Setting the WebBrowser's Dock property to Fill is the correct answer here. This completely eliminates the possibility that you'll have layout problems when you run your program on a machine that has a different system font size or a different video adapter DPI setting.
If you need room for some kind of gadget or toolbar, be sure to dock it as well (usually Top). Use Format + Order if the browser ends up underneath the gadget.
Use the control's Anchor property to anchor it to all 4 edges of the form. The control will automatically change it's size when the parent form resizes then.
The MSDN article explains the basics. Google finds quite a few interesting links as well.

Categories