C# set location of a minimized form - c#

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

Related

How to fill MDIForm with default content in c#?

I have created MDIForm that contains some child forms. Now i want to load some default content in MDIForm because without any content it is not looks good while opening MDIForm just like
.
When i tried to make some contents in MDIForm then the child form are behind the controls like
.
I tried load a child form in MDIParent form but it occurs some issues like i set form border style none, but it display minimize, maximize and close buttons. It affects on my designing & controls position too, but i can manage it using dock/anchor but the problem is form border style(as you can see in image2).
So please someone tell me that what is the right way to do this?
I hope you understand what i want to say. If you have doubt then you can ask me about that.

Showing a modeless form's 'title bar' inside the parent form when it's minimized

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.

How to show multiple form pages in single windows form application?

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

WPF modal window as tool window in WinForms disappears

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.

A modal form with a parent form as background

How can I have a black form as a background and some modal forms opened one at a time whose owner is the black form? I need these two to retain their order together (when minimized and maximized) that's why I have chosen the modal form.
I have made a simple main form with black background, and opened a form in dialog (modal) form. The main form provides a black background for me and the modal form stays in front of the black background. But when opening new forms, I can't set the owner of new modal form to the aforementioned black form. I have tried passing the black form object and also registering events to no avail.
Do you know any mechanism to implement the following scenario:
A black form as a background and a series of modal forms opened one at a time in front of the black one in a way that the black form is the owner of every modal form.
Thanks
Edit
Please consider this scenario: I have 3 forms named frmBlack, Form1 and Form2. I use frmBlack as the main blacked form. After placing a button on this form I call the Form1Object.ShowDialog(this). Now suppose that I want to navigate to the third form (Form2), [this means that I must close the Form1Object] I put a button on the second form (Form1) and when this button is pressed I must close the Form1 object and navigate to the Form2Object while its owner in the ShowDialog() function must be set to frmBlack.
This is done using MDI Forms.
Your application will look like this: http://www.datadynamics.com/Help/AB3/Images/MDI%20Child%20menu.gif
This works in winform projects, not in WPF project (at least not by default).
Parent or Owner? That's a difference. Parent is only used in MDI-Applications (see Luigi's post). The owner can be set in the call to ShowDialog( owningForm ).
What is it that you want to achieve?
hth
Mario
To achieve what you want from the window with the second button post pack to the frmBlack and let it do the work.
Or more specifically set a flag within the frmBlack, since in frm1.btnShowNextForm you need to close frm1...
And also take a look at Form.Owner
so something along these lines in frm1.buttonShowNextFormClicked()
{
if ( null != Owner )
{
FrmBlack frmBlackLocal = Owner as FrmBlack;
if ( null != frmBlackLocal )
{
frmBlackLocal.NextAction = FrmBLack.NextActions.ShowForm2; //an enum
}
}
Close();
}
and in frmBlack
{
frm1.ShowDialog(this);
if ( NextAction == NextActions.ShowForm2)
{
frm2.ShowDialog(this);
}
}
Well, of course it needs some brush-up (like extracting the next handler in a function of it's own, but you should get the idea.
hth
Mario

Categories