日期:2014-05-18  浏览次数:20702 次

如何实现panel或是类似容器的收缩,展开功能
for(int i=this.Loginpanel.Location.X;i>=0;i--)用这种效果的话。只能是收缩到form的边框上。但是如果想实现收缩至隐藏整个panel,能实现吗???????

------解决方案--------------------
using System.Runtime.InteropServices; 


#region//api
[DllImport("user32")]
private static extern bool AnimateWindow(IntPtr whnd, int dwtime, int dwflag);
//dwflag的取值如下
public const Int32 AW_HOR_POSITIVE = 0x00000001;
//从左到右显示
public const Int32 AW_HOR_NEGATIVE = 0x00000002;
//从右到左显示
public const Int32 AW_VER_POSITIVE = 0x00000004;
//从上到下显示
public const Int32 AW_VER_NEGATIVE = 0x00000008;
//从下到上显示
public const Int32 AW_CENTER = 0x00000010;
//若使用了AW_HIDE标志,则使窗口向内重叠,即收缩窗口;否则使窗口向外扩展,即展开窗口
public const Int32 AW_HIDE = 0x00010000;
//隐藏窗口,缺省则显示窗口
public const Int32 AW_ACTIVATE = 0x00020000;
//激活窗口。在使用了AW_HIDE标志后不能使用这个标志
public const Int32 AW_SLIDE = 0x00040000;
//使用滑动类型。缺省则为滚动动画类型。当使用AW_CENTER标志时,这个标志就被忽略
public const Int32 AW_BLEND = 0x00080000;
//透明度从高到低
#endregion

//从左到右 参数自己根据上面的替换实现不同的现实效果
AnimateWindow("控件或窗体名称".Handle, 1000, AW_SLIDE | AW_HIDE | AW_HOR_POSITIVE);
"控件或窗体名称".Show
------解决方案--------------------
这样最后就可以隐藏掉啊:
private void button1_Click(object sender, EventArgs e)
{
for (int i = this.panel1.Height,j = this.panel1.Width; i >= 0 && j >= 0; i--,j--)
{
this.panel1.Height = i;
this.panel1.Width = j;
System.Threading.Thread.Sleep(10);
Application.DoEvents();
}
}