<tfoot id='2GMNP'></tfoot>
      <bdo id='2GMNP'></bdo><ul id='2GMNP'></ul>

    <legend id='2GMNP'><style id='2GMNP'><dir id='2GMNP'><q id='2GMNP'></q></dir></style></legend>

      <small id='2GMNP'></small><noframes id='2GMNP'>

        <i id='2GMNP'><tr id='2GMNP'><dt id='2GMNP'><q id='2GMNP'><span id='2GMNP'><b id='2GMNP'><form id='2GMNP'><ins id='2GMNP'></ins><ul id='2GMNP'></ul><sub id='2GMNP'></sub></form><legend id='2GMNP'></legend><bdo id='2GMNP'><pre id='2GMNP'><center id='2GMNP'></center></pre></bdo></b><th id='2GMNP'></th></span></q></dt></tr></i><div id='2GMNP'><tfoot id='2GMNP'></tfoot><dl id='2GMNP'><fieldset id='2GMNP'></fieldset></dl></div>

        Javascript 类似 WinForms 的模态窗口

        时间:2023-10-05
      1. <tfoot id='4Pd4b'></tfoot>
        <legend id='4Pd4b'><style id='4Pd4b'><dir id='4Pd4b'><q id='4Pd4b'></q></dir></style></legend>
          <tbody id='4Pd4b'></tbody>

          • <bdo id='4Pd4b'></bdo><ul id='4Pd4b'></ul>
            1. <small id='4Pd4b'></small><noframes id='4Pd4b'>

                  <i id='4Pd4b'><tr id='4Pd4b'><dt id='4Pd4b'><q id='4Pd4b'><span id='4Pd4b'><b id='4Pd4b'><form id='4Pd4b'><ins id='4Pd4b'></ins><ul id='4Pd4b'></ul><sub id='4Pd4b'></sub></form><legend id='4Pd4b'></legend><bdo id='4Pd4b'><pre id='4Pd4b'><center id='4Pd4b'></center></pre></bdo></b><th id='4Pd4b'></th></span></q></dt></tr></i><div id='4Pd4b'><tfoot id='4Pd4b'></tfoot><dl id='4Pd4b'><fieldset id='4Pd4b'></fieldset></dl></div>
                  本文介绍了Javascript 类似 WinForms 的模态窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  有没有人知道一个好的模态窗口控件,类似于 Javascript 中使用的那些,但可用于具有透明背景的 WinForms (C#) 等等.

                  Does anybody know a good Modal Window control sort of like the ones used in Javascript but available for WinForms (C#) with the transparent background and all.

                  Javascript 示例http://okonet.ru/projects/modalbox/

                  Example in Javascript http://okonet.ru/projects/modalbox/

                  有点像

                  ModalCoolForm f = new ModalCoolForm();
                  f.ShowDialog(this);
                  

                  推荐答案

                  这是一个自定义表单,可以满足您的需求...根据您的喜好进行更改:

                  Here is a custom Form that'll do what you want... alter to your taste:

                  public partial class ModalLoadingUI : Form
                  {
                      #region Constants
                      private readonly Color BackgroundFadeColor = Color.FromArgb(50, Color.Black);
                      #endregion
                  
                      #region Constructors
                      public ModalLoadingUI()
                      {
                          InitializeComponent();
                      }
                      #endregion
                  
                      #region Properties
                      /// <summary>
                      /// Gets or Sets the main form that will be used as a background canvas for the loading form.
                      /// </summary>
                      public Form BackgroundForm { get; set; }
                  
                      /// <summary>
                      /// Gets or Sets the text to displayed as the progress text.
                      /// </summary>
                      public string Title
                      { 
                          get
                          {
                              return label1.Text;
                          }
                  
                          set
                          {
                              label1.Text = value;
                          }
                      }
                  
                      /// <summary>
                      /// Gets or Sets the value of the progress bar.
                      /// </summary>
                      public int? Progress
                      {
                          get
                          {
                              if (progressBar1.Style == ProgressBarStyle.Marquee)
                              {
                                  return null;
                              }
                              else
                              {
                                  return progressBar1.Value;
                              }
                          }
                  
                          set
                          {
                              if (value == null)
                              {
                                  progressBar1.Style = ProgressBarStyle.Marquee;
                                  progressBar1.Value = 100;
                  
                                  label2.Visible = false;
                              }
                              else
                              {
                                  progressBar1.Style = ProgressBarStyle.Continuous;
                                  progressBar1.Value = value.Value;
                  
                                  label2.Text = string.Format("{0}%", value);
                                  label2.Visible = true;
                              }
                          }
                      }
                  
                      /// <summary>
                      /// Gets or Sets a value to indicate if the background form should be faded out.
                      /// </summary>
                      public bool UseFadedBackground { get; set; }
                  
                      /// <summary>
                      /// Gets or Sets a value to indicate if the splash box is to be displayed.
                      /// </summary>
                      public bool UseSplashBox
                      {
                          get
                          {
                              return picShadow.Visible;
                          }
                  
                          set
                          {
                              if (value == true)
                              {
                                  picShadow.Visible = true;
                                  panel1.Visible = true;
                              }
                              else
                              {
                                  picShadow.Visible = false;
                                  panel1.Visible = false;
                              }
                          }
                      }
                      #endregion
                  
                      #region Base Events
                      private void ModalLoadingUI_Load(object sender, EventArgs e)
                      {
                          if (this.BackgroundForm != null)
                          {
                              this.Location = this.BackgroundForm.Location;
                          }
                      }
                  
                      private void ModalLoadingUI_VisibleChanged(object sender, EventArgs e)
                      {
                          if (this.Visible == true)
                          {
                              if (this.BackgroundForm != null)
                              {
                                  this.Location = this.BackgroundForm.Location;
                              }
                          }
                  
                          if (System.Diagnostics.Debugger.IsAttached == true)
                          {
                              this.TopMost = false;
                          }
                          else
                          {
                              this.TopMost = true;
                          }
                      }
                  
                      private void ModalLoadingUI_Shown(object sender, EventArgs e)
                      {
                      }
                      #endregion
                  
                      #region Public Methods
                      /// <summary>
                      /// Paints the background form as the background of this form, if one is defined.
                      /// </summary>
                      public void CaptureBackgroundForm()
                      {
                          if (this.InvokeRequired)
                          {
                              this.BeginInvoke(new MethodInvoker(CaptureBackgroundForm));
                              return;
                          }
                  
                          if (this.BackgroundForm == null)
                          {
                              return;
                          }
                  
                  
                          var bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb);
                          Graphics g = Graphics.FromImage(bmpScreenshot);
                  
                          try
                          {
                              // COPY BACKGROUND
                              int x = this.BackgroundForm.Left;
                              int y = this.BackgroundForm.Top;
                              var size = this.BackgroundForm.Size;
                  
                              g.CopyFromScreen(x, y, 0, 0, size, CopyPixelOperation.SourceCopy);
                  
                              // FADE IF DESIRED
                              if (this.UseFadedBackground == true)
                              {
                                  var rect = new Rectangle(0, 0, size.Width, size.Height);
                  
                                  g.FillRectangle(new SolidBrush(BackgroundFadeColor), rect);
                              }
                  
                              // PAINT SPLASH BOX SHADOW IF DESIRED
                              if(this.UseSplashBox == true)
                              {
                                  PaintPanelShadow(g);
                              }
                          }
                          catch (Exception e)
                          {
                              g.Clear(Color.White);
                          }
                  
                          this.BackgroundImage = bmpScreenshot;
                      }
                  
                      /// <summary>
                      /// Paints a shadow around the panel, if one is defined.
                      /// </summary>
                      /// <param name="g">The graphics object to paint into</param>
                      private void PaintPanelShadow(Graphics g)
                      {
                          var shadowImage = picShadow.Image;
                  
                          var x = panel1.Left + (panel1.Width / 2) - (shadowImage.Width / 2);
                          var y = panel1.Top + (panel1.Height / 2) - (shadowImage.Height / 2);
                  
                          g.DrawImage(shadowImage, x, y, shadowImage.Width, shadowImage.Height);
                      }
                      #endregion
                  }
                  

                  这篇关于Javascript 类似 WinForms 的模态窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:使用 jQuery 的 ASP.NET 回发? 下一篇:WinForms 编程 - 模态和非模态表单问题

                  相关文章

                      <bdo id='bfnOa'></bdo><ul id='bfnOa'></ul>

                  1. <small id='bfnOa'></small><noframes id='bfnOa'>

                    1. <legend id='bfnOa'><style id='bfnOa'><dir id='bfnOa'><q id='bfnOa'></q></dir></style></legend>

                    2. <tfoot id='bfnOa'></tfoot>
                      <i id='bfnOa'><tr id='bfnOa'><dt id='bfnOa'><q id='bfnOa'><span id='bfnOa'><b id='bfnOa'><form id='bfnOa'><ins id='bfnOa'></ins><ul id='bfnOa'></ul><sub id='bfnOa'></sub></form><legend id='bfnOa'></legend><bdo id='bfnOa'><pre id='bfnOa'><center id='bfnOa'></center></pre></bdo></b><th id='bfnOa'></th></span></q></dt></tr></i><div id='bfnOa'><tfoot id='bfnOa'></tfoot><dl id='bfnOa'><fieldset id='bfnOa'></fieldset></dl></div>