I have a C # WinForms application running on the .NET Framework 4.0.
When a user is inactive for a certain period of time, I want him to hide all displayed forms and show an icon in the notification area. When a user clicks on this icon, a login form appears, and if the credentials are valid, they open the exact forms that were opened before.
To do this, I save the list of open forms in objects Listfrom Formand hide them like this. This method is called by Timer :
List
Form
private void LogOut() { foreach (Form form in Application.OpenForms) if (form.Visible) { GlobalVariables.formList.Add(form); form.Hide(); } }
When the credentials are verified, I try to make the forms visible again, for example:
//Show the previous forms. foreach (Form form in GlobalVariables.formList) form.Visible = true; //Clear the forms list. GlobalVariables.formList.Clear();
MainForm , , , . ( ShowDialog() MainForm), form.Visible = true; :
ShowDialog()
form.Visible = true;
ObjectDisposedException was unhandled Cannot access a disposed object
? , , .
, try-catch , , , .
-, , 3 , !
:. , , , , ShowDialog(). Show(), .
Show()
Show() , . , .
, , . , Microsoft Winforms. , , , . , .
. , ShowDialog() , . , , , , , . , . , , , . , . . , .
, : ", , , !" , Windows, , , . , , , . , winapi.
, Winforms, , . , , , , ShowDialog(), . , , , .
, . , . , - . , , Windows. .
LockWorkStation() .
, , Hide() - . FormClosing.
Hide()
FormClosing
: ( . .)
private void button1_Click(object sender, EventArgs e) { Form1 f1 = new Form1(); f1.ShowDialog(); } private void button2_Click(object sender, EventArgs e) { Hide(); } private void Form1_FormClosing(object sender, FormClosingEventArgs e) { MessageBox.Show("Closing"); }
, , . : Visible true, . Show().
, .
, . , MSDN, :
, . , :
using (var theForm = new CreateInvoice()) { theForm.ShowDialog(); if (theForm.Updated) { GetInvoiceStatus(); } }
theForm, . , , theForm. , ShowDialog() , , , using, theForm, .
theForm
: () , (Model), . , (). -, , -, GDI, , , GDI.
, MVC MVP. .
, : , , . , .
Source: https://habr.com/ru/post/1527182/More articles:How can I set up "Reading Documents" so that the Sphinx autostart function works? - gitChange the locale of the main window after the user changes the settings in the control panel-> regional and language settings - c ++How to combine all the lines in a nested list? - listJliavalue_t value in julia source code - eclipseПравильно обрабатывайте WM_PASTE в процедуре подкласса - c++Временно скрыть модальный диалог - windowsСуммарная переменная в awk 'if condition' под 'for loop' - bashСвойство свойства свойства Python - pythonHow to iterate over messages in Hexo with Jade's own construct - node.jsRename / Delete file leaves empty file - androidAll Articles