I am using ordinary Silverlight ChildWindow in my application. When resizing the browser window, in particular when making its width smaller than that of the child window, the edges of the child window get cropped, so that it is impossible to close it via the close button as it is no more visible. I have tried a number of workarounds but nothing helped. In particular I have subscribed to the SizeChanged event of the child window and set its sizes relative to the layout root's sizes. Here is the code of the SizeChanged event handler:
// Get the dimensions of the application screen
Size appSize = Application.Current.RootVisual.RenderSize;
// Make the child window occupy the 90% of width and 40% of height of the entire screen
this.Width = appSize.Width * 9 / 10;
this.Height = appSize.Height * 4 / 10;
This code modifies the sizes of the child window, but it also updates the sizes of the overlay, so that it no longer covers the whole page, which is a very strange behavior.
Has anyone encountered this kind of problems? Please share any ideas.
Thanks in advance.
I had a similar problem. It occured because scale in a browser was higher than 100%.
Related
hoping you could help me out with the sizing if my forms. on my school laptop the form fits nicely to the resolution. however, on my personal laptop, the form does not fit the larger res and for some reason is more zoomed. I have sent pictures too
You get you screen resolution with following code:
Screen.PrimaryScreen.Bounds.Width;
Screen.PrimaryScreen.Bounds.Height;
you could adjust the position from every control in the form_load event with Control.Location or the size with Control.Size depending on the width and height of your screen.
For example
label1.Location.X = Screen.PrimaryScreen.Bounds.Width - 100;
label1.Location.Y = Screen.PrimaryScreen.Bounds.Height - 50;
If you want your control to always be fullscreen, you could also add this.WindowState = FormWindowState.Maximized; in the form_load event. then its easier to adjust the positions of the controls depending on screen size.
WPF grid container, with multiple rows/columns with usercontrols loaded in the sections.
Some rows/columns are expanded/collapsed by setting the Column/Row width (from 0 to 125* or a fixed value), based upon a button click.
Simple example code:
If colgrdFolder1.Width.Value Then
Me.Width = Me.Width - colgrdFolder1.ActualHeight
colgrdFolder1.Width = New GridLength(0)
Else
Me.Width = Me.Width + 150
colgrdFolder1.Width = New GridLength(150)
End If
This works, but when the parent resizes, it flashes as the column/row is set. When the parent Width is first increased you can see the grid resize and then when the new colWidth is set, it resizes (and flashes) again.
Is there not a property/method to freeze the window/prevent redraws until the resize is complete?
I think there are BeginInit() and EndInit() methods, that should do what you want (prevent redraw), but in my experience they haven't really worked (maybe I have used them incorrectly).
I don't know of any other way of preventing redraw, perhaps someone who is more of an expert in WPF can shed some more light...
In my Silverlight project, I have a couple canvases that all use ScaleTransforms to resize as the browser window size changes. However, if I make my browser window very small, then click the maximize button in the browser, the app stays the same size. How can I make it resize properly when the maximize button is clicked?
The canvas resizes up and down properly when I am resizing the window using the edge.
Have you tried wrapping your canvas with a Viewbox?
It turns out that the delegate for a resize event was being called after the resize happens (which makes sense); but that I had some conditionals that would prohibit it from resizing if it was already 800x600. If you resized the window quickly, it would not resize properly since it thought it was 800x600; but had in fact shrunk.
tl;dr - I did not code my resize event handler correctly.
I have a borderless form (FormBorderStyle = None) with the height of 23 pixels (set in the designer)
When .NET draws my form at runtime - it draws it 38 pixels high (it adds the height of a title-bar for some reason).
MessageBox.Show(this.Height.ToString()); //this shows 38!! why?
To work it around I have to set "Height = 23;" in the Form_Load event.
private void MyForm_Load(object sender, EventArgs e)
{
this.Height = 23; //workaround. wtf??
}
You can try this yourself in Visual Studio 2010 (Winforms App, target Framework - 2.0).
Wtf?
Yeah, it is a bug, of sorts. Note how in the designer you set the size of the form with the Width and Height properties. Those properties include the size of the borders and the title bar. That's a problem however, your form may run on a machine where the user has increased, say, the title bar font size. That then would reduce the size of the window's client area. Or in other words, the form's ClientSize property would change on that machine. Leaving less room for the controls and messing up the design of your form pretty badly.
There's code inside the Form class that runs after the Handle is created, right before the Load event runs. It recalculates the Size of the form, using the same ClientSize you had on your machine. Now everything is good, the Height of the form won't match the one you set in the designer but the form otherwise looks the same and the layout of the controls is identical.
That same code also ensures that the window doesn't get too small. And that's where it falls over, it doesn't pay enough attention to the FormBorderStyle property. Clipping the height to the title bar size plus the client area height, as you found out. It also prevents the form getting too narrow, trying to make sure that the icon and min/max/close buttons are always visible. Even if you don't have any.
The workaround is to change the ClientSize after this code runs, the OnLoad override or Load event handler is the right place for that. Beware that if you hard-code the form size like this then you should also set the AutoScaleMode property to None. Make sure that this doesn't cause trouble on a machine that has a different DPI setting.
I want to create a child window that takes up all the space of the left side of main window, but its minimum width is 128 pixels. I also want it to be resizable, but only on the right edge, and makes sure that the width stays at the minimum of 128. Creating the child window with these styles: WS_EX_STATICEDGE, WS_SIZEBOX|WS_CHILD|WS_VISIBLE and handling the WM_NCHITTEST message, I can make it only resizable on the right edge. But I can't make it so the minimum width stays at 128. Can somebody tell me how to do this or if there's another window class that takes care of all this?
You must handle the messages which resize the window: WM_POSCHANGING, WM_SIZING, WM_SIZE and WM_POSCHANGED. The most important is to handle WM_SIZING for good user experience.