I was wondering if anyone can help me with this rather baffling situation. I have a WPF form myForm which I am displaying modally in a WinForm application (without using an ElementHost). Everything works fine if I use the default WindowStyle and it is shown in the taskbar. However now I don't want the form to show in the taskbar or contain the minimize button, therefore I have done the following:
MyForm myForm = new MyForm();
myForm.ShowInTaskbar = false;
myForm.WindowStyle = System.Windows.WindowStyle.ToolWindow;
myForm.WindowStartupLocation =System.Windows.WindowStartupLocation.CenterOwner;
myForm.ShowDialog();
Now, the wpf form displays as expected modally and without the minimize button. If I now select the "parent" winform application in the taskbar, the wpf form disappears and there doesn't seem to be any way of returning to it! I have read this which is similar but not the same (pure WPF application), so I can understand why the main app does not appear in the ALT+TAB menu, but can anyone tell me how I can return to the wpf form?
Thanks in advance.
The use of WindowsInteropHelper allows you to wrap a hosted WPF-form using a Winforms-form and set its parent as a Winforms control, which prevents the WPF form from disappearing (as also pointed out by dowhilefor and Hans Passant)
E.g.:
// Use the interop helper for the specified wpf window hosted by the win32 owner
WindowInteropHelper wih = new WindowInteropHelper(wpfForm);
wih.Owner = this.someWin32FormsControl.Handle;
This is not related to Winforms or WPF, this is the way Windows functions. The only solution that I think you have is to wire up your modality; that is intercept the Activated event on your Winforms form and if your WPF tool window is visible, bring that window forward and give it focus.
Related
We have a simple Windows Forms application that will run in a Windows tablet. What we have so far is running well; the issue I'll be having is moving from winform to winform, and opening/closing Forms.
Currently, it looks something like this.
The following opens the main Form FormHome:
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new FormHome());
}
A click in button from FormHome will then open a new Form call FormInput:
var form = new FormInput();
form.StartPosition = FormStartPosition.CenterParent;
form.ShowDialog();
A click in FormInput will open yet another Form, FormFeedback:
var form = new FormFeedback(patientInputId);
form.StartPosition = FormStartPosition.CenterParent;
form.ShowDialog();
And finally, FormFeedback will open one last final Form, FormThanks:
var form = new FormThanks();
form.StartPosition = FormStartPosition.CenterParent;
form.ShowDialog();
FormThanks doesn't do anything; it just thanks the user and has a Close button. This means that this Close button will close FormThanks, FormFeedback, FormInput, so that the only Form I'll be seeing is FormHome.
Except for closing the winforms, everything else is working fine. But when I see the Forms that need to be opened/closed, I'm thinking that maybe it's better to use another architecture instead of the regular Windows Forms.
I was reading this SO link and someone suggests to use an MDI containter and replace with panels instead. But my first thought is that I'll be seeing the FormBorder of the MDI container, plus the FormBorder of the child Form.
What are your thoughts? Should I switch to another architecture or just find a way to close all those Forms?
Thanks.
You could try the .hide property. This will hide the forms you don't want to see and then you can use the .show to bring the ones you want forward. I hope i'm helping
I'm trying to implement some complement views inside my application and I would like to have a better layout control over them. I don't know how to explain in words what my desired functionality is, so I made it through with some photoshop help, hoping you could give me a hand to implement it.
My application now looks like this:
(i need reputation to post images so.. sorry for the links)
http://i59.tinypic.com/2ikv8m1.jpg
When I minimize the modeless form which is focused in the previous image, I would like to be able to see it (and handle it to maximize or close) inside my main form as I show in the image below (made it in photoshop)
http://i58.tinypic.com/1e28go.jpg
Hope someone can lead my into a solution and thanks for the support.
EDIT: I need to be able to move that form outside my main form, even to a different monitor.
If you don't want to use the MDI approach, then set TopLevel of the modeless Form to false and add it to the main Forms Controls collection before showing it:
Form frm = new Form();
frm.TopLevel = false;
this.Controls.Add(frm);
frm.Show();
*Obviously changing Form to the correct type of your modeless form.
If i understand what you are trying to do, you want to minimize a certain form but still see it within your app (im assuming like Excel or Word)
You can do something similar to what Idle_Mind said, but enclose both in a Form instead of the parent.
Form fParent = new Form();
fParent.Dock = DockMode.Fill;//i think this is the syntax. Use this if you want the form to fill to the screen
Form fChild = new Form();
fChild.TopLevel = false;
fParent.Controls.Add(fChild);
fChild.Show();
Here, it should minimize to the lower left part of the parent form. You can then size the parent to whatever you want it to be.
I have got a requirement to design a windows forms application using Visual Studio 2010.
According to the design I have to develop the application which contains a menu bar. On selecting of the menus from the Menu bar relevant forms should open. Now as per my requirement these menu forms should be displayed in the same parent Windows Form. Means everything should be in the single form Application.Nothing should be out of that.
The problem that I'm facing is that I don't know how to proceed with this. This is the first time I'm working on Windows Form Application leaving Web.
You are looking for developing an MDI application. MSDN article to guide you - http://msdn.microsoft.com/en-us/library/xyhh2e7e(v=vs.100).aspx
You could build a grid area on your form using a combination of split containers (horizontal and vertical).
Then in separate panels design each of your menu forms, with each panel visibility set to false.
When choosing a menu you would need to assign a parent (split container panel) to the menu form and set it to visible.
Step 1
Create a form and give the name it to "mdiMain" and set the property IsMdiContainer to true.
Add a MenuStrip control from the ToolBar and add some menues.
Step 2
Create another form and give the name it to "frmChild"
Step 3
Write some code in menu click event to display frmChild form in MDI Parent.
Dim frm As New frmChild()
frm.MdiParent = Me
frm.Show()
Now your application is ready. You can place your code and control in frmChild window form.
As an option in some cases you can use WebBrowser control and manipulate html code inside depending on the menu bar selection.
http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser%28v=vs.110%29.aspx
I have a little problem with my MDI Parent Window and the MDI Childs window. The problem is that i need 3 child window but only the first it'll be maximize, so i use this code:
UserAdmin usrWindow = new UserAdmin();
usrWindow.MdiParent = this;
usrWindow.WindowState = FormWindowState.Normal;
usrWindow.Show();
For the others 2 windows i use this code:
TaskAdmin tskWindow = new TaskAdmin ();
tskWindow.MdiParent = this;
tskWindow.Show();
I only need that the first windows is maximized, but when i open the others they open maximized too.
How can i do to open one maximized and others in the default size over the first?
Thanks
That is not possible, yet can be achieved with very very tricky (using WndProc override, custom event loops) and ugly code which will not work in different operation systems in the same manner (i.e WinXP/WinXPSP1/WinXPSP3/Vista/Win7)
Your TaskAdmin forms cannot have an MDIParent in this situation. You need to either float these forms over the MDIParent or place them in panels in the MDIParent, docked to a side.
I am developing an application in C#. I have a Main Form where I have some buttons that give the user the possibility to start a new form into the Main Form.
When there are more of this kind of forms opened and the user choose to minimize one, it goes to back behind all opened forms. So if the user would want to open again that form he must close/minimise all forms.(for beeing able to see the minimized one)
How can I manage the minimised form location so it could be visible after it is minimised? I tried without any result stuff like that: bringToFront, Activate, Focus, etc.
My Main Form contains the buttons and a panel, so the forms are opening in the panel bellow the buttons.
why don't you go for MDI win-form ? I think they fit really well in what you are trying to achieve
http://msdn.microsoft.com/en-us/library/ms973874.aspx
Finally I did managed myself to solve the problem. It was so simple.
For the forms that opens in the panel child I removed
formName.Dock = DockStyle.Fill;
and I set the formName.Height = panelContainer-25; So now the little form minimized is visible.
I know this is late post but might be useful for someone like me.
Try this this was working for me to set minimized window location and size as well
https://social.msdn.microsoft.com/Forums/windows/en-US/d6014e48-2adb-4096-8bea-94c2f3b1c47c/how-to-change-the-location-of-a-minimized-mdichild-form?forum=winforms