using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Threading;namespace WindowsApplication45 { public partial class Form1 : Form { Form F = new Form(); ProgressBar PB = new ProgressBar(); delegate void SetValue(int Value); public Form1() { InitializeComponent(); this.StartPosition = FormStartPosition.CenterScreen; this.ShowInTaskbar = false; this.WindowState = FormWindowState.Minimized; F.TopMost = true; F.Show(); PB.Parent = F; PB.Maximum = 30000; Thread T = new Thread(new ParameterizedThreadStart(SetValueThread)); T.Start(PB.Maximum); } void SetValueThread(Object MaxValue) { for (int i = 0; i <= (int)MaxValue; i++) PB.Invoke(new SetValue(DoSetValue), new Object[] { i }); } void DoSetValue(int Value) { PB.Value = Value; if (PB.Value == PB.Maximum) { F.Close(); // 处于同一个线程 this.ShowInTaskbar = true; // 处于同一个线程 this.WindowState = FormWindowState.Normal; // 处于同一个线程 } } } }
show()是显示为无模式窗体,调用它以后会立即返回执行其后面的代码,因此show出来的窗体不会再刷新了,所以图片不会动。 showdialog()是显示为有模式窗体,调用它以后,如果窗体不关闭程序是不会往下执行的,因此图片是会动的。我的解决方法是这样的 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 welcomformDemo { public partial class FrmMain : Form { private Frmwelcom wel;//欢迎窗体 private delegate DialogResult showmethod(); private delegate void closemethod();//声明两个代理 public FrmMain() { InitializeComponent(); } /// <summary> /// 主窗体load事件处理 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void FrmMain_Load(object sender, EventArgs e) { wel = new Frmwelcom(); showmethod s = new showmethod(wel.ShowDialog); //用wel.ShowDialog函数来实例化代理 s.BeginInvoke(null, null);//异步调用,调用后立即返回,此时欢迎窗体在另一个线程运行,不会被阻塞,图片显示正常 this.Location = wel.Location; //…………do some slow work…… Thread.Sleep(1000); //………… this.Invoke(new closemethod(wel.Close));//花费时间长的事情做完后,要回到欢迎窗体所在的线程将其关闭 } } }在此要更正一下20楼那位同志说的话,pictruebox是可以显示动态gif图片的
1.设置窗体的相应属性:
this.ControlBox = false;
this.FormBorderStyle = FormBorderStyle.None;
this.ShowInTaskbar = false;
2.利用多线程...
//program class
//……
Application.Run(new Form1());//form1是你放了gif图片的窗体,可以放一个timer,让它运行一段时间以后就自己退出,然后程序就会向下执行了
Application.Run(new Form2());//from2是你的主程序了
web的话,登录的时候显示图片,并用setTimeout来让浏览器过1秒左右再提交
Winform的话,异步/多线程~
当开始登陆时候,
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
在Application.Run(new Form1());代码前面先显示图片,然后在执行Application.Run(new Form1());
给工程添加一个窗体,名为splash.cs,添加一个PictureBox把你想显示的图片添加到PictureBox里面。
在属性里面设置FormBorderSytle为None或在Form_Load中添加
private void Form1_Load(object sender, EventArgs e)
{
this.FormBorderStyle = FormBorderStyle.None;
}
假设你主窗体是Main.cs
在你的Program.cs中添加代码如下
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
splash mySplash = new splash();
mySplash.Show();
Main frmMain = new Main();
//控制显示时间
System.Threading.Thread.Sleep(1000);
mySplash.Close();
mySplash.Dispose();
Application.Run(frmMain);
}
当抛砖引玉好了。
mySplash.Show();
这句话后面还应该跟一句
mySplash.Refresh();
否则界面上的图片就不现实了
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;namespace WindowsApplication45
{ public partial class Form1 : Form
{
Form F = new Form();
ProgressBar PB = new ProgressBar();
delegate void SetValue(int Value); public Form1()
{
InitializeComponent(); this.StartPosition = FormStartPosition.CenterScreen;
this.ShowInTaskbar = false;
this.WindowState = FormWindowState.Minimized; F.TopMost = true;
F.Show(); PB.Parent = F;
PB.Maximum = 30000; Thread T = new Thread(new ParameterizedThreadStart(SetValueThread));
T.Start(PB.Maximum); } void SetValueThread(Object MaxValue)
{
for (int i = 0; i <= (int)MaxValue; i++)
PB.Invoke(new SetValue(DoSetValue), new Object[] { i });
} void DoSetValue(int Value)
{
PB.Value = Value;
if (PB.Value == PB.Maximum)
{
F.Close(); // 处于同一个线程
this.ShowInTaskbar = true; // 处于同一个线程
this.WindowState = FormWindowState.Normal; // 处于同一个线程
}
}
}
}
如果改为ShowDialog()图片是动态的 但是不会跳到主窗口 怎么办??
非要显示的话试一下ImageAnimator
自己写个显示动画的方法
不过那就麻烦点了
showdialog()是显示为有模式窗体,调用它以后,如果窗体不关闭程序是不会往下执行的,因此图片是会动的。我的解决方法是这样的
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 welcomformDemo
{
public partial class FrmMain : Form
{
private Frmwelcom wel;//欢迎窗体
private delegate DialogResult showmethod();
private delegate void closemethod();//声明两个代理 public FrmMain()
{
InitializeComponent();
}
/// <summary>
/// 主窗体load事件处理
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void FrmMain_Load(object sender, EventArgs e)
{
wel = new Frmwelcom();
showmethod s = new showmethod(wel.ShowDialog); //用wel.ShowDialog函数来实例化代理
s.BeginInvoke(null, null);//异步调用,调用后立即返回,此时欢迎窗体在另一个线程运行,不会被阻塞,图片显示正常
this.Location = wel.Location;
//…………do some slow work……
Thread.Sleep(1000);
//…………
this.Invoke(new closemethod(wel.Close));//花费时间长的事情做完后,要回到欢迎窗体所在的线程将其关闭
}
}
}在此要更正一下20楼那位同志说的话,pictruebox是可以显示动态gif图片的