I have a WPF window that is opening a new WPF form but in a minimized state. My issue is that when the form is minimized, it automatically shifts to the bottom of the main screen. I want it to get minimized on the same screen from where it has been called.
var MainScreen = AlertWindowPopup.GetParentWindow(obj_MediaPlayer); //This code here gives me the positon of screen
var interopHelper = new WindowInteropHelper(MainScreen);
var activeScreen = Screen.FromHandle(interopHelper.Handle);
obj_Form_PTZ.Top = activeScreen.WorkingArea.Top;
obj_Form_PTZ.Left = activeScreen.WorkingArea.Left;
obj_Form_PTZ.Show();
obj_Form_PTZ.WindowState = WindowState.Minimized;
My WPF application is running on a different screen but its minimized state is coming on the main screen
When I maximize it then it automatically opens on the correct screen because I have provided the TOP and Left coordinates to the window object. So I want help in shifting the minimized state to the original screen.
when I click the btnFullScreen it doesn't go full screen, but when I resize the mainWindow and then click btnFullScreen it goes full screen, how can I make it go full screen without resizing it first?
is there any specific reason why you are setting WindowState, WindowStyle twice?
Just use
mainWindow.WindowState = WindowState.Maximized;
mainWindow.WindowStyle = WindowStyle.None;
once And Kaboom!!! You are Done.
I have a C# winforms application with a fixed-size starting dialog. After making some changes entirely unrelated to this form, the form now opens maximized, filling the entire screen with the actual content still at the regular size in upper left corner. Dragging the title bar down a bit with the mouse causes it to restore to its appropriate size.
The form has
MaximizeBox = False
StartPosition = CenterScreen
FormBorderStyle = Fixed3D
Does anyone have any suggestions what might be causing it to open maximized, and how to stop it?
Edit:
WindowState = Normal
is also set.
Edit 2:
I found the problem. My update routine was shutting down the original process so it could be updated (inappropriately, but that is a different bug), then restarting it with code I had borrowed from elsewhere, and part of that restart code was:
process.StartInfo.WindowStyle = ProcessWindowStyle.Maximized;
Thank you for the assistance. Though no direct answer was given (nor expected with the spotty information), it did point me in the right direction.
The Window being Maximised is normally set on the forms "WindowState", Light Reading. You need this to be set to WindowState.Normal. It's possible someone's set it to maximised in the designer? or somewhere else in the code. the 3 lines of code you have shown are not the problem.
Edit:
You need to do some investigation if you cant give us code from your form, Hook into some resize events, and see what's triggered it off. Forms dont just start up maximised unless they're told to and maximizing a window triggers a resize event.
I'm developing a magnifier in C# .NET (using WindowsForm) that shows a top-most click-able through form. This top-most window shows an specific part of the screen.
The problem I'm having is that to take the screenshot I need to Hide() and Show() the form (otherwise I would take a screenshot of the magnifier) and this creates an annoying flickering in which the magnifier disappears and rapidly appears again.
How could I take a screenshot of the Desktop without hiding/showing the form?
Is there another approach/workaround?
Thanks.
Use the form's Opacity property. Set it to 99% in the designer. When you are ready to take the screen shot, set it to 0, make the shot and set it back to 0.99.
The change is instant, no need to wait and no flicker or repainting. Do not restore it to 1.0, that flickers.
Do beware that you remove the "Hall of Mirrors" effect from the magnifier. Bit of a loss :)
I have a very typical hackish solution for minimizing to system tray in C#:
private void MainFormResize(object sender, EventArgs e) {
if (FormWindowState.Minimized == this.WindowState) {
this.Hide();
systemTrayIcon.Visible = true;
}
}
private void systemTrayIconMouseDoubleClick(object sender, MouseEventArgs e) {
systemTrayIcon.Visible = false;
this.Show();
this.WindowState = FormWindowState.Normal;
}
Ideally, I want my application to disappear/reappear when minimizing to or reopening from the system tray. Minimizing to the system tray works as expected -- the window disappears with no delay and there appears a new tray icon.
Double-clicking on the icon, however, has some very strange effects. The window undergoes a resize animation to its position -- the window appears to fly in from a completely random corner of the screen.
I don't want that. I just want Minimize > -Poof- Disappear and Double-click > -Poof- Appear with no animations or delays or anything of that sort.
Why does this code have an animation? If I call Form.Show() in any other context, the window automatically appears like I want, but when called from a NotifyIcon, it acts strangely. I thought it might be the WindowState = FormWindowState.Normal line, but if I remove that, the window isn't brought to the foreground.
Edit: This problem seems to be OS and theme dependent. The problem doesn't appear to exist in Windows XP, but it's hard to tell because my virtual machine is a little laggy. In Windows 7 Aero, the abitrary-offscreen position problem occurs. In Windows 7 Basic/Classic, it minimizes to the task bar, and reappears from its old position in the taskbar (as if it was actually minimized to the task bar, not the system tray). I haven't tested on Vista. Any tips?
Did you try reordering to put WindowState = FormWindowState.Normal before Show()? I believe the animation you are seeing is the standard window restore animation. Since you are calling Show() before restoring your window, it gets an off-screen position.
Edit: I see your issue now - I looked at it for a second or so, and even tried an IMessageFilter, but for some reason couldn't trap WM_SYSCOMMAND when minimizing (although it fires on restoring).
The one easy thing you could do is live with the minimize animation, though - in your resize handler, just before the Hide() call, set WindowState to Normal. You'll see the minimize animation, but not the maximize (which on most platforms is much less noticeable).
If you need to hide the window when the program runs, your best bet is to create a class that derives from ApplicationContext and shows the NotifyIcon. You then use this class instead of form in the Application.Run.
class TaskTray : ApplicationContext
{
private NotifyIcon _Icon;
public TaskTray()
{
_Icon = new NotifyIcon();
//...
)
}
static void Main()
{
Application.Run(new TaskTray());
}
At least it is possible to have the animation originate from where it should - you have to move the minimized window near the tray notification area: see my hack here
Well, this is an old question, but it's the first result I hit when googling, so I'll share my findings, maybe someone could find this useful.
My application starts with no window showing on the desktop, only a tray icon. The main window can be shown by double-clicking on the tray icon, and closing the window will hide it to the tray icon again.
When my application is hidden, the taskbar icon is hidden as well. However, when it's shown, I have the taskbar icon shown as well, so it can be switched between other windows.
It works as intended. However, I can't help but noticing the animation when showing the window feels very strange and jerky, and it's bugging me a lot. After some digging around, I found the animation behavior is affected by ShowInTaskbar property of the form.
private void ShowMainWindow(object sender, EventArgs e)
{
//ShowInTaskbar = true; // smooth animation
Show();
//ShowInTaskbar = true; // jerky animation
}
Without the ShowInTaskbar = true; line, the window would appear instantly without any animation. Putting the line below Show(); results in the "jerky" animation. Putting the line above Show() gives a smooth fading-in animation and that's the one I choose in the end.