467,879 Members | 1,324 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,879 developers. It's quick & easy.

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

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
Dec 28 '05 #1
  • viewed: 1678
Share:
5 Replies
Hi,

"Ronald S. Cook" <rc***@westinis.com> wrote in message
news:Ok**************@TK2MSFTNGP14.phx.gbl...
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

Dec 28 '05 #2
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:e3****************@TK2MSFTNGP15.phx.gbl...
Hi,

"Ronald S. Cook" <rc***@westinis.com> wrote in message
news:Ok**************@TK2MSFTNGP14.phx.gbl...
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


Dec 28 '05 #3
Eric Renken <Er*********@newsgroup.nospam> 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 - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Dec 29 '05 #4
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
Dec 29 '05 #5
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]" <sk***@pobox.com> wrote in message
news:MP***********************@msnews.microsoft.co m...
Eric Renken <Er*********@newsgroup.nospam> 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 - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Jan 12 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Michael Foord | last post: by
1 post views Thread by John Davis | last post: by
6 posts views Thread by BizWorld | last post: by
4 posts views Thread by garyusenet | last post: by
10 posts views Thread by =?Utf-8?B?UmljaGFyZCBCeXNvdXRo?= | last post: by
10 posts views Thread by DavidPr | last post: by
reply views Thread by jack112 | last post: by
reply views Thread by MrMoon | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.