Click here to Skip to main content
15,914,820 members
Home / Discussions / C#
   

C#

 
AnswerRe: Close UserControl Pin
Christian Graus10-Jun-07 13:12
protectorChristian Graus10-Jun-07 13:12 
Questiondatagrid Pin
md_refay10-Jun-07 10:59
md_refay10-Jun-07 10:59 
Questionsingelton problem Pin
akkram10-Jun-07 6:47
akkram10-Jun-07 6:47 
AnswerRe: singelton problem Pin
Luc Pattyn10-Jun-07 6:51
sitebuilderLuc Pattyn10-Jun-07 6:51 
GeneralRe: singelton problem Pin
akkram10-Jun-07 7:01
akkram10-Jun-07 7:01 
GeneralRe: singelton problem Pin
Luc Pattyn10-Jun-07 7:23
sitebuilderLuc Pattyn10-Jun-07 7:23 
GeneralRe: singelton problem Pin
akkram10-Jun-07 7:47
akkram10-Jun-07 7:47 
GeneralRe: singelton problem Pin
Luc Pattyn10-Jun-07 8:17
sitebuilderLuc Pattyn10-Jun-07 8:17 
Hi,

from your code it is apparant you implemented a singleton: initially there
is no instance of Form2; once you call Form2.Instance, there is exactly one.
If you call Form2.Instance again, you get the same instance.
This is not what you want for two reasons:
- if you close the "first" Form2, it renders all future Form2 instances useless
since you can close a Form only once
- it does not prevent you from calling Form.Show() twice.

What you need instead is no singleton logic; just create a Form2 when you need one; use it; get rid of it with Close(). And add some logic to prevent two Form2
instances to coexist; possible solutions are:
- disable the button while a Form2 is visible (best, user can see it!)
- or include a test in buttonClick, something like:

private Form2 lastForm2; // class member

if (lastForm2==null || !lastForm2.Visible) {
    lastForm2=new Form2();
    lastForm2.Show();
}


Smile | :)


AnswerRe: singelton problem Pin
Guffa10-Jun-07 7:43
Guffa10-Jun-07 7:43 
AnswerRe: singelton problem Pin
Muammar©10-Jun-07 8:46
Muammar©10-Jun-07 8:46 
GeneralRe: singelton problem Pin
Luc Pattyn10-Jun-07 8:49
sitebuilderLuc Pattyn10-Jun-07 8:49 
GeneralRe: singelton problem Pin
akkram10-Jun-07 23:35
akkram10-Jun-07 23:35 
GeneralRe: singelton problem [modified] Pin
Alaric_11-Jun-07 5:27
professionalAlaric_11-Jun-07 5:27 
QuestionSearch.asp.cs in C# Pin
haibec10-Jun-07 5:27
haibec10-Jun-07 5:27 
AnswerRe: Search.asp.cs in C# Pin
Colin Angus Mackay10-Jun-07 6:00
Colin Angus Mackay10-Jun-07 6:00 
GeneralRe: Search.asp.cs in C# Pin
haibec10-Jun-07 6:07
haibec10-Jun-07 6:07 
GeneralRe: Search.asp.cs in C# Pin
Colin Angus Mackay10-Jun-07 11:18
Colin Angus Mackay10-Jun-07 11:18 
AnswerRe: Search.asp.cs in C# Pin
Christian Graus10-Jun-07 13:14
protectorChristian Graus10-Jun-07 13:14 
GeneralRe: Search.asp.cs in C# Pin
haibec10-Jun-07 13:23
haibec10-Jun-07 13:23 
GeneralRe: Search.asp.cs in C# Pin
Christian Graus10-Jun-07 14:36
protectorChristian Graus10-Jun-07 14:36 
QuestionDataGridViewCheckBoxColumn on-click Event Pin
dbetting10-Jun-07 4:52
dbetting10-Jun-07 4:52 
QuestionChange typing language Pin
clint198210-Jun-07 4:50
clint198210-Jun-07 4:50 
AnswerRe: Change typing language Pin
Colin Angus Mackay10-Jun-07 6:02
Colin Angus Mackay10-Jun-07 6:02 
QuestionRe: Change typing language Pin
clint198210-Jun-07 11:59
clint198210-Jun-07 11:59 
AnswerRe: Change typing language Pin
Colin Angus Mackay10-Jun-07 13:19
Colin Angus Mackay10-Jun-07 13:19 

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.