- Form. Close Метод
- Определение
- Исключения
- Комментарии
- How to close the windows form
- Answered by:
- Question
- Answers
- All replies
- How to close the windows form
- Лучший отвечающий
- Вопрос
- Ответы
- Все ответы
- How to close one FORM from another FORM in C# Winform Application
- 4 Answers 4
- Not the answer you’re looking for? Browse other questions tagged c# winforms forms or ask your own question.
- Linked
- Related
- Hot Network Questions
- Subscribe to RSS
- c# open a new form then close the current form?
- 15 Answers 15
Form. Close Метод
Определение
Закрывает форму. Closes the form.
Исключения
Форма была закрыта при создании дескриптора. The form was closed while a handle was being created.
Нельзя вызывать этот метод из события Activated, если свойство WindowState задано как Maximized. You cannot call this method from the Activated event when WindowState is set to Maximized.
Комментарии
При закрытии формы все ресурсы, созданные в объекте, закрываются, и форма удаляется. When a form is closed, all resources created within the object are closed and the form is disposed. Можно предотвратить закрытие формы во время выполнения, обрабатывая Closing событие и установив Cancel свойство объекта, CancelEventArgs переданного в качестве параметра обработчику событий. You can prevent the closing of a form at run time by handling the Closing event and setting the Cancel property of the CancelEventArgs passed as a parameter to your event handler. Если закрываемая форма является начальной формой приложения, приложение завершается. If the form you are closing is the startup form of your application, your application ends.
Два условия, когда форма не удаляется Close , имеет значение, если (1) она является частью приложения с многодокументным интерфейсом (MDI), а форма не видна, и (2) форма была отображена с помощью ShowDialog . The two conditions when a form is not disposed on Close is when (1) it is part of a multiple-document interface (MDI) application, and the form is not visible; and (2) you have displayed the form using ShowDialog. В таких случаях необходимо вручную вызвать, Dispose чтобы пометить все элементы управления формы для сборки мусора. In these cases, you will need to call Dispose manually to mark all of the form’s controls for garbage collection.
How to close the windows form
This forum has migrated to Microsoft Q&A. Visit Microsoft Q&A to post new questions.
Answered by:
Question
I am working in visual studio C# 2005.
I have written a client socket program. After closing the client connection. I want to shutdown the form.
In VB if you put down «end» the form closes and so does the program.
But when i put down form.close();
the ‘close’ does not come in popup menu at all.
where am i going wrong
Answers
I guess you could try
this .Close() or Application .Exit()
this.Close() should be what you wanted.
All replies
You wanted to place a confirmation for the form close I guess..sorry if i misunderstood your question.
I guess you could try
this .Close() or Application .Exit()
this.Close() should be what you wanted.
hi, how are you guys ? every thing is fine ?
I am working on Sockets on both Server and clients sides,
so, I think the best thing to do for this situation is to do the following:
1 — It would best to make a confirmation message box for closing.
2 — shutdown all the Sockets the you initialized before closing the application.
3 — Finally, just close the application.
notice that step 2 is the most important in this process, since that if you didn’t shutdown the Socket it most of the time couse the application to not response.
How to close the windows form
Лучший отвечающий
Вопрос
I am working in visual studio C# 2005.
I have written a client socket program. After closing the client connection. I want to shutdown the form.
In VB if you put down «end» the form closes and so does the program.
But when i put down form.close();
the ‘close’ does not come in popup menu at all.
where am i going wrong
Ответы
I guess you could try
this .Close() or Application .Exit()
this.Close() should be what you wanted.
Все ответы
You wanted to place a confirmation for the form close I guess..sorry if i misunderstood your question.
I guess you could try
this .Close() or Application .Exit()
this.Close() should be what you wanted.
hi, how are you guys ? every thing is fine ?
I am working on Sockets on both Server and clients sides,
so, I think the best thing to do for this situation is to do the following:
1 — It would best to make a confirmation message box for closing.
2 — shutdown all the Sockets the you initialized before closing the application.
3 — Finally, just close the application.
notice that step 2 is the most important in this process, since that if you didn’t shutdown the Socket it most of the time couse the application to not response.
How to close one FORM from another FORM in C# Winform Application
I’m working on C# winform application, in that I want to close one form from the another form i.e. I have 2 forms Form1 and Form2 and I want to close Form2 from Form1 for that I have written following code on button click event of Form1, but I’m getting the following exception-
«Object reference not set to an instance of an object.»
4 Answers 4
For future readers!
You can use the following code to close one FORM from another FORM in C# Winform Application.
Those 2 lines of code are self-explanatory!
ActiveForm returns «Currently active form from this application» = Form you clicked. How you start your Form2? I think you should define it like
Than you can just call close()/Dispose/Hide by calling
See MSDN -> Form.ActiveForm Property
If your application is a multiple-document interface (MDI) application, use the ActiveMdiChild property to obtain the currently active MDI child form.
I think you need a void in your MDI-Form like
Hope I could help 🙂
Not the answer you’re looking for? Browse other questions tagged c# winforms forms or ask your own question.
Linked
Related
Hot Network Questions
Subscribe to RSS
To subscribe to this RSS feed, copy and paste this URL into your RSS reader.
site design / logo © 2021 Stack Exchange Inc; user contributions licensed under cc by-sa. rev 2021.4.16.39093
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.
c# open a new form then close the current form?
For example, Assume that I’m in form 1 then I want:
- Open form 2( from a button in form 1)
- Close form 1
- Focus on form 2
15 Answers 15
Steve’s solution does not work. When calling this.Close(), current form is disposed together with form2. Therefore you need to hide it and set form2.Closed event to call this.Close().
Many different ways have already been described by the other answers. However, many of them either involved ShowDialog() or that form1 stay open but hidden. The best and most intuitive way in my opinion is to simply close form1 and then create form2 from an outside location (i.e. not from within either of those forms). In the case where form1 was created in Main , form2 can simply be created using Application.Run just like form1 before. Here’s an example scenario:
I need the user to enter their credentials in order for me to authenticate them somehow. Afterwards, if authentication was successful, I want to show the main application to the user. In order to accomplish this, I’m using two forms: LogingForm and MainForm . The LoginForm has a flag that determines whether authentication was successful or not. This flag is then used to decide whether to create the MainForm instance or not. Neither of these forms need to know about the other and both forms can be opened and closed gracefully. Here’s the code for this: