Problem with focus on main form after splash screen

V

Vicky

Hello,

I created a small application which
shows splash screen for a moment, and
then hides it and shows main form.
The problem is with focus on main
form. In OnLoad() method of main
form I did this.Activated(); this.focus();
It causes that my application's name blinks
on task bar, but main form still is not
on the first plan -- I mean, it is behind window
with icons I run my application from.
When I run my application from Visual
Studio, everything is OK - splash screen
and main form are on the first plan.
What to do to make main form on the first
plan?

Thanks in advance.
Vicky
 
C

C?sar F. Q?eb Montejo via DotNetMonster.com

You need run the form in a thread. See the code below for have an idea:

Dim SplashFrm As New SplashForm
Dim Thread As New Threading.Thread(AddressOf SplashFrm.FadeIn)
SplashFrm.ShowDialog() 'Show the splash window
Thread.Start()

Dim LoginFrm As New Login
'The login window or another form that return DialogResult.OK
'for continue and show the main window.
If LoginFrm.ShowDialog() = DialogResult.OK Then
Dim MainForm As New frmMain 'The main window
Try
Application.Run(MainForm)
Catch e As Exception
MessageBox.Show(e.Message)
End Try
Else 'If the user press the cancel button in the login form
Application.Exit() ' The application is terminated
End If

Best regards from Mexico
CFQ?eb
 
C

C?sar F. Q?eb Montejo via DotNetMonster.com

Sorry I'm have forgetting the code in the splash form:

Imports System.Threading
Public Class SplashForm
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()
me.Opacity=0
'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As _
Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form
'Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Timer1 As System.Windows.Forms.Timer
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.components = New System.ComponentModel.Container
Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(SplashForm))
Me.Timer1 = New System.Windows.Forms.Timer(Me.components)
'
'Timer1
'
Me.Timer1.Enabled = True
Me.Timer1.Interval = 50
'
'SplashForm
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.BackgroundImage = CType(resources.GetObject("$this.BackgroundImage"), System.Drawing.Image)
Me.ClientSize = New System.Drawing.Size(376, 224)
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None
Me.Name = "SplashForm"
Me.Opacity = 0
Me.ShowInTaskbar = False
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "SplashForm"
Me.TopMost = True

End Sub

#End Region

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Opacity += 0.02
If (Opacity >= 1) Then Close()
End Sub

Public Sub FadeIn() 'This is the delegate for the thread starts
While (Opacity < 1)
Opacity += 0.02
Thread.Sleep(175)
End While
End Sub
End Class

This code show your splash with a fade effect (from transparent to opacity = 1

Regards
CFQ?eb
 
C

C?sar F. Q?eb Montejo via DotNetMonster.com

In the constructor you have frm.TopLevel = true?
 
V

Vicky

In the constructor you have frm.TopLevel = true?If I set TopLevel = true, my app is on first level,
but task bar is not visible when I move mouse cursor
on the bottom of the screen. So, I think it is not
a solution. But maybe it is only one possible
solution in this case ?

Vicky.
 

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