Preventing automatic offsetting when opening a new window - c#

In WPF, when a new Window is shown, it is offset by maybe 10 pixels horizontally and vertically. Is there an easy way to prevent this, so the window opens directly over the one that triggered it? (They are the same size - consider it similar to an installer's behavior)

You should set the WindowStartupLocation property of all windows to CenterScreen value.

You can set the Left and Top properties of the new window to be the same as the owner window.
You should do this before you call the Show or ShowDialog methods.
Good luck,
M. Moshe

Related

Scrollbars if form larger than screen

I'm needing some assistance with what I can tell a vendor developing a form in an application I don't have the source to. We've found a bug with one of their large Winforms where if it's opened in an RDP session at 1024x768, the bottom 250px or so of the form which is ~1000px high is unreachable.
They're being difficult about saying there's no solution which I know to be nonsense, but I don't have a Visual Studio environment presently set up to build a proof of concept to test for myself and then show them otherwise.
From what I can tell from other StackOverflow questions and MSDN documentation pages, something like the following should resolve the problem so the form will auto-size to the maximum displayable height then put a vertical scrollbar in to allow viewing the bottom part of the form. Will the following achieve my goal?
public MyTallForm()
{
InitializeComponent();
this.AutoScroll = true
this.AutoSize = true
}
AutoSize responds to change in controls inside the form by growing & shrinking the form as needed.
AutoScroll responds to change in controls inside the form by displaying/hiding the scrollbars.
Thus, AutoScroll won't be activated if AutoSize is active since the form is always large enough. If the problem is from too small display resolution, you'll want AutoScroll.
If the form kept open between RDP sessions, you might need to subscribe to DisplaySettingsChanged to be aware of resolution changes, and either simply Maximize (not sure if it's already maximized, toggling to Minimized and back to Maximized perhaps?) or use GetWorkingArea if you need detailed size.
Set AutoScroll = True and AutoScaleMode to Dpi In Form Properties
Hope it helps.

c# - How to arrange elements in WindowsForm like Windows Explorer

I'm populating a self-made Windows Explorer which simulate the Microsoft Windows Explorer. This is the layout of my Windows Form:
What I want it to be is:
But when I maximized the windows, it looks like this:
The problem is that the treeView's width got increased, too. How to stop that ?
Any ideas? I've tried many ways but nothing works.
Try to add a second splitcontainer around the groupbox and the splitcontainer you already have. Then set the panel at the bottom as the fixed panel.
You can set the SplitContainer.FixedPanel property to disable automatic resizing of one of the panels. This way the specified panel will remain the same width/height even when the container itself is resized.
You could use Anchoring (each control will have that in the Properties menu), and select what you want it "anchored" to. That should allow your controls to stetch to fit the form.
It can be fiddly, so you have to anchor each control and think about how to wish to set it. EG to make a control extend if you increase the height of your form, click the top and bottom anchors.

Skip Aero Window Animation

How can I disable the "opening" animation of a window under Aero programatically?
When opening a new Form it "pops in" (fade in + a slight scaling transformation).
I want to stop this animation and show the window instantly.
I already tried to set the Location property of the Form to somewhere offscreen, then calling Show(), and then moving it at its correct location.
But that doesn't help, the animation will continue.
Maybe there is some hidden property I can set?
I don't want to disable open/close/minimize/maximize animations globally!
I just want to skip the "window-open" animation of my window.
I already played around with single and multiple calls ShowWindow(...) directly after Form.Show(). But no matter what parameters I pass, doesn't abort the opening-animation.
I've got it! After some trying around with ShowWindow, BorderStyles I found my exact solution:
Change the initial "FormBorderStyle" property of the form to one of those:
None
FixedToolWindow
SizeableToolWindow
Add a eventhandler to the Forms "Shown" event.
Inside the eventhandler, change the FormBorderStyle to "Sizeable" (or any other).
Now the trick is that "none" and "*toolwindow" borderstyles will suppress the opening/popup animation for that form. Than, as soon as the form is being displayed the borderstyle is changed, giving it the original functionality (Icon in the Control-Bar, Minimize/Maximize Buttons etc...)
Edit: For everyone who might want to try this too, I have to point out that this can will screw with the actual size of the window when done with PInvoke commands.
If you rely on the size of the window being correct, be sure to resize the the window to its intended size after you done this.
This is part of windows visual effects and can be adjusted using the SystemParametersInfo Method.
I found that the animation is only take place when the form is shown for the first time.
So here is the trick:
var form = new Form();
form.Show();
form.Hide();
form.Show();
I tested it only in Windows 8
You can change the style before and after, like this, which will prevent the fade-out animation.
this.FormBorderStyle = FormBorderStyle.Sizable;
this.Show();
// Do whatever
this.FormBorderStyle = FormBorderStyle.Sizable;
this.Show();

how to show complete window when screen resolution changed C#

I have a WinForm,when the its size is 700x700,when I change the screen resolution of the system from 1366x768 to other(like 800x600),only part of the window is visible.How can I make it fully visible? what property of the form i have to change?
I would say would say you want to adjust your Form.Size and Form.Location to fit within the Screen.GetWorkingArea(). You will want to do that when the event Microsoft.Win32.SystemEvents.DisplaySettingsChanged is fired. As in this answer.
You will want to adjust the Bounds property of your form. Screen.PrimaryScreen can support you to get the new right size.

WPF windows position

I need help on WPF...
When user move/drag/change the position of the 1st page window (mainwindow.xaml), then user click on "next" button to proceed to 2nd page(process.xaml), the window (process.xaml) is not at the same position as the (mainwindow.xaml) that the user move to earlier on. How can I make it to remember the position of the window throughout? And when user close the window, and run it again, the window will be default appear in the center unless user move the window.
Really need help for this. Thanks.
Maybe it would be easiest to only have one window throughout the whole application, but replace the window's contents? Create your screens as usercontrols instead, then set content on the main window instead of opening a new one..
You might want to make use of the WindowStartupLocation for process.xaml.
Setting WindowStartupLocation to Manual causes a window to be positioned according to its Left and Top property values. If either the Left or Top properties aren't specified, their values are determined by Windows.
Like this:
this.Owner = MainWindow; // reference to mainwindow.xaml
this.Left = Owner.Left;
this.Top = Owner.Top;
this.WindowStartupLocation = WindowStartupLocation.Manual;

Categories