.NET AnimateWindow [英] .NET AnimateWindow

查看:246
本文介绍了.NET AnimateWindow的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做一个通知窗口就像当你收到新的电子邮件Outlook使用。我有一个无模式形式通知窗口,上面有两个Label控件来显示通知信息。要获得淡入效果,我P /调用的Win32 AnimateWindow功能。一切似乎是正常的工作,除了一件事。

I am trying to make a notification window like Outlook uses when you receive a new email. I have a modeless form for the notification window with two Label controls on it to display the notification info. To get the fade-in effect, I am p/invoking the Win32 AnimateWindow function. Everything seems to be working alright except for one thing.

在我的P / Invoke AnimateWindow,在Label控件中的文本只出现在表格后动画效果已经结束。我想它逐渐淡出与窗体的其余部分。我怀疑它是与当表单更新其子控件。我在想,该表格没有告诉其子更新,直到AnimateWindow调用之后。我试图坚持Form.Update()设置文本框的标签后调用,但这并不能帮助。

When I p/invoke AnimateWindow, the text in the Label controls just appears on the Form after the animation effect is over. I would like it to gradually fade in with the rest of the Form. I suspect that it has something to do with when the Form updates its child controls. I'm thinking that the Form doesn't tell its children to update until after the AnimateWindow call. I have tried sticking Form.Update() calls after setting the text fields for the Labels, but that doesn't help.

基本步骤,我现在正服下的:

Basic steps I'm taking now:

// 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 );
   }
}

没有人有任何建议,得到这个工作?

Does anyone have any suggestions to get this to work?

编辑:
我摸索出了黑客攻击。标签文本分配后,我设置了敬酒的大小为0,宽度和高度为0。接下来,我先打电话显示,然后隐藏在祝酒。然后,我设置了烤面包的大小回到它最初。最后,我呼吁AnimateWindow上致祝酒辞。是啊,它的工作原理,但它是一个黑客...任何更好的想法?


I worked out a hack. After the Label text is assigned, I set the toast's size to 0 width and 0 height. Next I call first Show and then Hide on the toast. Then I set the toast's size back to what it was originally. Finally, I call AnimateWindow on the toast. Yeah, it works, but it is a hack... Any better ideas?

推荐答案

还有就是这个对的 $ C $的CProject 网站。

There is a great example of this on the codeproject site.

这篇关于.NET AnimateWindow的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆