How to close an existing form after opening another form?










0















new to c# wandered how i can use a form to open a new form whilst also closing that initial form. I have a form that a user needs to fill out and click login on to move forward which at this point if the information is correct should open the next form and close the current one. All i seem to get is both forms closing. i can do it without closing the initial form but then it is obviously still open in the background. The form i'm trying to open is form encryption and the one 'im trying to close is form1 any help is much appreciated.



here's my code:



if (maskedTxtLogin != null)

FormEncryption Encryption = new FormEncryption();

Encryption.Show();

this.Close();


else

MessageBox.Show("Please input your initials");










share|improve this question






















  • it depend on whether your "initial" form is the application form (or the Main form). You cannot close the Main form (which is the Application form) and expect the child still running. The this could be referring to your Main form.

    – Casperonian
    Nov 15 '18 at 23:50











  • The initial form is the login form. The main form is the one that is opened by the initial form. Is their any way around this child form issue? maybe have it open from the beginning but invisible and then becomes visible when the other one is closed? do you think this could work? cheers for any help

    – Jack McLoughlin
    Nov 16 '18 at 0:17











  • According to Windows, the main form is the initial form. Whichever is the first form to open must stay alive for the whole life of the application. So yes, what you describe would work better.

    – Gabriel Luci
    Nov 16 '18 at 0:21











  • Okay thanks anyway guys !

    – Jack McLoughlin
    Nov 16 '18 at 0:23











  • You can control when your application closes by using a custom ApplicationContext. The Application.Run(new Form1()) statement in Program.Main create a default ApplicationContext with Form as its main form. By using a custom ApplicationContext and overriding the OnMainFormClosed method, you can redefine MainForm as it is just a property of the context. You start the application using Application.Run(new CustomApplicationContext).

    – TnTinMn
    Nov 16 '18 at 0:54
















0















new to c# wandered how i can use a form to open a new form whilst also closing that initial form. I have a form that a user needs to fill out and click login on to move forward which at this point if the information is correct should open the next form and close the current one. All i seem to get is both forms closing. i can do it without closing the initial form but then it is obviously still open in the background. The form i'm trying to open is form encryption and the one 'im trying to close is form1 any help is much appreciated.



here's my code:



if (maskedTxtLogin != null)

FormEncryption Encryption = new FormEncryption();

Encryption.Show();

this.Close();


else

MessageBox.Show("Please input your initials");










share|improve this question






















  • it depend on whether your "initial" form is the application form (or the Main form). You cannot close the Main form (which is the Application form) and expect the child still running. The this could be referring to your Main form.

    – Casperonian
    Nov 15 '18 at 23:50











  • The initial form is the login form. The main form is the one that is opened by the initial form. Is their any way around this child form issue? maybe have it open from the beginning but invisible and then becomes visible when the other one is closed? do you think this could work? cheers for any help

    – Jack McLoughlin
    Nov 16 '18 at 0:17











  • According to Windows, the main form is the initial form. Whichever is the first form to open must stay alive for the whole life of the application. So yes, what you describe would work better.

    – Gabriel Luci
    Nov 16 '18 at 0:21











  • Okay thanks anyway guys !

    – Jack McLoughlin
    Nov 16 '18 at 0:23











  • You can control when your application closes by using a custom ApplicationContext. The Application.Run(new Form1()) statement in Program.Main create a default ApplicationContext with Form as its main form. By using a custom ApplicationContext and overriding the OnMainFormClosed method, you can redefine MainForm as it is just a property of the context. You start the application using Application.Run(new CustomApplicationContext).

    – TnTinMn
    Nov 16 '18 at 0:54














0












0








0








new to c# wandered how i can use a form to open a new form whilst also closing that initial form. I have a form that a user needs to fill out and click login on to move forward which at this point if the information is correct should open the next form and close the current one. All i seem to get is both forms closing. i can do it without closing the initial form but then it is obviously still open in the background. The form i'm trying to open is form encryption and the one 'im trying to close is form1 any help is much appreciated.



here's my code:



if (maskedTxtLogin != null)

FormEncryption Encryption = new FormEncryption();

Encryption.Show();

this.Close();


else

MessageBox.Show("Please input your initials");










share|improve this question














new to c# wandered how i can use a form to open a new form whilst also closing that initial form. I have a form that a user needs to fill out and click login on to move forward which at this point if the information is correct should open the next form and close the current one. All i seem to get is both forms closing. i can do it without closing the initial form but then it is obviously still open in the background. The form i'm trying to open is form encryption and the one 'im trying to close is form1 any help is much appreciated.



here's my code:



if (maskedTxtLogin != null)

FormEncryption Encryption = new FormEncryption();

Encryption.Show();

this.Close();


else

MessageBox.Show("Please input your initials");







c# forms






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 15 '18 at 23:39









Jack McLoughlinJack McLoughlin

134




134












  • it depend on whether your "initial" form is the application form (or the Main form). You cannot close the Main form (which is the Application form) and expect the child still running. The this could be referring to your Main form.

    – Casperonian
    Nov 15 '18 at 23:50











  • The initial form is the login form. The main form is the one that is opened by the initial form. Is their any way around this child form issue? maybe have it open from the beginning but invisible and then becomes visible when the other one is closed? do you think this could work? cheers for any help

    – Jack McLoughlin
    Nov 16 '18 at 0:17











  • According to Windows, the main form is the initial form. Whichever is the first form to open must stay alive for the whole life of the application. So yes, what you describe would work better.

    – Gabriel Luci
    Nov 16 '18 at 0:21











  • Okay thanks anyway guys !

    – Jack McLoughlin
    Nov 16 '18 at 0:23











  • You can control when your application closes by using a custom ApplicationContext. The Application.Run(new Form1()) statement in Program.Main create a default ApplicationContext with Form as its main form. By using a custom ApplicationContext and overriding the OnMainFormClosed method, you can redefine MainForm as it is just a property of the context. You start the application using Application.Run(new CustomApplicationContext).

    – TnTinMn
    Nov 16 '18 at 0:54


















  • it depend on whether your "initial" form is the application form (or the Main form). You cannot close the Main form (which is the Application form) and expect the child still running. The this could be referring to your Main form.

    – Casperonian
    Nov 15 '18 at 23:50











  • The initial form is the login form. The main form is the one that is opened by the initial form. Is their any way around this child form issue? maybe have it open from the beginning but invisible and then becomes visible when the other one is closed? do you think this could work? cheers for any help

    – Jack McLoughlin
    Nov 16 '18 at 0:17











  • According to Windows, the main form is the initial form. Whichever is the first form to open must stay alive for the whole life of the application. So yes, what you describe would work better.

    – Gabriel Luci
    Nov 16 '18 at 0:21











  • Okay thanks anyway guys !

    – Jack McLoughlin
    Nov 16 '18 at 0:23











  • You can control when your application closes by using a custom ApplicationContext. The Application.Run(new Form1()) statement in Program.Main create a default ApplicationContext with Form as its main form. By using a custom ApplicationContext and overriding the OnMainFormClosed method, you can redefine MainForm as it is just a property of the context. You start the application using Application.Run(new CustomApplicationContext).

    – TnTinMn
    Nov 16 '18 at 0:54

















it depend on whether your "initial" form is the application form (or the Main form). You cannot close the Main form (which is the Application form) and expect the child still running. The this could be referring to your Main form.

– Casperonian
Nov 15 '18 at 23:50





it depend on whether your "initial" form is the application form (or the Main form). You cannot close the Main form (which is the Application form) and expect the child still running. The this could be referring to your Main form.

– Casperonian
Nov 15 '18 at 23:50













The initial form is the login form. The main form is the one that is opened by the initial form. Is their any way around this child form issue? maybe have it open from the beginning but invisible and then becomes visible when the other one is closed? do you think this could work? cheers for any help

– Jack McLoughlin
Nov 16 '18 at 0:17





The initial form is the login form. The main form is the one that is opened by the initial form. Is their any way around this child form issue? maybe have it open from the beginning but invisible and then becomes visible when the other one is closed? do you think this could work? cheers for any help

– Jack McLoughlin
Nov 16 '18 at 0:17













According to Windows, the main form is the initial form. Whichever is the first form to open must stay alive for the whole life of the application. So yes, what you describe would work better.

– Gabriel Luci
Nov 16 '18 at 0:21





According to Windows, the main form is the initial form. Whichever is the first form to open must stay alive for the whole life of the application. So yes, what you describe would work better.

– Gabriel Luci
Nov 16 '18 at 0:21













Okay thanks anyway guys !

– Jack McLoughlin
Nov 16 '18 at 0:23





Okay thanks anyway guys !

– Jack McLoughlin
Nov 16 '18 at 0:23













You can control when your application closes by using a custom ApplicationContext. The Application.Run(new Form1()) statement in Program.Main create a default ApplicationContext with Form as its main form. By using a custom ApplicationContext and overriding the OnMainFormClosed method, you can redefine MainForm as it is just a property of the context. You start the application using Application.Run(new CustomApplicationContext).

– TnTinMn
Nov 16 '18 at 0:54






You can control when your application closes by using a custom ApplicationContext. The Application.Run(new Form1()) statement in Program.Main create a default ApplicationContext with Form as its main form. By using a custom ApplicationContext and overriding the OnMainFormClosed method, you can redefine MainForm as it is just a property of the context. You start the application using Application.Run(new CustomApplicationContext).

– TnTinMn
Nov 16 '18 at 0:54













0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53329390%2fhow-to-close-an-existing-form-after-opening-another-form%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53329390%2fhow-to-close-an-existing-form-after-opening-another-form%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Top Tejano songwriter Luis Silva dead of heart attack at 64

ReactJS Fetched API data displays live - need Data displayed static

政党