Hide MainForm when LoginForm is called?
I have 2 forms, 1 Login form and the other is the Main Application Form.
The Main Form launches Login Form since auth = false, the issue is though since I am calling the login from the main application how do I then hide the main form when the login form is shown and then display the mainform once the user is authenticated?
This is my Main App call:
/*
* Created by SharpDevelop.
* User: SAVENZ
* Date: 7/26/2015
* Time: 3:46 PM
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
namespace NewCOCBot
{
/// <summary>
/// Description of MainForm.
/// </summary>
public partial class MainForm : Form
{
public MainForm()
{
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();
//
// TODO: Add constructor code after the InitializeComponent() call.
//
var auth = false;
if(auth == false){
LoginForm authForm = new LoginForm();
authForm.Show();
}
}
}
}
c# forms
|
show 1 more comment
I have 2 forms, 1 Login form and the other is the Main Application Form.
The Main Form launches Login Form since auth = false, the issue is though since I am calling the login from the main application how do I then hide the main form when the login form is shown and then display the mainform once the user is authenticated?
This is my Main App call:
/*
* Created by SharpDevelop.
* User: SAVENZ
* Date: 7/26/2015
* Time: 3:46 PM
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
namespace NewCOCBot
{
/// <summary>
/// Description of MainForm.
/// </summary>
public partial class MainForm : Form
{
public MainForm()
{
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();
//
// TODO: Add constructor code after the InitializeComponent() call.
//
var auth = false;
if(auth == false){
LoginForm authForm = new LoginForm();
authForm.Show();
}
}
}
}
c# forms
did you try this.close() ???
– Zohaib Waqar
Jul 26 '15 at 10:40
1
You could simply useShowDialog()instead ofShow()
– Flat Eric
Jul 26 '15 at 10:42
@FlatEric that seems to do the trick, what would i need to do to recall or pass the dialog as authenticated? just Close() the dialog?
– Elevant
Jul 26 '15 at 10:44
ShowDialog()returns aDialogResult, which you can set inLoginFormbefore you close it.
– Flat Eric
Jul 26 '15 at 10:46
Creating login forms is a very traditional newbie-to-winforms mistake. Such an app always runs in a session where the user already logged-in using the highly secure Windows login procedure. One that's battle-hardened by being attacked every conceivable way. You are not talking to a complete stranger on the Internet. Putting your own login procedure on top of that is a very significant security risk, users will simply re-use their Windows logon password and the odds that you treat them just as securely as Windows does are very slim. Don't do it.
– Hans Passant
Jul 26 '15 at 10:54
|
show 1 more comment
I have 2 forms, 1 Login form and the other is the Main Application Form.
The Main Form launches Login Form since auth = false, the issue is though since I am calling the login from the main application how do I then hide the main form when the login form is shown and then display the mainform once the user is authenticated?
This is my Main App call:
/*
* Created by SharpDevelop.
* User: SAVENZ
* Date: 7/26/2015
* Time: 3:46 PM
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
namespace NewCOCBot
{
/// <summary>
/// Description of MainForm.
/// </summary>
public partial class MainForm : Form
{
public MainForm()
{
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();
//
// TODO: Add constructor code after the InitializeComponent() call.
//
var auth = false;
if(auth == false){
LoginForm authForm = new LoginForm();
authForm.Show();
}
}
}
}
c# forms
I have 2 forms, 1 Login form and the other is the Main Application Form.
The Main Form launches Login Form since auth = false, the issue is though since I am calling the login from the main application how do I then hide the main form when the login form is shown and then display the mainform once the user is authenticated?
This is my Main App call:
/*
* Created by SharpDevelop.
* User: SAVENZ
* Date: 7/26/2015
* Time: 3:46 PM
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
namespace NewCOCBot
{
/// <summary>
/// Description of MainForm.
/// </summary>
public partial class MainForm : Form
{
public MainForm()
{
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();
//
// TODO: Add constructor code after the InitializeComponent() call.
//
var auth = false;
if(auth == false){
LoginForm authForm = new LoginForm();
authForm.Show();
}
}
}
}
c# forms
c# forms
edited Dec 31 '18 at 22:57
Flimzy
38.7k106597
38.7k106597
asked Jul 26 '15 at 10:35
ElevantElevant
144521
144521
did you try this.close() ???
– Zohaib Waqar
Jul 26 '15 at 10:40
1
You could simply useShowDialog()instead ofShow()
– Flat Eric
Jul 26 '15 at 10:42
@FlatEric that seems to do the trick, what would i need to do to recall or pass the dialog as authenticated? just Close() the dialog?
– Elevant
Jul 26 '15 at 10:44
ShowDialog()returns aDialogResult, which you can set inLoginFormbefore you close it.
– Flat Eric
Jul 26 '15 at 10:46
Creating login forms is a very traditional newbie-to-winforms mistake. Such an app always runs in a session where the user already logged-in using the highly secure Windows login procedure. One that's battle-hardened by being attacked every conceivable way. You are not talking to a complete stranger on the Internet. Putting your own login procedure on top of that is a very significant security risk, users will simply re-use their Windows logon password and the odds that you treat them just as securely as Windows does are very slim. Don't do it.
– Hans Passant
Jul 26 '15 at 10:54
|
show 1 more comment
did you try this.close() ???
– Zohaib Waqar
Jul 26 '15 at 10:40
1
You could simply useShowDialog()instead ofShow()
– Flat Eric
Jul 26 '15 at 10:42
@FlatEric that seems to do the trick, what would i need to do to recall or pass the dialog as authenticated? just Close() the dialog?
– Elevant
Jul 26 '15 at 10:44
ShowDialog()returns aDialogResult, which you can set inLoginFormbefore you close it.
– Flat Eric
Jul 26 '15 at 10:46
Creating login forms is a very traditional newbie-to-winforms mistake. Such an app always runs in a session where the user already logged-in using the highly secure Windows login procedure. One that's battle-hardened by being attacked every conceivable way. You are not talking to a complete stranger on the Internet. Putting your own login procedure on top of that is a very significant security risk, users will simply re-use their Windows logon password and the odds that you treat them just as securely as Windows does are very slim. Don't do it.
– Hans Passant
Jul 26 '15 at 10:54
did you try this.close() ???
– Zohaib Waqar
Jul 26 '15 at 10:40
did you try this.close() ???
– Zohaib Waqar
Jul 26 '15 at 10:40
1
1
You could simply use
ShowDialog() instead of Show()– Flat Eric
Jul 26 '15 at 10:42
You could simply use
ShowDialog() instead of Show()– Flat Eric
Jul 26 '15 at 10:42
@FlatEric that seems to do the trick, what would i need to do to recall or pass the dialog as authenticated? just Close() the dialog?
– Elevant
Jul 26 '15 at 10:44
@FlatEric that seems to do the trick, what would i need to do to recall or pass the dialog as authenticated? just Close() the dialog?
– Elevant
Jul 26 '15 at 10:44
ShowDialog() returns a DialogResult, which you can set in LoginForm before you close it.– Flat Eric
Jul 26 '15 at 10:46
ShowDialog() returns a DialogResult, which you can set in LoginForm before you close it.– Flat Eric
Jul 26 '15 at 10:46
Creating login forms is a very traditional newbie-to-winforms mistake. Such an app always runs in a session where the user already logged-in using the highly secure Windows login procedure. One that's battle-hardened by being attacked every conceivable way. You are not talking to a complete stranger on the Internet. Putting your own login procedure on top of that is a very significant security risk, users will simply re-use their Windows logon password and the odds that you treat them just as securely as Windows does are very slim. Don't do it.
– Hans Passant
Jul 26 '15 at 10:54
Creating login forms is a very traditional newbie-to-winforms mistake. Such an app always runs in a session where the user already logged-in using the highly secure Windows login procedure. One that's battle-hardened by being attacked every conceivable way. You are not talking to a complete stranger on the Internet. Putting your own login procedure on top of that is a very significant security risk, users will simply re-use their Windows logon password and the odds that you treat them just as securely as Windows does are very slim. Don't do it.
– Hans Passant
Jul 26 '15 at 10:54
|
show 1 more comment
3 Answers
3
active
oldest
votes
In MainForm:
LoginForm authForm = new LoginForm();
var result = authForm.ShowDialog();
if (result == DialogResult.OK)
{
// authentication was successful
}
In LoginForm: Set authentication result ok (if if was successful)
DialogResult = DialogResult.OK;
add a comment |
I think the best way is run login form and main form both from Program.cs file.
You can change Program.cs file like this:
namespace YorNameSpace
{
public static class Program
{
public static DialogResult result;
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
using (var loginForm = new loading())
result=loginForm.ShowDialog();
if (result == DialogResult.OK)
{
// login was successful
Application.Run(new Main());
}
}
}
}
add a comment |
Display the form as a dialog this will hide mainform while login form is visible.
LoginForm authForm = new LoginForm();
authForm.ShowDialog();
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f31635974%2fhide-mainform-when-loginform-is-called%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
In MainForm:
LoginForm authForm = new LoginForm();
var result = authForm.ShowDialog();
if (result == DialogResult.OK)
{
// authentication was successful
}
In LoginForm: Set authentication result ok (if if was successful)
DialogResult = DialogResult.OK;
add a comment |
In MainForm:
LoginForm authForm = new LoginForm();
var result = authForm.ShowDialog();
if (result == DialogResult.OK)
{
// authentication was successful
}
In LoginForm: Set authentication result ok (if if was successful)
DialogResult = DialogResult.OK;
add a comment |
In MainForm:
LoginForm authForm = new LoginForm();
var result = authForm.ShowDialog();
if (result == DialogResult.OK)
{
// authentication was successful
}
In LoginForm: Set authentication result ok (if if was successful)
DialogResult = DialogResult.OK;
In MainForm:
LoginForm authForm = new LoginForm();
var result = authForm.ShowDialog();
if (result == DialogResult.OK)
{
// authentication was successful
}
In LoginForm: Set authentication result ok (if if was successful)
DialogResult = DialogResult.OK;
answered Jul 26 '15 at 10:49
Flat EricFlat Eric
5,99272437
5,99272437
add a comment |
add a comment |
I think the best way is run login form and main form both from Program.cs file.
You can change Program.cs file like this:
namespace YorNameSpace
{
public static class Program
{
public static DialogResult result;
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
using (var loginForm = new loading())
result=loginForm.ShowDialog();
if (result == DialogResult.OK)
{
// login was successful
Application.Run(new Main());
}
}
}
}
add a comment |
I think the best way is run login form and main form both from Program.cs file.
You can change Program.cs file like this:
namespace YorNameSpace
{
public static class Program
{
public static DialogResult result;
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
using (var loginForm = new loading())
result=loginForm.ShowDialog();
if (result == DialogResult.OK)
{
// login was successful
Application.Run(new Main());
}
}
}
}
add a comment |
I think the best way is run login form and main form both from Program.cs file.
You can change Program.cs file like this:
namespace YorNameSpace
{
public static class Program
{
public static DialogResult result;
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
using (var loginForm = new loading())
result=loginForm.ShowDialog();
if (result == DialogResult.OK)
{
// login was successful
Application.Run(new Main());
}
}
}
}
I think the best way is run login form and main form both from Program.cs file.
You can change Program.cs file like this:
namespace YorNameSpace
{
public static class Program
{
public static DialogResult result;
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
using (var loginForm = new loading())
result=loginForm.ShowDialog();
if (result == DialogResult.OK)
{
// login was successful
Application.Run(new Main());
}
}
}
}
answered Jul 26 '15 at 11:04
mitlimitli
257212
257212
add a comment |
add a comment |
Display the form as a dialog this will hide mainform while login form is visible.
LoginForm authForm = new LoginForm();
authForm.ShowDialog();
add a comment |
Display the form as a dialog this will hide mainform while login form is visible.
LoginForm authForm = new LoginForm();
authForm.ShowDialog();
add a comment |
Display the form as a dialog this will hide mainform while login form is visible.
LoginForm authForm = new LoginForm();
authForm.ShowDialog();
Display the form as a dialog this will hide mainform while login form is visible.
LoginForm authForm = new LoginForm();
authForm.ShowDialog();
answered Jul 26 '15 at 10:47
Malik FaiqMalik Faiq
338
338
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f31635974%2fhide-mainform-when-loginform-is-called%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
did you try this.close() ???
– Zohaib Waqar
Jul 26 '15 at 10:40
1
You could simply use
ShowDialog()instead ofShow()– Flat Eric
Jul 26 '15 at 10:42
@FlatEric that seems to do the trick, what would i need to do to recall or pass the dialog as authenticated? just Close() the dialog?
– Elevant
Jul 26 '15 at 10:44
ShowDialog()returns aDialogResult, which you can set inLoginFormbefore you close it.– Flat Eric
Jul 26 '15 at 10:46
Creating login forms is a very traditional newbie-to-winforms mistake. Such an app always runs in a session where the user already logged-in using the highly secure Windows login procedure. One that's battle-hardened by being attacked every conceivable way. You are not talking to a complete stranger on the Internet. Putting your own login procedure on top of that is a very significant security risk, users will simply re-use their Windows logon password and the odds that you treat them just as securely as Windows does are very slim. Don't do it.
– Hans Passant
Jul 26 '15 at 10:54