hi
with visuial studio c# i'm doing
form include another forms
the basic form contain #of buttons if button click basic form hide and new one open
all that is ok
the problem:
if any form (basic or others)
closing by (x) in the bar the form close but it still running
does not actually close
iwant solution please by remove bar or another sugguest one.:-/
help me please :icon_smile:

you can use javascript to stop user from doing what you dont want.

i.e. disable close button of browser.

"does not actually close"
i mean that form is closed but if i try to change code in visuial studio
give error because the form is opened by another prossece

"does not actually close"
i mean that form is closed but if i try to change code in visuial studio
give error because the form is opened by another prossece


how i can do it by java script?

This means that the application is not closing down and is probably due to the main form being hidden.
When you hide your basic form it is not closed.
When you click on the (x)close button of the other form it closes but I suspect that the main form is not being shown again.

Because you do not want user access to the main form (and therefor hide it) you could use the ShowDialog() method to show your other forms. That way, when the other form closes, control will pass to just after the ShowDialog and you can make your basic form visible again.

This code snippet should give you an idea of what I mean.

button1_Click(...)
{
    this.Hide();
    Form2 form = new Form2();
    form.ShowDialog(this);
    this.Show();
}

thank you for help me
but the soloution is not effective
on x click same form return another click same form close and the hidden still work
how i can disable (x) from the Form(not basic)

thank you for help me
but the solution is not effective
on x click same form return another click same form close and the hidden still work
how i can disable (x) from the Form(not basic)

To remove the buttons on the title bar of a form set the ControlBox property to false.
However, if you do this then you must make sure that you have some other coding method to close the form.
E.g. a button on form that executes this.Close();

i do that
disable x and but button return to the basic form
but still the same problem

give me another solution :(

Hmmm. You said

give error because the form is opened by another prossece

How are you starting your app?

Also, post me the code for the buttons that open the other forms so I can see what you are doing.

sorry for late;

add a = new add();
            a.Show();
            this.Hide();

some time open form from debug(not open visuial)then close it by x
then open from visuial
if i try to rebuild give error because it opend by anothe app.

Try changing the code to this

add a = new add();
            this.Hide();
            a.ShowDialog(this);
            this.Show();

Also, what do you mean by "open from visuial"?

Edited 6 Years Ago by nick.crane: n/a

I mean open visuila
file>>open>>windowa appl.

perviouse try this code not good

This code worked for me.

public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnShowForm2_Click(object sender, EventArgs e)
        {
            Form2 frm = new Form2();
            this.Hide();
            frm.ShowDialog(this);
            this.Show();
            this.BringToFront(); //<-- Try adding this too
        }
    }
public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }

ok it's
play
but there is another problem:(
i have more than button each one open new form
the pervious method good with only one button the other buttons open new basic form

Use a function like this

private void btnShowForm2_Click(object sender, EventArgs e)
        {
            OpenForm(new Form2());
        }

        private void OpenForm(Form form)
        {
            this.Hide();
            form.ShowDialog(this);
            this.Show();
            this.BringToFront();
        }

thank you very very much

i hope help you if you need me

good luck and thank you again
solved

This question has already been answered. Start a new discussion instead.