How to run login then main .NET forms?

Posted by Tung on 07-Jul-2010 11:10

Hi, I've made two GUI for .NET forms for a login and main screen and a start.p procedure to run them. But I'm not sure how to use the .NET version of WAIT-FOR properly to run the login and then if it got a valid user, run the main screen and hide/delete the login form.

The only way I've found is to instantiate both forms, hide the main form and in the login form's OK button (if the user & password is valid), hide the login form and show the main form.

My start.p has:

oNetLogin = NEW netlogin (). /* login form */
oTreeMenu = NEW net1 ().    /* main form  */
oTreeMenu:Hide().

WAIT-FOR System.Windows.Forms.Application:Run().

IF VALID-OBJECT(oNetLogin) THEN DELETE OBJECT oNetLogin.
IF VALID-OBJECT(oTreeMenu) THEN DELETE OBJECT oTreeMenu.
QUIT.

And in the login form's OK button (after the validation):

oNetLogin:Hide().
oTreeMenu:Show().

Very messy and even then, if I close the main form with the X button in the top right corner, it doesn't return to start.p and leaves a Progress session running. Has anyone got a better way of doing it? Thanks!

All Replies

Posted by Admin on 07-Jul-2010 11:19

Without any test:

DEFINE VARIABLE oDialogResult AS System.Windows.Forms.DialogResult NO-UNDO.

oNetLogin = NEW netlogin (). /* login form */

oTreeMenu = NEW net1 (). /* main form */

WAIT-FOR oNetLogin:ShowDialog() SET oDialogResult .

IF NOT Progress.Util.EnumHelper:AreEqual (oDialogResult, System.Windows.Forms.DialogResult:Ok) THEN

RETURN . /* or QUIT */

WAIT-FOR System.Windows.Forms.Application:Run (oTreeMenu) .

On validation in the LoginForm you should set

THIS-OBJECT:DialogResult = System.Windows.Forms.DialogResult:Ok .

I'd try as often as possible to avoid the use of the Application:Run () with no parameters.

Posted by Tung on 08-Jul-2010 03:44

That worked!

I did get the error "System.InvalidOperationException: Form that is already visible cannot be displayed as a modal dialog box. Set the form's visible property to false before calling showDialog." but since it was a helpful message, I fixed it by adding "oNetlogin:Visible = NO." before the WAIT-FOR.

I did read a similar discussion http://communities.progress.com/pcom/message/80282#80282 but it didn't have this:

mikefe wrote:

On validation in the LoginForm you should set

THIS-OBJECT:DialogResult = System.Windows.Forms.DialogResult:Ok .


Thanks!

Posted by Tung on 30-Jul-2010 06:07

I've found out you can also set the property DialogResult to return a value, instead of doing it programmatically.

Posted by rbf on 30-Jul-2010 15:43

From Future Proof Software's OpenEdge GUI for .NET Workshop:

/* startup.p */

DEFINE VARIABLE loginDialog AS login NO-UNDO.
DEFINE VARIABLE mainMenu AS MainMenu NO-UNDO.

loginDialog = NEW login().

loginDialog:ShowModalDialog().

IF NOT Progress.Util.EnumHelper:AreEqual(loginDialog:DialogResult,
                               System.Windows.Forms.DialogResult:OK) THEN
  QUIT.   

DELETE OBJECT loginDialog.

/* Run the actual application */

mainMenu = NEW MainMenu ().
mainMenu:Show().

WAIT-FOR System.Windows.Forms.Application:Run(MainMenu).

QUIT.

Posted by Admin on 30-Jul-2010 15:48

rbf schrieb:

From Future Proof Software's OpenEdge GUI for .NET Workshop:

/* startup.p */

DEFINE VARIABLE loginDialog AS login NO-UNDO.
DEFINE VARIABLE mainMenu AS MainMenu NO-UNDO.

loginDialog = NEW login().

loginDialog:ShowModalDialog().

IF NOT Progress.Util.EnumHelper:AreEqual(loginDialog:DialogResult,
                               System.Windows.Forms.DialogResult:OK) THEN
  QUIT.   

DELETE OBJECT loginDialog.

/* Run the actual application */

mainMenu = NEW MainMenu ().
mainMenu:Show().

WAIT-FOR System.Windows.Forms.Application:Run(MainMenu).

QUIT.

Note that it's note required to Show() a Form before using it with Application:Run().

See: http://msdn.microsoft.com/en-us/library/ms157902.aspx

Posted by rbf on 30-Jul-2010 16:41

mikefe wrote:

Note that it's note required to Show() a Form before using it with Application:Run().

See: http://msdn.microsoft.com/en-us/library/ms157902.aspx

OK thanks.

This thread is closed