C#的WinForms AnimateWindow问题 [英] C# WinForms AnimateWindow issue

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

问题描述

我使用下面的代码进行动画的窗口。
让我解释一下我的程序一点点的视觉结构。我有一个FlowLayoutPanel的坐落在我的Form1的顶部,位于顶部的FlowLayoutPanel的也不少分组框中对象。 。最后我有一个按钮,位于组框顶部的无形的RichTextBox对象

I am using the following code to animate a window. Let me explain the visual structure of my program a little bit. I have one FlowLayoutPanel located on top of my Form1 and also many GroupBox objects located on top the FlowLayoutPanel. And finally I have one Button and an invisible RichTextBox object located on top of the GroupBox.

例如:Form1-> FlowLayoutPanel-> GroupBox->按钮RichTextBox的(无形)

ex: Form1->FlowLayoutPanel->GroupBox->Button and RichTextBox(invisible)

我想要实现的是,当我点击按钮的对象,我希望我的RichTextBox向下滑动。我试了一下通过创建一个按钮,并在我的主要形式上面一个RichTextBox和它的工作完美的罚款。然而,当我使用的GroupBox控件在运行时做同样的事情,我的动画函数抛出未知异常。

What I'm trying to achieve is, when I click the Button object, I want my RichTextBox to slide downwards. I tried it by creating one button and a RichTextBox on top of my main Form and it worked perfectly fine. However, when I try the same thing using the GroupBox controls at runtime, my Animate function throws an unknown exception.

class Effects
{
public enum Effect { Roll, Slide, Center, Blend }

public static void Animate(Control ctl, Effect effect, int msec, int angle)
{
    int flags = effmap[(int)effect];
    if (ctl.Visible) { flags |= 0x10000; angle += 180; }
    else
    {
        if (ctl.TopLevelControl == ctl) flags |= 0x20000;
        else if (effect == Effect.Blend) throw new ArgumentException();
    }
    flags |= dirmap[(angle % 360) / 45];
    bool ok = AnimateWindow(ctl.Handle, msec, flags);
    if (!ok) throw new Exception("Animation failed");
    ctl.Visible = !ctl.Visible;
}

private static int[] dirmap = { 1, 5, 4, 6, 2, 10, 8, 9 };
private static int[] effmap = { 0, 0x40000, 0x10, 0x80000 };

[DllImport("user32.dll")]
public static extern bool AnimateWindow(IntPtr handle, int msec, int flags);
}



我也注意到,当我打电话使用的RichTextBox的父$ B $的动画功能b如Effects.Animate(textBox.parent,Effects.Effect.Slide,150,90);

I also noticed that when I call the Animate function using RichTextBox's parent e.g Effects.Animate(textBox.parent, Effects.Effect.Slide, 150, 90);

动漫作品没有任何问题。
我不知道为什么它与父,而不是实际对象的作品。
如Effects.Animate(文本框中Effects.Effect.Slide,150,90);

the animation works without any problem. I don't know why it works with the parent and not the actual object. e.g Effects.Animate(textBox, Effects.Effect.Slide, 150, 90);

推荐答案

我测试了代码和它的作品甚至在文本框(上RichTextBox的工作也不过事实证明,其中i类型恢复到原来的黑色,只有区)。

I tested your code and it works even on the textboxes (worked on richtextbox also but it turned black and only areas where i types returned to their original colour).

确保控制要运行该代码上必须隐藏被称为效应函数之前。例如,我叫Effects.Animate(textBox1的,Effects.Effect.Center,1000,120);并且textBox1.Visible设定为在设计假

Make sure the control you want to run this code on must be hidden before the effect function is called. For example, I called Effects.Animate(textBox1, Effects.Effect.Center, 1000, 120); and the textBox1.Visible was set to false in the designer.

维杰

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

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