1

[更新] Hans Passant によるコメントの例とリンクを使用しましたが、うまく機能しています。皆さんの助けに感謝します。コメントの場合に回答を選択する方法がわからないので、将来の視聴者のためにこの更新を上部に含めます.

そのため、Excel インスタンスがバックグラウンドで読み込まれ、会社のロゴと連絡先情報が表示されるようにしながら、スプラッシュ スクリーンを winforms アプリケーションに表示しようとしています。

私はwinformsは初めてですが、インターネット上のチュートリアルから、「空の」フォームを作成し、スプラッシュをBackgroundImageプロパティとして使用してUIをボーダレスフォームに変更できることがわかりました。私は .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) では何も表示されません。

以下では、表示プロパティを変更し、None の代わりに FixedSingle FormBorderStyle を含めて、下にあるものを表示しています。そのため、スプラッシュ画面を読み込んでいますが、背景を表示できません。誰かがこれについて何か洞察を持っていますか? ありがとう。

空のスプラッシュ スクリーン

4

1 に答える 1

0

ここにそれを行う1つの方法があります。

[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;
        }
    }
于 2013-11-11T04:03:45.507 に答える