Click here to Skip to main content
15,908,901 members
Home / Discussions / C#
   

C#

 
QuestionFixed form size for different screen resolutions Pin
cshaaaa11-Dec-05 19:52
cshaaaa11-Dec-05 19:52 
AnswerRe: Fixed form size for different screen resolutions Pin
NassosReyzidis12-Dec-05 1:18
NassosReyzidis12-Dec-05 1:18 
QuestionCheckBoxList inside in web forms Pin
ckruger11-Dec-05 19:43
ckruger11-Dec-05 19:43 
QuestionDatagridTextBoxColumn with Combo Pin
Mahi.Ragava11-Dec-05 19:23
Mahi.Ragava11-Dec-05 19:23 
QuestionProxy with authentication retire something. Pin
icerein11-Dec-05 18:46
icerein11-Dec-05 18:46 
AnswerRe: Proxy with authentication retire something. Pin
icerein11-Dec-05 19:48
icerein11-Dec-05 19:48 
QuestionBuild Comment Web Pages Dialog Box in c# Pin
aynka200011-Dec-05 18:40
aynka200011-Dec-05 18:40 
QuestionLogin failure needs to close main app... Pin
flicktom11-Dec-05 18:11
flicktom11-Dec-05 18:11 
I have an MDI parent form "formMAIN" with the following code:

public formMAIN()<br />
{<br />
  InitializeComponent();<br />
  // blah blah blah<br />
  LoginForm loginForm = new LoginForm();<br />
  loginForm.ShowDialog();<br />
<br />
  if (LoggedUserName != "")<br />
  {<br />
    this.Text += " [" + LoggedUserName + "]";<br />
  }<br />
  else<br />
  {<br />
    // problem area... I want to close the main form if login failed...<br />
    //   IE... LoggedUserName will be ""<br />
  }<br />
  ...


The loginForm connects to the database, checks for matching user name and password and sets the formMAIN's static variable "LoggedUserName" if a match is found. I placed it in the constructor of formMAIN so that it would appear first.

I want to be able to close this main form immediately if the user closes the login form or clicks the "cancel" button on it... IE.. LoggedUserName will be blank when the focus returns to the formMAIN.

I tried "this.Close();" as well as Application.Close(), but it doesn't work. I'm guessing this is because it's in the constructor for the form, which obviously is not yet completely instantiated. I can't put it in the initialize area for the same reason.

I need some way to automatically perform the this.Close() operation 'after' the formMAIN completes initialization if the LoggedUserName value is still "" (IE.. failed log-in or user canceled the login form). How can this be done with the least amount of code?



Flicktom

-- modified at 0:23 Monday 12th December, 2005
AnswerRe: Login failure needs to close main app... Pin
Vikram A Punathambekar11-Dec-05 18:58
Vikram A Punathambekar11-Dec-05 18:58 
GeneralRe: Login failure needs to close main app... Pin
flicktom13-Dec-05 14:36
flicktom13-Dec-05 14:36 
AnswerRe: Login failure needs to close main app... Pin
Polis Pilavas12-Dec-05 2:36
Polis Pilavas12-Dec-05 2:36 
Questionhow to using *.ocx written in vb6 for c#.net Pin
tinh cau11-Dec-05 17:52
tinh cau11-Dec-05 17:52 
AnswerRe: how to using *.ocx written in vb6 for c#.net Pin
Christian Graus11-Dec-05 18:09
protectorChristian Graus11-Dec-05 18:09 
AnswerRe: how to using *.ocx written in vb6 for c#.net Pin
Johan Russouw11-Dec-05 23:12
Johan Russouw11-Dec-05 23:12 
QuestionOpening a textbox using OleDbReader Pin
Mahi.Ragava11-Dec-05 17:51
Mahi.Ragava11-Dec-05 17:51 
AnswerRe: Opening a textbox using OleDbReader Pin
Christian Graus11-Dec-05 18:11
protectorChristian Graus11-Dec-05 18:11 
GeneralRe: Opening a textbox using OleDbReader Pin
Mahi.Ragava11-Dec-05 18:29
Mahi.Ragava11-Dec-05 18:29 
GeneralRe: Opening a textbox using OleDbReader Pin
Christian Graus11-Dec-05 18:36
protectorChristian Graus11-Dec-05 18:36 
GeneralRe: Opening a textbox using OleDbReader Pin
Mahi.Ragava11-Dec-05 18:40
Mahi.Ragava11-Dec-05 18:40 
GeneralRe: Opening a textbox using OleDbReader Pin
Christian Graus11-Dec-05 18:44
protectorChristian Graus11-Dec-05 18:44 
GeneralRe: Opening a textbox using OleDbReader Pin
Mahi.Ragava11-Dec-05 18:53
Mahi.Ragava11-Dec-05 18:53 
GeneralRe: Opening a textbox using OleDbReader Pin
Christian Graus11-Dec-05 18:55
protectorChristian Graus11-Dec-05 18:55 
GeneralRe: Opening a textbox using OleDbReader Pin
Mahi.Ragava11-Dec-05 19:06
Mahi.Ragava11-Dec-05 19:06 
GeneralRe: Opening a textbox using OleDbReader Pin
Christian Graus11-Dec-05 19:06
protectorChristian Graus11-Dec-05 19:06 
GeneralRe: Opening a textbox using OleDbReader Pin
Mahi.Ragava12-Dec-05 1:33
Mahi.Ragava12-Dec-05 1:33 

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.