Scaling two Windows Forms controls while keeping the same ratio - winforms

I have 2 controls in a resize-able panel (1 datagridview and 1 textbox) with some space betwen and I need them both to scale in all directions with the panel. Problem is, since they're vertically stacked they run into each other when the panel scales vertically. I think I need some way to scale vertically while keeping the same ratio of the total panel size (ie, if the panel is scaled 2x, each control is scaled 2x) instead of anchoring them to all sides. Using C# if that matters, but I'm hoping for a non-programmatic solution.

A TableLayoutPanel was designed to provide this kind of scaling support. You'll need three rows with the middle one Absolute and the top and bottom Percent. Dock fill the controls in the rows, the rest is automatic.

Related

How to make a resizeable (from conner) layout like in 3d max main window

I have WPF prototype application which includes 1-4 other controls (WebBrowser control) like on picture
A need to resize a control (with facebook) taking it's conner and reducing size until the center of a window. If the size of this control would be less then "minSize" then it should be hidden\closed. Other layouts should fill an empty area.
I don't know from which controls should I start my experiments. No one does the right work.
I tried Grid, but it's impossible to take cell's conner to resize webBrowser control.
GridSplitter works just for two panels and doesn't let me take cell's conner.
Some developers say about custom control creating...

Is there an alternative to a WPF WrapPanel that wraps after a certain number of items, not a height?

Normally a WPF WrapPanel (Orientation="Vertical") will stack items vertically (and grow vertically) until it runs out of space from the parent container, and then it will "wrap" to the next column.
I want this functionality, but I want to add a hard limit to the number of items in a column. For instance, if my height is 100 and I have 3 items that are 30 pixels high, normally it could fit them all without wrapping. However, say I want to force it to wrap after 2. In that case, I want it to only grow to a height of 60, and wrap the 3rd item into the second column.
Is there something I can do to make this happen?
Maybe you can do it with the UniformGrid.
Use the Rows property to definie the amount of elements in vertical direction.
here is a nice little article about the available layout panels in WPF. If one of these does not fit the bill, you might have to build your own custom panel, here is a decent demo.

Scale usercontrol in wpf ? vertical and horizontal scrollbars

I implemented a usercontrol, but i have a problem with rescaling the window. I know when i make the window smaller, everything scales, and every textbox and label becomes also smaller. But this is not what i want, i just want that when i make the screen smaller, everything stays the same size, and that scrollbars appear ( vertical and horizontal ). How do i do that?
Thanks
Assumption
The behaviour you describe, is not mandatory the default layout-behaviour of WPF. It depends on the layout-controls you use. I assume, you're using a Grid with setting it's columns and rows to the Start (*)-GridLengths. This would have more or less such an effect as you describe (without scaling). Or maybe you are using a ViewBox, this control scales the whole content based on the available layout size.
Solution
I guess that wrapping your whole content into a ScrollViewer will probably do what you desire. If not, I suggest that you post some XAML-code to show us how you have built your content.
<ScrollViewer>
<YourContent>
</YourContent>
</ScrollViewer>
Update
If you really scale your window (applying a ScaleTransformation) and you want your UserControl to be the only control within that does not scale, you have to scale your UserControl in the opposite direction as you have done it with your window. Apply a ScaleTransformation and set the scale values to 1/scale. Or try to use the ViewBox to blow up the content of your UserControl, but this will not be very exact.

How to display texts and shapes with same width height at any zoom in Silverlight deep zoom applications?

In my Silverlight application I display texts (textblock on canvas) as well as rectangles and lines (again shapes drawn on the canvas) over deep zoom images. I handle zoom in / out, pan and tilts. What is not realy cool in my opinion, is the way my vector objects look at different zoom factors. Of cause they become bigger or smaller.
Would you have any suggestions how to keep some of the objects dimentions look the same at any zoom? let's say, a line with StrokeThickness will always be of 10 screen pixels. or text block width, height 100 screen pix by 300 screen pix.
Thanks,
Val
It depends on how/where your objects are defined that you want to remain at 1:1 scale.
The 2 options I can think of are:
Render those objects in a canvas above the deep zoom (this means you need to work out the positions again yourself).
Apply reciprocal scaling to those objects (which means you work out what scale the item is going to display at and apply a 1/x scaling factor to them. That way the deep zoom shrinks an object that is scaled up to compensate and the 2 cancel out).
Hope this helps.

Silverlight canvas scrollbars

I have read that placing a canvas inside a scrollviewer won't work because the canvas does not report its size. I have been experimenting with different containers (borders, grids, canvases and scrollviewers) and could really do with a simple explanation of how scrollviewers behave within nested containers. e.g. If I have a container hierarchy of UserControl>Grid1>Canvas1>ScrollViewer>Grid2>Canvas2 should scrollbars appear around Grid2 when Canvas2 becomes wider than Canvas1? (or indeed wider than UserControl) If not, how should I organise my containers so I can add loads of uielements to Canvas2 and have scrollbars appear as necessary. (My usercontrol width and height are set to 100%)
Canvas will work with a ScrollViewer if you explicitly give it a size. The problem comes from the fact that if you don't supply a Height and Width for any control it will try and determine it's available area based off it's parent container. A ScrollViewer however has infinite available area.
Take a Grid for example. If I define a Grid that has 2 Star Width columns and 2 Star Height rows. How does the Grid know how wide each of those columns should be? The star says they should be half of the available area, but inside a ScrollViewer the available area is infinity.
What controls are you adding to Canvas2? If you are adding them with fixed positions than the ScrollViewer will expand to house all elements. If you aren't giving them fixed positions than all the controls will stack on top of each other, because that is the arrange behavior of a Canvas

Resources