Click here to Skip to main content
15,909,741 members
Home / Discussions / C#
   

C#

 
AnswerRe: Struggling to find a suitable data structure Pin
Gary R. Wheeler26-Apr-09 0:30
Gary R. Wheeler26-Apr-09 0:30 
Questionblock the keyboard few keys when my system running on the PC Pin
Ravenet25-Apr-09 23:20
Ravenet25-Apr-09 23:20 
AnswerRe: block the keyboard few keys when my system running on the PC Pin
Christian Graus26-Apr-09 1:34
protectorChristian Graus26-Apr-09 1:34 
GeneralRe: block the keyboard few keys when my system running on the PC Pin
Ravenet26-Apr-09 2:21
Ravenet26-Apr-09 2:21 
QuestionWeb broswer control and Page Content element event in Windows Forms Pin
Ravenet25-Apr-09 22:58
Ravenet25-Apr-09 22:58 
Questionerror:cannot access disposed object Pin
shefa' isied25-Apr-09 22:47
shefa' isied25-Apr-09 22:47 
AnswerRe: error:cannot access disposed object Pin
DaveyM6925-Apr-09 22:53
professionalDaveyM6925-Apr-09 22:53 
AnswerRe: error:cannot access disposed object Pin
Moreno Airoldi26-Apr-09 0:40
Moreno Airoldi26-Apr-09 0:40 
By what you say I suppose you have a reference in Form1 to Form2, something like:

C#
class Form1 : Form
{
    ...
    Form2 RefToForm2 = new Form2();
    ...
    private void ButtonToShowForm2_Clicked(...)
    {
        RefToForm2.Show();
    }
    ...
}


Now, as Dave said in his answer, you can use e.Cancel = true to avoid automatic disposal of Form2, but I think you should first consider if you need your instance of Form2 to stay in memory or you can simply create a new instance every time you need to show Form2. The latter is usually the best practice.

So, if you store some value in Form2 and you don't want to lose it, you should store it somewhere else and recover it when you load Form2. Then, you can simply do:

C#
class Form1 : Form
{
    ...
    private void ButtonToShowForm2_Clicked(...)
    {
        Form2 RefToForm2 = Application.OpenForms["Form2"];
        if (RefToForm2 == null) RefToForm2 = new Form2();
        RefToForm2.Show();
        RefToForm2.Activate();
    }
    ...
}


Or something similar.

Hope this can help. Smile | :)

2+2=5 for very large amounts of 2
(always loved that one hehe!)

QuestionInstalling Visual Studio.NET 2008......Help needed! Pin
Rajdeep.NET is BACK25-Apr-09 20:20
Rajdeep.NET is BACK25-Apr-09 20:20 
AnswerRe: Installing Visual Studio.NET 2008......Help needed! Pin
DaveyM6925-Apr-09 22:07
professionalDaveyM6925-Apr-09 22:07 
GeneralRe: Installing Visual Studio.NET 2008......Help needed! Pin
Rajdeep.NET is BACK25-Apr-09 23:26
Rajdeep.NET is BACK25-Apr-09 23:26 
GeneralRe: Installing Visual Studio.NET 2008......Help needed! Pin
harold aptroot26-Apr-09 3:05
harold aptroot26-Apr-09 3:05 
Questionuse dll in net2008 Pin
ZAHEDI_HOSSEIN25-Apr-09 19:16
ZAHEDI_HOSSEIN25-Apr-09 19:16 
AnswerRe: use dll in net2008 Pin
DaveyM6925-Apr-09 19:35
professionalDaveyM6925-Apr-09 19:35 
QuestionVideo chat... first one but does it look ok? Pin
Jacob Dixon25-Apr-09 18:25
Jacob Dixon25-Apr-09 18:25 
QuestionImplementing WPF in a Visual C# project........ is it possible? Pin
Rajdeep.NET is BACK25-Apr-09 16:34
Rajdeep.NET is BACK25-Apr-09 16:34 
AnswerRe: Implementing WPF in a Visual C# project........ is it possible? Pin
Sibugathulla25-Apr-09 17:10
professionalSibugathulla25-Apr-09 17:10 
GeneralRe: Implementing WPF in a Visual C# project........ is it possible? Pin
Rajdeep.NET is BACK25-Apr-09 19:58
Rajdeep.NET is BACK25-Apr-09 19:58 
QuestionError in declaring a bitmap as the .image of a picture box Pin
sebogawa25-Apr-09 15:33
sebogawa25-Apr-09 15:33 
AnswerRe: Error in declaring a bitmap as the .image of a picture box Pin
Sibugathulla25-Apr-09 17:19
professionalSibugathulla25-Apr-09 17:19 
QuestionRe: Error in declaring a bitmap as the .image of a picture box Pin
sebogawa25-Apr-09 21:00
sebogawa25-Apr-09 21:00 
AnswerRe: Error in declaring a bitmap as the .image of a picture box Pin
Christian Graus25-Apr-09 22:57
protectorChristian Graus25-Apr-09 22:57 
GeneralRe: Error in declaring a bitmap as the .image of a picture box Pin
sebogawa25-Apr-09 23:03
sebogawa25-Apr-09 23:03 
AnswerRe: Error in declaring a bitmap as the .image of a picture box Pin
Luc Pattyn26-Apr-09 0:48
sitebuilderLuc Pattyn26-Apr-09 0:48 
Question[Message Deleted] Pin
Mohamed Ibrahim Omar25-Apr-09 11:22
Mohamed Ibrahim Omar25-Apr-09 11:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.