2

I have a windows form running a thread which reads a string and showing it in text boxes.

It has start - stop buttons to start showing words in the text boxes within the window Main_Form.

now, i need to create an opening form that handle the start stop. when you press start the same thing should happen, but Main_Form could be closed

you have a button to open the Main_Form and see the text boxes change

it only works when i type:

m_mf = new Main_Form();
m_mf.Show();
m_mf.start();

if i type

m_mf.Visible = false;

or close the Main Form window the program kills itself

Rudi Visser
  • 21,350
  • 5
  • 71
  • 97
ro-E
  • 279
  • 1
  • 5
  • 16
  • 1
    Setting `Visible` should not cause the program to close unless you are trying to do that from within a new thread (in which case you 'd get an exception). Are you? – Jon Feb 13 '13 at 10:15
  • hi jon, i don't want to close the program. i want the thread within `Main_Form` to run, nevertheless the window is shows or not. i have a button in the `Opening_Form` show to the `Main_Form` – ro-E Feb 13 '13 at 10:23
  • That's what I 'm saying. **`Visible = false` does not close the program either.** If your program closes that is because **you have a bug somewhere**. The bug might be that you are setting `Visible` from another thread. – Jon Feb 13 '13 at 10:25
  • if i type `m_mf.Hide();` the program works, but it's not nice because the window appears and disappears. so my question is there a way to works with the text boxes (what `Main_Form` does) without having the window appear thank you for you answers! – ro-E Feb 13 '13 at 10:28

2 Answers2

1

Have you tried using Hide() rather than visible = false:

m_mf.Hide();

If you use m_mf.Close(); that will completely close the program.

This article might help you a little.

Kobunite
  • 365
  • 8
  • 23
  • `Hide()` is exactly the same as setting `Visible = false`. It's in the [documentation](http://msdn.microsoft.com/en-us/library/system.windows.forms.control.hide.aspx): *"Hiding the control is equivalent to setting the Visible property to false"* – Jon Feb 13 '13 at 10:16
  • actually m_mf.hide() works! but is there a way to make it work without showing the window popping? – ro-E Feb 13 '13 at 10:18
  • 1
    Maybe this helps? http://stackoverflow.com/questions/1730731/how-to-start-winform-app-minimized-to-tray – Thorsten Dittmar Feb 13 '13 at 11:15
0

Do you mean to run a new form after m_mf is close, in your main function you can modify it as follows:

 Application.Run(new m_mf());
 Application.Run(new Form1());
Igoy
  • 2,942
  • 22
  • 23
  • hi, I don't want to run 2 programs, i want to run only run program. in the program.cs i want to leave it `Application.Run(new Opening_Form());`, and when pressing start in the `Opening_Form` to have the `Main_Form` thread running – ro-E Feb 13 '13 at 10:31