代码之家  ›  专栏  ›  技术社区  ›  madhatter160

.NET动画窗口

  •  2
  • madhatter160  · 技术社区  · 17 年前

    我正在尝试创建一个通知窗口,就像您收到新电子邮件时outlook使用的一样。我有一个通知窗口的非模式表单,上面有两个标签控件来显示通知信息。为了使淡入效果生效,我正在p/调用win32 animatewindow函数。除了一件事,一切似乎都正常。

    当i p/invoke animatewindow时,标签控件中的文本仅在动画效果结束后显示在窗体上。我希望它逐渐淡入其他形式。我怀疑这与窗体更新其子控件的时间有关。我认为表单直到animatewindow调用之后才告诉其子级更新。在设置了标签的文本字段之后,我尝试了粘贴form.update()调用,但这没有帮助。

    我现在要采取的基本步骤是:

    // Main form of the application.
    public class MainForm : Form
    {
       // The notification toast.
       protected ToastForm toast;
    
       // Public method called to show and update the toast.
       public void UpdateToast( string text1, string text2 )
       {
          // Create a new toast form if one does not exist yet.
          if ( this.toast == null )
          {
             this.toast = new ToastForm();
          }
    
          // Update the toast form's Label controls.
          // Note that this isn't exactly how it's done in my app.  There are fields safely
          // wrapping the Label controls.  I just did it this way here to be concise.
          this.toast.firstLabel.Text = text1;
          this.toast.secondLabel.Text = text2;
    
          // This doesn't help.
          this.toast.Update();
    
          // P/invoke the Win32 AnimateWindow function on the toast form.
          User32.AnimateWindow( this.toast.Handle, 750, AnimateWindowFlags.AW_ACTIVATE | AnimateWindowFlags.AW_BLEND );
    
          // Call Show method on the toast form.  This is needed to get the controls to
          // update at all.
          this.toast.Show( this );
       }
    }
    

    有人有什么建议让这个工作吗?

    编辑:
    我想出了一个办法。指定标签文本后,我将toast的大小设置为0 width和0 height。下一步我叫第一场秀,然后躲在吐司上。然后我把吐司的大小改回原来的大小。最后,我在祝酒词中调用animatewindow。是的,很管用,但这是一个黑客…有更好的主意吗?

    3 回复  |  直到 14 年前
        1
  •  2
  •   Darrin Lynn    17 年前

    有一个很好的例子 codeproject 站点。

        2
  •  0
  •   SLaks    17 年前

    默认情况下,winforms控件使用gdi+来呈现文本。我怀疑这就是这种行为的原因。

    尝试禁用兼容文本呈现 in the entire application 或 for the labels 强制它改用gdi。

        3
  •  0
  •   David Anderson    14 年前

    只需使用计时器并通过其淡入窗体 Opacity 财产。对你很有用。