IgnaceMaes / MaterialSkin

Theming .NET WinForms, C# or VB.Net, to Google's Material Design Principles.
MIT License
2.91k stars 841 forks source link

Form Closing Problem #264

Closed manusoft closed 1 year ago

manusoft commented 3 years ago

I have two forms in my project frmContactList and frmContact. When I start the program it will show frmContact then i will click Create button to show frmContact. The problem is when I close frmContact form, it will close all forms. How can I fix this.

falcomus commented 3 years ago

Change method "TerminateOnClose" in "MaterialForm.cs" (~ at Line 651]

Before:

    private void TerminateOnClose(object sender, FormClosedEventArgs e)
    {
        Application.Exit();
    }

After:

    private void TerminateOnClose(object sender, FormClosedEventArgs e)
    {
        if (Application.OpenForms.Count > 0  && this == Application.OpenForms[0])
            Application.Exit();
    }

This will fix this problem.

falcomus commented 3 years ago

or shorter:

//Close application only if only one form is open (the MainForm

if (Application.OpenForms.Count == 1) Application.Exit();

jmelendezdev commented 2 years ago

Another native option is:

if (ActiveMdiChild != null) Application.Exit();

manusoft commented 1 year ago

Thank you all. @falcomus
@jmelendezdev

benjachiban commented 10 months ago

where do I find that file? because when installing through nuget, it only finds *.dll files i use vb.net, not C

falcomus commented 10 months ago

Hello, you can download the source code here:https://github.com/IgnaceMaes/MaterialSkin Don't know if there are VisualBasic sources available, if you can't find it - maybe you can convert the C# files with a VB to C# converter.I did a conversion from VB to C#, it worked like a charm. Ithink it should work in both directions.

If you have the sources, embed the project in your solution and add a reference to this project in your main project.

falcomus commented 10 months ago

https://marketplace.visualstudio.com/items?itemName=SharpDevelopTeam.CodeConverter