A modal form with a parent form as background - c#

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

Related

Devexpress Winforms - Forms are fractured while transition one form to another

I am using Devexpress winform for my project. There are three forms simply. The first is MainForm that used MdiParent, the second is FormArticles that used listing articles about law into GridControl. And the last is FormArticleView that used viewing selected article into pdfViewer control. I managed to use documentManager and SplashScreenManager while loading Mdi Child forms and articles into one of Mdi Child form FormArticles. Here is my code:
public prjLibrary()
{
InitializeComponent();
var frm = new FormArticles{ MdiParent = this, Dock = DockStyle.Fill };
frm.Show();
}
While transition one form to another, the forms is fractured and after load it is fixed. Here is my screenshot:
And here is fixed view:
How can I fix fractured view while transition of forms?
This is because when the form from the first screenshot is getting focused, the controls have to be rendered in their Paint-event. This seems to take some time but you can see the fractured text is shown in rectangles where I think the underlying controls (radio buttons, text boxes, labels) are placed. So they are not rendered yet and not ready to go while any other call is blocking the thread. I think the problem is that you create a new form in your mainForm's constructor.
Anyway, it is a good practice to perform heavy tasks (which seem to block the painting of your controls) in a background thread having the UI waiting for the response. If this is too hard to do, try to do it after the UI is shown to the user. This could be the OnLoad- or even OnShown-event.
Note that I don't want to encourage you to write any business code into the UI layer but that seems not to be the question here.

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 make form always on top in Application

I have a form that i want to always be on top whenever it is opened in the application but i dont want it to be on top when the main form is minimized or another application is navigated. I want it to be on top only in my application.
Following the answer in the question : How to make a window always stay on top in .Net?
this.TopMost = true;
Makes the form on top but the form is still on top when another application is navigated to or the main form is closed.
Pls how do i make the form only on top in the application while enabling user to still work on the main form?
You are looking for an owned window. It is always on top of the owner and it gets minimized along with the owner. Good examples of owned windows are the various helper windows inside Visual Studio. You can undock them but they'll always stay on top of the VS main window.
You create an owned window by displaying it with the Show(owner) overload. Or by explicitly assigning its Owner property.
Set the top level and then set the owner, example below.
public Form1()
{
InitializeComponent();
Form2 f2 = new Form2();
//top level not really needed
f2.TopLevel = true;
f2.Show(this);
}

C# set location of a minimized form

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

Display one form and return text to another - Java

I have an application in C# that I am converting to Java, specifically the C# version consists of a Windows Form (Main Form) that spawns a new form (Secondary Form) via the ShowDialog() method.
The event handler for a button (OK) on the Secondary form sets it's DialogResult to OK when clicked, therefore in the Main Form I can check what DialogResult was set and retrieve data from the Secondary Form instance through properties.
I'm using SwingUI with NetBeans and I was wondering how I would go about implementing the same functionality in the Java application.
An example:
The Box to be displayed (Secondary Form):
The behaviour for the Secondary Form:
Then a simple piece of code in the Main Form to get the results:
As you can see it doesn't really take a lot of effort to achieve this in C#, how big of a task would it be to do it in Java?
Thanks for your time.
A dialog that returns a String:
String s = (String)JOptionPane.showInputDialog(
frame,
"Complete the sentence:\n"
+ "\"Green eggs and...\"",
"Customized Dialog",
JOptionPane.PLAIN_MESSAGE,
icon,
possibilities,
"ham");
Taken from the Swing Dialog tutorial. You can create a more complex dialog by subclassing the JDialog class and creating accessor methods to get the data.

Categories