waitdialogform z

  1. namespace DevExpress.Utils
  2. {
  3.     using DevExpress.LookAndFeel;
  4.     using DevExpress.Skins;
  5.     using DevExpress.Utils.Drawing;
  6.     using DevExpress.XtraEditors;
  7.     using System;
  8.     using System.ComponentModel;
  9.     using System.Drawing;
  10.     using System.Reflection;
  11.     using System.Windows.Forms;
  12.     public class WaitDialogForm : XtraForm
  13.     {
  14.         private Font boldFont;
  15.         private string caption;
  16.         private Font font;
  17.         private PictureBox pic;
  18.         private string title;
  19.         public WaitDialogForm() : this("")
  20.         {
  21.         }
  22.         public WaitDialogForm(string caption) : this(caption, "")
  23.         {
  24.         }
  25.         public WaitDialogForm(string caption, Size size) : this(caption, "", size, null)
  26.         {
  27.         }
  28.         public WaitDialogForm(string caption, string title) : this(caption, title, new Size(260, 50), null)
  29.         {
  30.         }
  31.         public WaitDialogForm(string caption, string title, Size size) : this(caption, title, size, null)
  32.         {
  33.         }
  34.         public WaitDialogForm(string caption, string title, Size size, Form parent)
  35.         {
  36.             this.caption = "";
  37.             this.title = "";
  38.             this.boldFont = new Font("Arial", 9f, FontStyle.Bold);
  39.             this.font = new Font("Arial", 9f);
  40.             this.caption = caption;
  41.             this.title = (title == "") ? "Loading Data. Please Wait." : title;
  42.             this.pic = new PictureBox();
  43.             base.FormBorderStyle = FormBorderStyle.FixedDialog;
  44.             base.ControlBox = false;
  45.             base.ClientSize = size;
  46.             if (parent == null)
  47.             {
  48.                 base.StartPosition = FormStartPosition.CenterScreen;
  49.             }
  50.             else
  51.             {
  52.                 base.StartPosition = FormStartPosition.Manual;
  53.                 base.Left = parent.Left + ((parent.Width - base.Width) / 2);
  54.                 base.Top = parent.Top + ((parent.Height - base.Height) / 2);
  55.             }
  56.             base.ShowInTaskbar = false;
  57.             base.TopMost = true;
  58.             base.Paint += new PaintEventHandler(this.WaitDialogPaint);
  59.             this.pic.Size = new Size(0x10, 0x10);
  60.             this.pic.Location = new Point(8, (base.ClientSize.Height / 2) - 0x10);
  61.             this.pic.Image = Image.FromStream(Assembly.GetExecutingAssembly().GetManifestResourceStream("DevExpress.Utils.wait.gif"));
  62.             base.Controls.Add(this.pic);
  63.             base.Show();
  64.             this.Refresh();
  65.         }
  66.         public string GetCaption()
  67.         {
  68.             return this.Caption;
  69.         }
  70.         protected override void OnClosing(CancelEventArgs e)
  71.         {
  72.             this.pic.Image = null;
  73.             this.boldFont = null;
  74.             this.font = null;
  75.             base.OnClosing(e);
  76.         }
  77.         public void SetCaption(string newCaption)
  78.         {
  79.             this.Caption = newCaption;
  80.         }
  81.         private void WaitDialogPaint(object sender, PaintEventArgs e)
  82.         {
  83.             Rectangle clipRectangle = e.ClipRectangle;
  84.             clipRectangle.Inflate(-1, -1);
  85.             GraphicsCache cache = new GraphicsCache(e);
  86.             using (StringFormat format = new StringFormat())
  87.             {
  88.                 Brush solidBrush = cache.GetSolidBrush(LookAndFeelHelper.GetSystemColor(base.LookAndFeel, SystemColors.WindowText));
  89.                 format.Alignment = format.LineAlignment = StringAlignment.Center;
  90.                 format.Trimming = StringTrimming.EllipsisCharacter;
  91.                 if (base.LookAndFeel.ActiveLookAndFeel.ActiveStyle == ActiveLookAndFeelStyle.Skin)
  92.                 {
  93.                     ObjectPainter.DrawObject(cache, new SkinTextBorderPainter(base.LookAndFeel), new BorderObjectInfoArgs(null, clipRectangle, null));
  94.                 }
  95.                 else
  96.                 {
  97.                     ControlPaint.DrawBorder3D(e.Graphics, clipRectangle, Border3DStyle.RaisedInner);
  98.                 }
  99.                 clipRectangle.X += 30;
  100.                 clipRectangle.Width -= 30;
  101.                 clipRectangle.Height /= 3;
  102.                 clipRectangle.Y += clipRectangle.Height / 2;
  103.                 e.Graphics.DrawString(this.title, this.boldFont, solidBrush, clipRectangle, format);
  104.                 clipRectangle.Y += clipRectangle.Height;
  105.                 e.Graphics.DrawString(this.caption, this.font, solidBrush, clipRectangle, format);
  106.                 cache.Dispose();
  107.             }
  108.         }
  109.         public override bool AllowFormSkin
  110.         {
  111.             get
  112.             {
  113.                 return false;
  114.             }
  115.         }
  116.         public string Caption
  117.         {
  118.             get
  119.             {
  120.                 return this.caption;
  121.             }
  122.             set
  123.             {
  124.                 this.caption = value;
  125.                 this.Refresh();
  126.             }
  127.         }
  128.     }
  129. }
posted on 2017-11-05 19:17  武胜-阿伟  阅读(417)  评论(0编辑  收藏  举报