WPF随笔

导航

WinForm Splash的简单实现

WinForm Splash的简单实现

  1. 从Form派生一个新类
  2. 设置一张图片到BackgroundImage属性。
  3. 重写OnPaintBackground 画上版本号

        protected override void OnPaintBackground(PaintEventArgs e)
        {
            base.OnPaintBackground(e);

            Version version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
            string build = version.Build.ToString("0000");
            string versionText = string.Format("{0}.{1}.{2}", version.Major, version.Minor, build);

            versionText = string.Format("Version {0}", versionText);
            SizeF strSize = e.Graphics.MeasureString(versionText, this.Font);
            Point pt = new Point(this.ClientRectangle.Right - (int)strSize.Width - 5, this.ClientRectangle.Bottom - (int)strSize.Height - 3);
            e.Graphics.DrawString(versionText, this.Font, new SolidBrush(this.ForeColor), pt);
        }

posted on 2009-05-16 21:26  Jeffery Sun  阅读(628)  评论(0编辑  收藏  举报