c#中点关闭窗口时怎么使窗口渐渐消失?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c#中点关闭窗口时怎么使窗口渐渐消失?相关的知识,希望对你有一定的参考价值。

万分感谢!!!

参考技术A 楼上貌似调了Windows的接口,应该可以实现。我建议你一种简单的方法,可以逐渐减少窗体的透明度,最后关闭窗口。具体的做法是定义一个Timer对象,点击关闭按钮时即使Timer对象.Start();然后每隔一段时间修改透明度,即this.Opacity属性,最后如果Opacity为0了,再关闭窗口。 参考技术B /******************************************************************
*
* 说明:
*
* 1.命名空间: Apc_AniWindow
* 类名 : AniWindow
*
* 2.声明: AniWindow a=new AniWindow(this.Handle,100,1,this);
*
* 3.参数说明:AniWindow(窗口句柄,动画样式,打开或关闭标志,实例表单);
* 窗口句柄: this.Handle
* 动画样式: 0 -> 普通显示
* 1 -> 从左向右显示
* 2 -> 从右向左显示
* 3 -> 从上到下显示
* 4 -> 从下到上显示
* 5 -> 透明渐变显示
* 6 -> 从中间向四周
* 7 -> 左上角伸展
* 8 -> 左下角伸展
* 9 -> 右上角伸展
* 10 -> 右下角伸展
* 开关标志: 0为关闭窗口 1为打开窗口
* 实例表单: 为了去除Label的BUG, 取值 this
*
* ===============================无敌分割线================================
*
* 另有不得不说的BUG,目前只知当FORM上有可视的Label的时候,会出错,现已解决.
* 但不知道还有没有别的控件会引发错误,
*
* 还有,如果是Form上的Label,程序会自动设为不可视,如果是Panel里面的....X_X 还是会出错.
* 所以,如果你的程序里有LABEL,还是在PANEL中,,,那你只好自己写代码来实现可视不可视喽...
*
******************************************************************/
using System;
using System.Windows.Forms;
namespace Apc_AniWindow

/// <summary>
/// Class1 的摘要说明。
/// </summary>
public class AniWindow

[System.Runtime.InteropServices.DllImport("user32")]
private static extern bool AnimateWindow(IntPtr hwnd,int dwTime, int dwFlags);
private const int AW_HOR_POSITIVE = 0x0001;
private const int AW_HOR_NEGATIVE = 0x0002;
private const int AW_VER_POSITIVE = 0x0004;
private const int AW_VER_NEGATIVE = 0x0008;
private const int AW_CENTER = 0x0010;
private const int AW_HIDE = 0x10000;
private const int AW_ACTIVATE = 0x20000;
private const int AW_SLIDE = 0x40000;
private const int AW_BLEND = 0x80000;
private int CloseOpen=0x20000; public AniWindow(IntPtr hwnd,int dwFlags,int CloseOrOpen,System.Windows.Forms.Form myform)

try

if(CloseOrOpen==1)

foreach(System.Windows.Forms.Control mycontrol in myform.Controls)

string m=mycontrol.GetType().ToString();
m=m.Substring(m.Length-5);
if(m=="Label")

mycontrol.Visible=false; //这里是在动画效果之前,把表单上可视的LABEL设为不可视



//打开or关闭 0是关闭 1是打开
if(CloseOrOpen==0)CloseOpen=0x10000;
if(dwFlags==100)

int zz=10;
Random a=new Random();
dwFlags=(int)a.Next(zz);

switch(dwFlags)

case 0://普通显示
AnimateWindow(hwnd,200,AW_ACTIVATE);
break;
case 1://从左向右显示
AnimateWindow(hwnd,200,AW_HOR_POSITIVE|CloseOpen);
break;
case 2://从右向左显示
AnimateWindow(hwnd,200,AW_HOR_NEGATIVE|CloseOpen);
break;
case 3://从上到下显示
AnimateWindow(hwnd,200,AW_VER_POSITIVE|CloseOpen);
break;
case 4://从下到上显示
AnimateWindow(hwnd,200,AW_VER_NEGATIVE|CloseOpen);
break;
case 5://透明渐变显示
AnimateWindow(hwnd,200,AW_BLEND|CloseOpen);
break;
case 6://从中间向四周
AnimateWindow(hwnd,200,AW_CENTER|CloseOpen);
break;
case 7://左上角伸展
AnimateWindow(hwnd,200,AW_SLIDE|AW_HOR_POSITIVE|AW_VER_POSITIVE|CloseOpen);
break;
case 8://左下角伸展
AnimateWindow(hwnd,200,AW_SLIDE|AW_HOR_POSITIVE|AW_VER_NEGATIVE|CloseOpen);
break;
case 9://右上角伸展
AnimateWindow(hwnd,200,AW_SLIDE|AW_HOR_NEGATIVE|AW_VER_POSITIVE|CloseOpen);
break;
case 10://右下角伸展
AnimateWindow(hwnd,200,AW_SLIDE|AW_HOR_NEGATIVE|AW_VER_NEGATIVE|CloseOpen);
break;

if(CloseOrOpen==1)

foreach(System.Windows.Forms.Control mycontrol in myform.Controls)

string m=mycontrol.GetType().ToString();
m=m.Substring(m.Length-5);
if(m=="Label")

mycontrol.Visible=true; //这里恢复LABEL的可视.




catch


初步完成的,要真正使用,还需要你自己修改...最近有点忙,你自己弄下吧

Node.js 服务器只能存在于 cmd 窗口中吗?当cmd窗口关闭时一切都会消失?

【中文标题】Node.js 服务器只能存在于 cmd 窗口中吗?当cmd窗口关闭时一切都会消失?【英文标题】:Can Node.js server only exist in the cmd window? And everything will be gone when cmd window is shut? 【发布时间】:2018-01-13 01:00:29 【问题描述】:

与作为服务运行的操作系统相比,是不是有点不方便,后者看起来更稳定且不易碎?

很抱歉,我才刚刚开始探索 Node.js。我知道 Node.js 确实很棒,只是我对它不熟悉。所以请原谅我这个可能很愚蠢的问题。

【问题讨论】:

【参考方案1】:

有一个名为forever的服务化工具,即使退出cmd,node.js应用也会继续运行。

【讨论】:

【参考方案2】:

也许这就是您正在寻找的答案。

How to make a node.js application run permanently?

可能重复的问题。

【讨论】:

是的。非常感谢!

以上是关于c#中点关闭窗口时怎么使窗口渐渐消失?的主要内容,如果未能解决你的问题,请参考以下文章

c#关闭窗口怎么强制退出所有运行的线程

C#里面,子窗口关闭以后,刷新一个父窗口的控件的属性,怎么办

winform中点击打开一个窗口,再次点击的时候那个窗口怎么办?

c# 通过窗口名字关闭窗口

c#里面如何显示下一个窗体而关闭当前窗体?

C# WPF 建立渐隐窗口