繁体   English   中英

Windows XP上不显示Windows Form BackgroundImage属性-启动画面问题

[英]Windows Form BackgroundImage property not displaying on Windows XP - Splash Screen Issue

[更新]我已经使用了Hans Passant的示例和评论中的链接,并且效果很好。 感谢大家的帮助,我不确定在评论时如何选择答案,因此我将在顶部包含此更新,以供将来的观看者使用。

因此,我试图将启动屏幕显示在winforms应用程序中,同时在后台加载excel实例,并允许显示公司徽标和联系信息。

我是Winforms的新手,但是从Internet上的教程中,我发现您可以创建一个“空”表单并将UI更改为无边界表单,并且将您的启动画面作为BackgroundImage属性。 我已经完成了一个.bmp文件,并使用此代码显示它。

    private void Form1_Load(object sender, EventArgs e)
    {
        SplashScreen splash = new SplashScreen(); 
        var start = DateTime.Now;

        splash.Show();
        xlHelper = new ExcelHelper();
        var end = DateTime.Now;

        Thread.Sleep(3000 - ((start - end).Milliseconds));
        splash.Close();           
    } 

这在我的Windows 8机器和另一台Windows 7机器上似乎可以正常工作,但是在XP(SP3)上却无法显示,什么也没有。

在下面,我更改了它的显示属性,并包含了FixedSingle FormBorderStyle而不是None,它正在显示下面的内容。 因此,它正在加载初始屏幕,但无法显示背景。 有人对此有见识吗? 谢谢。

空启动画面

这是一种方法。

[Program.cs]
static class Program
{
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
           var formMain = new Forms.FormMain();
           var splash = new Forms.FormSplash( formMain );
           splash.Show();
           Application.DoEvents();
           Application.Run( formMain );
        }
}

[FormMain.cs]
public partial class FormMain : Form
{
        public FormMain()
        {
            // This Form is initially invisible.
            // The splash screen Form is responsible to making this form visible.
            //
            this.Opacity = 0;

            InitializeComponent();
        }
}

[FormSplash.cs]
    public partial class FormSplash : Form
    {
        Forms.FormMain _theMainForm;

        public FormSplash()
        {
            InitializeComponent();

            // ctlLogoText is a RichTextBox control.
            //

            this.ctlLogoText.BorderStyle = BorderStyle.None;
            this.ctlLogoText.Rtf = SR.LogoText;
        }

        public FormSplash( Forms.FormMain theMainForm )
            : this()
        {
            _theMainForm = theMainForm;

            Application.Idle += new EventHandler( Application_Idle );
        }

        void Application_Idle( object sender, EventArgs e )
        {
            Application.Idle -= new EventHandler( Application_Idle );

            if ( null != _theMainForm )
            {
                // theTimer is a System.Windows.Forms.Timer.
                //
                this.theTimer.Interval = Math.Min( 5000, Math.Max( 1000, 1000 * Settings.Default.SplashDelay ) );
                this.theTimer.Start();
            }
        }

        void theTimer_Tick( object sender, EventArgs e )
        {
            this.theTimer.Stop();
            this.Close();

            Application.DoEvents();

            _theMainForm.Opacity = 100;
            _theMainForm.Refresh();
            _theMainForm = null;
        }
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM