C#中的动画面板

我试图在按钮点击时添加一个面板.我的代码在下面,我做到了.但现在我正试图在我的面板上放置其他按钮等,当你点击第一个按钮和面板幻灯片时,我没有任何新按钮.

//Constants
    const int AW_SLIDE = 0X40000;
    const int AW_HOR_POSITIVE = 0X1;
    const int AW_HOR_NEGATIVE = 0X2;
    const int AW_BLEND = 0X80000;

        [DllImport("user32")]

        static extern bool AnimateWindow(IntPtr hwnd,int time,int flags);
        photosflag=0;

 private void photosbutton_Click(object sender,EventArgs e)
        {
            if (photosflag == 0)
            {
                object O = Controller.Properties.Resources.ResourceManager.Getobject("photospressed");
                photosbutton.Image = (System.Drawing.Image)O;
                photosflag = 1;
                int ylocation = photosbutton.Location.Y;
                //Set the Location
                photospanel.Location = new Point(101,ylocation);

                //Animate form
                AnimateWindow(photospanel.Handle,500,AW_SLIDE | AW_HOR_POSITIVE);


            }
            else
            {
                object O = Controller.Properties.Resources.ResourceManager.Getobject("photos");
                photosbutton.Image = (System.Drawing.Image)O;
                photosflag = 0;
                photospanel.Visible = false;

            }


        }

在photospanel我有三个图片框.但是当面板显示(滑入)图片框时,就不存在了.

解决方法

好的 – 这是一个非常简单的例子,它不依赖于AnimateWindow API:

向表单添加计时器控件.在我的,我将间隔设置为10(毫秒).您可以使用此值来根据需要平滑动画

我在表单上有按钮和面板(不可见)

我在表单上声明了以下私有成员 – 它们是面板的起始X位置,结束位置和每个增量移动的像素数 – 再次,调整以影响速度/平滑度等

private int _startLeft = -200;  // start position of the panel
private int _endLeft = 10;      // end position of the panel
private int _stepSize = 10;     // pixels to move

然后在按钮上单击,我启用计时器:

animationTimer.Enabled = true;

最后,计时器tick事件中的代码使面板可见,将其移动到位,并在完成时禁用自身:

private void animationTimer_Tick(object sender,EventArgs e)
{
    // if just starting,move to start location and make visible
    if (!photosPanel.Visible)
    {
        photosPanel.Left = _startLeft;
        photosPanel.Visible = true;
    }

    // incrementally move
    photosPanel.Left += _stepSize;
    // make sure we didn't over shoot
    if (photosPanel.Left > _endLeft) photosPanel.Left = _endLeft;

    // have we arrived?
    if (photosPanel.Left == _endLeft)
    {
        animationTimer.Enabled = false;
    }            
}

相关文章

目录简介使用JS互操作使用ClipLazor库创建项目使用方法简单测...
目录简介快速入门安装 NuGet 包实体类User数据库类DbFactory...
本文实现一个简单的配置类,原理比较简单,适用于一些小型项...
C#中Description特性主要用于枚举和属性,方法比较简单,记录...
[TOC] # 原理简介 本文参考[C#/WPF/WinForm/程序实现软件开机...
目录简介获取 HTML 文档解析 HTML 文档测试补充:使用 CSS 选...