Display a dialog once my main form is showing?

G

Grant Schenck

I have a C# form application. Once my main window is showing I want to
pop-up a login type dialog. What event would I trap to affect this? I
tried handling the form load but the main form window is not yet visible
then.

Thanks!

Grant Schenck
 
N

Nicholas Paldino [.NET/C# MVP]

Grant,

You will want to use the Activated event to handle this. First, you
have to define a flag in your class:

// Default to false, indicating that the form is not activated for the first
time.
private bool firstTimeActivation = true;

Then, you have to handle the Activated event:

// If the flag is true, then show your login form.
if (firstTimeActivation)
{
// Set the flag to false here. The reason for this is that when
// your login form is closed, this form will activate again, and
// this will be called again before you exit this block for the first
// time.
firstTimeActivation = !firstTimeActivation;

// Show your login form here.
}

Hope this helps.
 
M

Metallikanz!

There are many events which are fired while the form is getting loaded, painted:

Activated, GotFocus, LayOut.... Please consult MSDN for type Form and have a look at the Event section.

HTH, Metallikanz!
 
G

Grant Schenck

Thank you!

That did the trick.

Grant Schenck

Nicholas Paldino said:
Grant,

You will want to use the Activated event to handle this. First, you
have to define a flag in your class:

// Default to false, indicating that the form is not activated for the first
time.
private bool firstTimeActivation = true;

Then, you have to handle the Activated event:

// If the flag is true, then show your login form.
if (firstTimeActivation)
{
// Set the flag to false here. The reason for this is that when
// your login form is closed, this form will activate again, and
// this will be called again before you exit this block for the first
// time.
firstTimeActivation = !firstTimeActivation;

// Show your login form here.
}

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Grant Schenck said:
I have a C# form application. Once my main window is showing I want to
pop-up a login type dialog. What event would I trap to affect this? I
tried handling the form load but the main form window is not yet visible
then.

Thanks!

Grant Schenck
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

It does depend if you want to have the back window visible or not, if not
use Load ( the good thing of this one is that it fires only once ) if you
want it visible you could follow Nicholas's suggestion.

cheers,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top