【问题标题】:How do I make the form partially transparent when moving?移动时如何使表单部分透明?
【发布时间】:2010-11-15 02:23:09
【问题描述】:

如何在通过拖动标题栏移动表单时将 winform 的不透明度设置为 50% 左右,并在鼠标左键打开后将其不透明度重置为 100%。

【问题讨论】:

  • @Imsasu:WinForms 是 .NET 中使用的表单的非官方名称。

标签: .net winforms drag-and-drop opacity titlebar


【解决方案1】:

有趣的是,您也可以在 OnResizeBegin 和 OnResizeEnd 覆盖中执行此操作 - 这将适用于移动和调整表单大小。

如果您只想在移动时更改不透明度,而不是在调整大小时更改,那么 alex 的答案会更好。

【讨论】:

    【解决方案2】:

    Form.Opacity 设置为 0.5,以响应表单 WndProc 中的 WM_NCLBUTTONDOWN

    然后在收到WM_NCLBUTTONUP 时将 Opacity 设置为 1.0。

    【讨论】:

      【解决方案3】:

      这是一个代码示例:

          public partial class Form1 : System.Windows.Forms.Form
      {
          private const long BUTTON_DOWN_CODE = 0xa1;
          private const long BUTTON_UP_CODE = 0xa0;
          private const long WM_MOVING = 0x216;
      
          static bool left_button_down = false;
      
          protected override void DefWndProc(ref System.Windows.Forms.Message m)
          {
              //Check the state of the Left Mouse Button
              if ((long)m.Msg == BUTTON_DOWN_CODE)
                  left_button_down = true;
              else if ((long)m.Msg == BUTTON_UP_CODE)
                  left_button_down = false;
      
              if (left_button_down)
              {
                  if ((long)m.Msg == WM_MOVING)
                  {
                      //Set the forms opacity to 50% if user is moving
                      if (this.Opacity != 0.5)
                          this.Opacity = 0.5;
                  }
              }
      
              else if (!left_button_down)
                  if (this.Opacity != 1.0)
                      this.Opacity = 1.0;
      
              base.DefWndProc(ref m);
          }
      }
      

      【讨论】:

        猜你喜欢
        • 2010-12-05
        • 1970-01-01
        • 2014-09-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多