C#WinForm程序不不在任务栏显示的处理方法
http://blog.sina.com.cn/s/blog_4c6e822d0102e0dg.html
在我用c#写一些小程序是总是希望,程序窗体不在任务栏上显示程序的窗体,c# Form提供了一个
属性值可以很好的解决这个问题
这个属性就是 ShowInTaskbar
在微软的官方声明格式为:
public bool ShowInTaskbar { get; set; }
及可以通过这个属性来获取或设置一个值
这个属性值的默认值是true 就是要在任务栏上显示窗体,如果我们想不显示就直接在load事件中加上如下语句
this.ShowInTaskbar =false
C#利用API,做像QQ系统消息 一样的右下角弹出窗体
http://blog.sina.com.cn/s/blog_60e2dbcf0100gh2w.html
实例源码:通过测试!
首先要引入命名空间:
using System.Runtime.InteropServices;
下面是一个API接口类:
public class Win32
{
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;
public const Int32 AW_HIDE = 0x00010000;
public const Int32 AW_ACTIVATE = 0x00020000;
public const Int32 AW_SLIDE = 0x00040000;
public const Int32 AW_BLEND = 0x00080000;
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern bool AnimateWindow(
IntPtr hwnd, // handle to window
int dwTime, // duration of animation
int dwFlags // animation type
);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern bool SetWindowPos(
IntPtr hwnd,
int hWndInsertAfter,
int x,
int y,
int cx,
int cy,
int wFlags
);
}
在Form load事件里如下:
int x = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Size.Width - this.Width-10;
int y = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Size.Height - this.Height-10;
this.SetDesktopLocation(x, y);
Win32.SetWindowPos(this.Handle, 100, Screen.PrimaryScreen.Bounds.Width - this.Width, Screen.PrimaryScreen.Bounds.Height - this.Height - 30, 50, 50, 1);
Win32.AnimateWindow(this.Handle, 500, Win32.AW_VER_NEGATIVE);
C#中WinForm窗口闪烁或任务栏图标闪烁的代码
http://www.blue1000.com/bkhtml/2012-12/71006.htm
近日为来电通来电弹屏软件优化来电通知方式,要求即实用又人性化,即实现消息通知的目的,又不影响用户现有的操作。于是参考了QQ的消息通知方式:让窗口闪烁或者任务栏图标闪烁。
代码使用了Windows API的以下函数:
[DllImport("user32.dll")] //闪烁窗体
public static extern bool FlashWindowEx(ref FLASHWINFO pwfi);
用到了以下常量及结构体:
[StructLayout(LayoutKind.Sequential)]
public struct FLASHWINFO
{
public UInt32 cbSize;
public IntPtr hwnd;
public UInt32 dwFlags;
public UInt32 uCount;
public UInt32 dwTimeout;
}
//闪烁窗体参数
public const UInt32 FLASHW_STOP = 0;//停止闪动.系统将窗体恢复到初始状态.
public const UInt32 FLASHW_CAPTION = 1;//闪动窗体的标题.
public const UInt32 FLASHW_TRAY = 2;//闪动任务栏按钮
public const UInt32 FLASHW_ALL = 3;//闪动窗体标题和任务栏按钮
public const UInt32 FLASHW_TIMER = 4;//连续不停的闪动,直到此参数被设置为:FLASHW_STOP
public const UInt32 FLASHW_TIMERNOFG = 12;//连续不停的闪动,直到窗体用户被激活.通常用法将参数设置为: FLASHW_ALL | FLASHW_TIMERNOFG
使用方法函数:
/// <summary>
/// 窗口闪烁
/// </summary>
/// <param name="handle">窗口句柄</param>
public static void FlashWindow(IntPtr handle)
{
FLASHWINFO fInfo = new FLASHWINFO();
fInfo.cbSize = Convert.ToUInt32(System.Runtime.InteropServices.Marshal.SizeOf(fInfo));
fInfo.hwnd = handle;
fInfo.dwFlags = FLASHW_ALL | FLASHW_TIMERNOFG;//这里是闪动窗标题和任务栏按钮,直到用户激活窗体
fInfo.uCount = UInt32.MaxValue;
fInfo.dwTimeout = 0;
FlashWindowEx(ref fInfo);
}