Bonjour,
J'ai un problème de focus quand je lance mon appli, qui fait apparaître au préalable un splashscreen.
Si d'autres applications sont déjà lancées, le splash s'affiche, puis se ferme et le form principal s'affiche, mais en arrière plan, car c'est une autre appli qui a pris le focus.
Est-ce dû au fait que j'appelle le splash dans un thread ?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Threading; namespace Splash { public partial class MainForm : Form { private static bool EndSplash = false; public MainForm() { InitializeComponent(); // Affichage du SplashScreen Thread th = new Thread(new ThreadStart(ShowSplash)); th.Start(); Thread.Sleep(2000); // Pause de 2 secondes pour voir le splash même si initialisation rapide EndSplash = true; // Donne le signal de fin du splash pour sortir de la boucle d'attente dans la procédure ShowSplash } private void ShowSplash() { Splash sp = new Splash(); sp.Show(); while (!EndSplash) Application.DoEvents(); sp.Dispose(); } } }
Comment faire pour que ce soit mon appli qui garde le focus ?
Merci.
Partager