Click here to Skip to main content
15,880,364 members
Home / Discussions / C#
   

C#

 
GeneralRe: Generics and type constraints Pin
Dan Neely16-Jul-09 5:45
Dan Neely16-Jul-09 5:45 
GeneralRe: Generics and type constraints Pin
dojohansen16-Jul-09 6:35
dojohansen16-Jul-09 6:35 
GeneralRe: Generics and type constraints Pin
Dan Neely16-Jul-09 7:09
Dan Neely16-Jul-09 7:09 
AnswerRe: Generics and type constraints Pin
Gideon Engelberth16-Jul-09 7:16
Gideon Engelberth16-Jul-09 7:16 
GeneralRe: Generics and type constraints Pin
dojohansen16-Jul-09 22:00
dojohansen16-Jul-09 22:00 
QuestionResetting Objects to startup-state Pin
chrisx5116-Jul-09 3:02
chrisx5116-Jul-09 3:02 
AnswerRe: Resetting Objects to startup-state Pin
Luc Pattyn16-Jul-09 3:24
sitebuilderLuc Pattyn16-Jul-09 3:24 
AnswerRe: Resetting Objects to startup-state Pin
dojohansen16-Jul-09 5:30
dojohansen16-Jul-09 5:30 
If "new" really should be like restarting the application, the easiest way to do it might be to actually restart the application, like this:

void btnReset_Click(object sender, EventArgs e)
{
  Application.Restart();
}


This is the only easy way I can think of to guarantee that all state, including any statics you may be using, child forms and so on, is truly reset. But it may not be a good solution if your app is slow to start up.

With default startup location this will cause the app to "move" (of course the form is really a new form, but it's location will be displaced relative to the one that was destroyed when you restarted the application). You can get around this if you use another startup location, like CenterScreen, but it will look odd if the user moves or resizes the form before restarting.

An alternative way to do it if it's only UI state you want to reset might be this:

void btnReset_Click(object sender, EventArgs e)
{
    int[] n = { Left, Top, Width, Height };
    Controls.Clear();
    InitializeComponent();
    Left = n[0];
    Top = n[1];
    Width = n[2];
    Height = n[3];
}


This obviously will only reset the form in question. But it's general at least, so you could incorporate such logic into your custom base class for forms, so only one piece of code needs to be modified should you wish to change any of it later on.
QuestionHow to Provide Confirmation Link to the New User in C# Pin
ChandrakanthGaddam16-Jul-09 1:35
ChandrakanthGaddam16-Jul-09 1:35 
AnswerRe: How to Provide Confirmation Link to the New User in C# Pin
Pete O'Hanlon16-Jul-09 1:57
mvePete O'Hanlon16-Jul-09 1:57 
Questionupdate progress bar concurrently in windows form Pin
Praveen Raghuvanshi16-Jul-09 1:33
professionalPraveen Raghuvanshi16-Jul-09 1:33 
AnswerRe: update progress bar concurrently in windows form Pin
monstale16-Jul-09 2:11
monstale16-Jul-09 2:11 
AnswerRe: update progress bar concurrently in windows form Pin
MumbleB16-Jul-09 2:19
MumbleB16-Jul-09 2:19 
QuestionIf statement with ? and : characters Pin
soso_online16-Jul-09 1:00
soso_online16-Jul-09 1:00 
AnswerRe: If statement with ? and : characters Pin
Tamer Oz16-Jul-09 1:13
Tamer Oz16-Jul-09 1:13 
GeneralRe: If statement with ? and : characters Pin
soso_online16-Jul-09 2:09
soso_online16-Jul-09 2:09 
AnswerRe: If statement with ? and : characters Pin
Luc Pattyn16-Jul-09 1:25
sitebuilderLuc Pattyn16-Jul-09 1:25 
GeneralRe: If statement with ? and : characters Pin
soso_online16-Jul-09 2:09
soso_online16-Jul-09 2:09 
AnswerRe: If statement with ? and : characters Pin
Pete O'Hanlon16-Jul-09 1:54
mvePete O'Hanlon16-Jul-09 1:54 
GeneralRe: If statement with ? and : characters Pin
soso_online16-Jul-09 2:08
soso_online16-Jul-09 2:08 
QuestionWindows Form Datagridview Pin
Rajeshwar Code- Developer16-Jul-09 0:58
Rajeshwar Code- Developer16-Jul-09 0:58 
AnswerRe: Windows Form Datagridview Pin
Vimalsoft(Pty) Ltd16-Jul-09 1:14
professionalVimalsoft(Pty) Ltd16-Jul-09 1:14 
GeneralRe: Windows Form Datagridview Pin
Rajeshwar Code- Developer16-Jul-09 1:19
Rajeshwar Code- Developer16-Jul-09 1:19 
GeneralRe: Windows Form Datagridview Pin
Vimalsoft(Pty) Ltd16-Jul-09 1:21
professionalVimalsoft(Pty) Ltd16-Jul-09 1:21 
GeneralRe: Windows Form Datagridview Pin
Rajeshwar Code- Developer16-Jul-09 1:36
Rajeshwar Code- Developer16-Jul-09 1:36 

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.