PC Review


Reply
Thread Tools Rate Thread

Basic question about login form and passing success back to main form

 
 
Ronald S. Cook
Guest
Posts: n/a
 
      28th Dec 2005
It's been longer that I remember since writing windows (not web) apps.

1) I want to load a main form

2) User clicks login button which brings up login form (on top of main form)

3) Upon entering successful password and clicking ok, login form should go
away

4) Main form should then display admin controls

I'm not sure how this code should look. How should success be passewd back
to the main form? If the main form is already loaded (just behind the login
form), how then do I "reload" (or whatever) to let it know it should show
some admin controls?

Thanks for any help!
RC


 
Reply With Quote
 
 
 
 
Ignacio Machin \( .NET/ C# MVP \)
Guest
Posts: n/a
 
      28th Dec 2005
Hi,

"Ronald S. Cook" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> It's been longer that I remember since writing windows (not web) apps.
>
> 1) I want to load a main form
>
> 2) User clicks login button which brings up login form (on top of main
> form)
>
> 3) Upon entering successful password and clicking ok, login form should go
> away
>
> 4) Main form should then display admin controls
>
> I'm not sure how this code should look. How should success be passewd
> back to the main form? If the main form is already loaded (just behind
> the login form), how then do I "reload" (or whatever) to let it know it
> should show some admin controls?



A very simple way of solving this is displaying the login as a modal
windows (which probably you use ) , set the DialogResult accordingly and if
the correct value is received show the controls:

//you can use any of the values of DialogResult
if ( theLoginForm.ShowDialog() == DialogResult.Yes )
SetAdminControlsVisible();


Btw, you use Form.DialogResult = ... inside the form. probably like

void button1_onclick(.... )
{
if( Islogincorrect( textbox1.Text, textbox2.Text) )
{
this.DialogResult = DialogResult.Yes;
this.Close();
}
}



How to make the controls visible depends of your form and the controls, you
can simple do a Control.Visible = true; to all the controls you need.



--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation


> Thanks for any help!
> RC
>



 
Reply With Quote
 
Eric Renken
Guest
Posts: n/a
 
      28th Dec 2005
Actually once you set the DialogResult of a form you don't need to call
this.Close(). Setting the DialoResult seems to take care of that from what
I have seen.

Eric Renken

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote
in message news:e3BLOE%(E-Mail Removed)...
> Hi,
>
> "Ronald S. Cook" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> It's been longer that I remember since writing windows (not web) apps.
>>
>> 1) I want to load a main form
>>
>> 2) User clicks login button which brings up login form (on top of main
>> form)
>>
>> 3) Upon entering successful password and clicking ok, login form should
>> go away
>>
>> 4) Main form should then display admin controls
>>
>> I'm not sure how this code should look. How should success be passewd
>> back to the main form? If the main form is already loaded (just behind
>> the login form), how then do I "reload" (or whatever) to let it know it
>> should show some admin controls?

>
>
> A very simple way of solving this is displaying the login as a modal
> windows (which probably you use ) , set the DialogResult accordingly and
> if the correct value is received show the controls:
>
> //you can use any of the values of DialogResult
> if ( theLoginForm.ShowDialog() == DialogResult.Yes )
> SetAdminControlsVisible();
>
>
> Btw, you use Form.DialogResult = ... inside the form. probably like
>
> void button1_onclick(.... )
> {
> if( Islogincorrect( textbox1.Text, textbox2.Text) )
> {
> this.DialogResult = DialogResult.Yes;
> this.Close();
> }
> }
>
>
>
> How to make the controls visible depends of your form and the controls,
> you can simple do a Control.Visible = true; to all the controls you need.
>
>
>
> --
> Ignacio Machin,
> ignacio.machin AT dot.state.fl.us
> Florida Department Of Transportation
>
>
>> Thanks for any help!
>> RC
>>

>
>



 
Reply With Quote
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      29th Dec 2005
Eric Renken <(E-Mail Removed)> wrote:
> Actually once you set the DialogResult of a form you don't need to call
> this.Close(). Setting the DialoResult seems to take care of that from what
> I have seen.


Fortunately it's more than "seems to" (which would be a dodgy thing to
rely on, IMO). It's nicely documented:

(From the DialogResult property docs.)

<quote>
If the form is displayed as a dialog box, setting this property with a
value from the DialogResult enumeration sets the value of the dialog
box result for the form, hides the modal dialog box, and returns
control to the calling form
</quote>

--
Jon Skeet - <(E-Mail Removed)>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
 
Reply With Quote
 
Ignacio Machin \( .NET/ C# MVP \)
Guest
Posts: n/a
 
      29th Dec 2005
Hi,


>
> (From the DialogResult property docs.)
>
> <quote>
> If the form is displayed as a dialog box, setting this property with a
> value from the DialogResult enumeration sets the value of the dialog
> box result for the form, hides the modal dialog box, and returns
> control to the calling form
> </quote>



Yep, always RTFM first




--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation


 
Reply With Quote
 
Eric Renken
Guest
Posts: n/a
 
      12th Jan 2006
I guess to me it always works fine because when I display a modal dialog
like this I always have them wrapped in a using statement so when it is
finished I know it will be disposed of.

using ( Form myModal = new AskAQuestion() )
{
myModal.ShowDialog();
}

Eric Renken

"Jon Skeet [C# MVP]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Eric Renken <(E-Mail Removed)> wrote:
>> Actually once you set the DialogResult of a form you don't need to call
>> this.Close(). Setting the DialoResult seems to take care of that from
>> what
>> I have seen.

>
> Fortunately it's more than "seems to" (which would be a dodgy thing to
> rely on, IMO). It's nicely documented:
>
> (From the DialogResult property docs.)
>
> <quote>
> If the form is displayed as a dialog box, setting this property with a
> value from the DialogResult enumeration sets the value of the dialog
> box result for the form, hides the modal dialog box, and returns
> control to the calling form
> </quote>
>
> --
> Jon Skeet - <(E-Mail Removed)>
> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
> If replying to the group, please do not mail me too



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing values from main form to a new record on a child form =?Utf-8?B?TGFycnk=?= Microsoft Access Forms 4 1st Mar 2007 01:40 AM
Passing Value back to the Main Form =?Utf-8?B?VGVycmFuY2U=?= Microsoft Dot NET 6 24th Jul 2006 08:21 PM
Form Reference Question (Getting Back Your Visual Basic 6.0 Goodies) gerryLowry::Ability Business Computer Services {KC Microsoft VB .NET 7 3rd Aug 2005 09:12 PM
basic main form --> child form question Vishnudev Ramakrishnan Microsoft Dot NET Framework Forms 0 16th Jul 2004 02:25 AM
Passing selected records from search form to main form Tony Scullion Microsoft Access Form Coding 0 28th Jul 2003 09:10 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:22 AM.