Coc*_*Dev 5 c# wpf splash-screen visual-studio-2010 c#-4.0
我需要有一个PNG(透明度)作为启动画面.图像的透明部分应该是清晰的,以便用户可以看到它后面(或桌面)的任何窗口.
我还需要显示启动画面5秒钟(合同特别说5秒)并且它不能更短.我知道VS 2010中的构建属性,但启动画面来得太快(不到5秒).
我该怎么办才能让它停留5秒钟(大约)
我有一个类似的问题,我无法在WPF项目中使用内置的splashscreen选项.
该项目现已开源,您可以在这里查看:https://code.google.com/p/theomniscientchimp/
这是一个自动更新程序(我猜你不需要一些东西).
这是您应该需要的最低限度:
WPF方面:
<Window x:Class="TheOmniscientChimp.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:CustomXaml"
Icon="SC2_Replay_Monkey.ico"
Title="MainWindow" Height="256" Width="456" Background="#00005555" AllowsTransparency="True" WindowStyle="None" WindowStartupLocation="CenterScreen" >
<Grid Width="Auto">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Image Name="splashScreenImage" Stretch="Fill" Grid.Row="0" />
</Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)
C#侧(代码背后):
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
BitmapImage splashScreenImageSource = new BitmapImage();
splashScreenImageSource.BeginInit();
splashScreenImageSource.UriSource = new Uri("Your_Image.png", UriKind.Relative);
splashScreenImageSource.EndInit();
splashScreenImage.Source = splashScreenImageSource;
}
public void AsynchronousExit()
{
BackgroundWorker worker = new BackgroundWorker();
worker.DoWork += new DoWorkEventHandler(worker_DoWork);
worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(worker_RunWorkerCompleted);
worker.RunWorkerAsync();
}
private void worker_DoWork(object sender, DoWorkEventArgs e)
{
//Makes the thread wait for 5s before exiting.
Thread.Sleep(5000);
}
private void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
Environment.Exit(0);
}
}
Run Code Online (Sandbox Code Playgroud)
如果您需要帮助进行调整,请告诉我.
FB.
如果我不得不这样做,我会添加一个窗口,并设置其属性AllowsTransparency = true;设置它开始加载在此之前一切形式我的意思是可以通过修改完成之前App.xml,并设置Startup="Application_Startup
为禁用,你必须设置顶defauld控制WindowStyle = none
,并有在其代码
private void Application_Startup(object sender, StartupEventArgs e)
{
MainWindow mn = new MainWindow();
mn.ShowDialog();
}
Run Code Online (Sandbox Code Playgroud)
使用计时器做你想做的事
private DispatcherTimer timer;
timer = new DispatcherTimer();
timer.Tick += new EventHandler(timer_Tick);
timer.Interval = TimeSpan.FromMilliseconds(5000);
timer.IsEnabled = true;
void timer_Tick(object sender, EventArgs e)
{
///Close your window here
}
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助
| 归档时间: |
|
| 查看次数: |
10045 次 |
| 最近记录: |