WinForm 窗体右下方提示信息 WinForm 的程序。打算在窗体右下方提示信息,像QQ的重大事件右下方出来个小窗体吧,请问怎么做,还有这么做的从下向上缓慢移动上来,然后在缓缓下去呢? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 可以自己写啊,做个小窗体,用timer控件.Load事件里://控制窗体的初始位置和高度,位置可以根据屏幕大小来决定.this.Top = XX;this.Left = XX;this.Height = XX;Timer_Click事件:上来时:if(this.Height < 窗体设计器里本来的大小){ this.Top += 5;//这个数值自己看着定 this.Height += 5;//这个数值和上面的相同}下去时:if(this.Height > Load事件里初始的高度){ this.Top -= 5;//这个数值自己看着定 this.Height -= 5;//这个数值和上面的相同}else{ this.Close();} UP ,原来我 做过,现在忘了,重新学习一下,原来我根到一个例子实现过,他用了 几个 Timer 搞得效果差不多是那么回事,但好象太费了..期望有更好方案. using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.Drawing.Drawing2D;using System.Runtime.InteropServices;namespace TaskbarForm{ public partial class TaskbarForm : Form { public Bitmap BackgroundBitmap = null; private string titleText; private string contentText; private Color normalTitleColor = Color.FromArgb(0, 0, 0); private Font normalTitleFont = new Font("宋体", 12, FontStyle.Regular, GraphicsUnit.Pixel); private Color normalContentColor = Color.FromArgb(0, 0, 0); private Font normalContentFont = new Font("宋体", 12, FontStyle.Regular, GraphicsUnit.Pixel); public Rectangle TitleRectangle; public Rectangle TitlebarRectangle; public Rectangle ContentRectangle; public Rectangle CloseBtnRectangle; private Rectangle WorkAreaRectangle; private int SavedTop; private int currentTop = 1; private int intervalValue = 2; public const int WM_NCLBUTTONDOWN = 0x00A1; //消息:左键点击 winuser.h public const int HT_CAPTION = 0x0002; //标题栏 [DllImportAttribute("user32.dll")] public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam); //发送消息 //winuser.h 中有函数原型定义 [DllImportAttribute("user32.dll")] public static extern bool ReleaseCapture(); //释放鼠标捕捉 winuser.h [DllImportAttribute("user32.dll")] //winuser.h private static extern Boolean ShowWindow(IntPtr hWnd, Int32 nCmdShow); public int CurrentState=0; //0=hide 1=uptoshow 2=showing 3=downtohide public TaskbarForm() { InitializeComponent(); } public void SetBackgroundBitmap(Image image, Color transparencyColor) { BackgroundBitmap = new Bitmap(image); Width = BackgroundBitmap.Width; Height = BackgroundBitmap.Height; Region = BitmapToRegion(BackgroundBitmap, transparencyColor); } public Region BitmapToRegion(Bitmap bitmap, Color transparencyColor) { if (bitmap == null) throw new ArgumentNullException("Bitmap", "Bitmap cannot be null!"); int height = bitmap.Height; int width = bitmap.Width; GraphicsPath path = new GraphicsPath(); for (int j = 0; j < height; j++) for (int i = 0; i < width; i++) { if (bitmap.GetPixel(i, j) == transparencyColor) continue; int x0 = i; while ((i < width) && (bitmap.GetPixel(i, j) != transparencyColor)) i++; path.AddRectangle(new Rectangle(x0, j, i - x0, 1)); } Region region = new Region(path); path.Dispose(); return region; } protected void DrawText(Graphics grfx) { if (titleText != null && titleText.Length != 0) { StringFormat sf = new StringFormat(); sf.Alignment = StringAlignment.Near; sf.LineAlignment = StringAlignment.Center; sf.FormatFlags = StringFormatFlags.NoWrap; sf.Trimming = StringTrimming.EllipsisCharacter; grfx.DrawString(titleText, normalTitleFont, new SolidBrush(normalTitleColor), TitleRectangle, sf); } if (contentText != null && contentText.Length != 0) { StringFormat sf = new StringFormat(); sf.Alignment = StringAlignment.Center; sf.LineAlignment = StringAlignment.Center; sf.FormatFlags = StringFormatFlags.MeasureTrailingSpaces; sf.Trimming = StringTrimming.Word; grfx.DrawString(contentText, normalContentFont, new SolidBrush(normalContentColor), ContentRectangle, sf); } } protected override void OnPaintBackground(PaintEventArgs e) { Graphics grfx = e.Graphics; grfx.PageUnit = GraphicsUnit.Pixel; Graphics offScreenGraphics; Bitmap offscreenBitmap; offscreenBitmap = new Bitmap(BackgroundBitmap.Width, BackgroundBitmap.Height); offScreenGraphics = Graphics.FromImage(offscreenBitmap); if (BackgroundBitmap != null) { offScreenGraphics.DrawImage(BackgroundBitmap, 0, 0, BackgroundBitmap.Width, BackgroundBitmap.Height); } DrawText(offScreenGraphics); grfx.DrawImage(offscreenBitmap, 0, 0); } public void ShowForm(string ftitletext, string fcontenttext, Rectangle fRegionofFormTitle, Rectangle fRegionofFormTitlebar, Rectangle fRegionofFormContent, Rectangle fRegionofCloseBtn) { titleText = ftitletext; contentText = fcontenttext; WorkAreaRectangle = Screen.GetWorkingArea(WorkAreaRectangle); this.Top = WorkAreaRectangle.Height + this.Height; FormBorderStyle = FormBorderStyle.None; WindowState = FormWindowState.Normal; this.SetBounds(WorkAreaRectangle.Width - this.Width, WorkAreaRectangle.Height - currentTop, this.Width, this.Height); CurrentState = 1; timer1.Enabled = true; TitleRectangle = fRegionofFormTitle; TitlebarRectangle = fRegionofFormTitlebar; ContentRectangle = fRegionofFormContent; CloseBtnRectangle = fRegionofCloseBtn; ShowWindow(this.Handle, 4); //#define SW_SHOWNOACTIVATE 4 } private void timer1_Tick(object sender, EventArgs e) { if (CurrentState == 1) { this.SetBounds(WorkAreaRectangle.Width - this.Width, WorkAreaRectangle.Height - currentTop, this.Width, this.Height); currentTop = currentTop + intervalValue; if (this.Top <= WorkAreaRectangle.Height - this.Height) { timer1.Enabled = false; CurrentState = 2; timer2.Enabled = true; //显示停留计时 currentTop = 1; } } else if (CurrentState==3) { this.SetBounds(WorkAreaRectangle.Width - this.Width, SavedTop + currentTop, this.Width, this.Height); currentTop = currentTop + intervalValue; if (this.Top >= WorkAreaRectangle.Height) { timer1.Enabled = false; this.Hide(); CurrentState = 0; currentTop = 1; } } } private void TaskbarForm_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { if (TitlebarRectangle.Contains(e.Location)) //单击标题栏时拖动 { ReleaseCapture(); //释放鼠标捕捉 SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0); //发送左键点击的消息至该窗体(标题栏) } if (CloseBtnRectangle.Contains(e.Location)) //单击Close按钮关闭 { this.Hide(); currentTop = 1; } if (ContentRectangle.Contains(e.Location )) //单击内容区域 { System.Diagnostics.Process.Start("http://www.Rithia.com"); } } } private void timer2_Tick(object sender, EventArgs e) { timer2.Enabled = false; CurrentState = 1; currentTop = 1; SavedTop = this.Top; CurrentState = 3; timer1.Enabled = true; } private void TaskbarForm_MouseMove(object sender, MouseEventArgs e) { if (ContentRectangle.Contains(e.Location)) { Cursor = Cursors.Hand; } else Cursor = Cursors.Default; } }} using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;namespace TaskbarForm{ public partial class Form1 : Form { private TaskbarForm tf; public Form1() { InitializeComponent(); tf = new TaskbarForm(); } private void button2_Click(object sender, EventArgs e) { Application.Exit(); } private void button1_Click(object sender, EventArgs e) { if (tf.CurrentState==0) { tf.Hide(); tf.SetBackgroundBitmap(new Bitmap("popup2.bmp"), Color.FromArgb(255, 0, 255)); Rectangle TitleRectangle = new Rectangle(2, 1, 70, 25); Rectangle TitlebarRectangle = new Rectangle(1, 1, tf.Width , 25); Rectangle ContentRectangle = new Rectangle(100, 41, 133, 68); Rectangle ClosebtnRectangle = new Rectangle(tf.Width -25, 1, 25 , 25); tf.ShowForm("提示", "这是关于DemoOfTaskbarForm的提示内容。", TitleRectangle, TitlebarRectangle,ContentRectangle, ClosebtnRectangle); } } private void Form1_Load(object sender, EventArgs e) { } }} 1、在窗体右下角,就用状态栏2、如果在任务栏上显示,就用NotifyIcon控件,用notifyIcon1.ShowBalloonTip来显示消息 c# 调用floodfill的问题 三层架构之数据库的增删改的问题 webservice 问题 在C#中子窗口如何控制父窗口 用SqlParemeter提交参数出现错误 如何制作c#windows应用程序的安装部署? 怎么能像公安那样测到手机现在在什么位置? 简单的问题,讨论的都有分... 一个好问题 。。。。答对100分 如何把两个TextBox内输入的数字经过数学运算的结果赋給另一个TextBox 怎样给 ExcuteNonQurey加上trans(只有最后14分了) Attribute如何同时应用在多个对象上
Load事件里:
//控制窗体的初始位置和高度,位置可以根据屏幕大小来决定.
this.Top = XX;
this.Left = XX;
this.Height = XX;Timer_Click事件:
上来时:
if(this.Height < 窗体设计器里本来的大小)
{
this.Top += 5;//这个数值自己看着定
this.Height += 5;//这个数值和上面的相同
}
下去时:
if(this.Height > Load事件里初始的高度)
{
this.Top -= 5;//这个数值自己看着定
this.Height -= 5;//这个数值和上面的相同
}
else
{
this.Close();
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using System.Runtime.InteropServices;namespace TaskbarForm
{
public partial class TaskbarForm : Form
{
public Bitmap BackgroundBitmap = null; private string titleText;
private string contentText;
private Color normalTitleColor = Color.FromArgb(0, 0, 0);
private Font normalTitleFont = new Font("宋体", 12, FontStyle.Regular, GraphicsUnit.Pixel);
private Color normalContentColor = Color.FromArgb(0, 0, 0);
private Font normalContentFont = new Font("宋体", 12, FontStyle.Regular, GraphicsUnit.Pixel); public Rectangle TitleRectangle;
public Rectangle TitlebarRectangle;
public Rectangle ContentRectangle;
public Rectangle CloseBtnRectangle; private Rectangle WorkAreaRectangle; private int SavedTop;
private int currentTop = 1;
private int intervalValue = 2; public const int WM_NCLBUTTONDOWN = 0x00A1; //消息:左键点击 winuser.h
public const int HT_CAPTION = 0x0002; //标题栏 [DllImportAttribute("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam); //发送消息 //winuser.h 中有函数原型定义
[DllImportAttribute("user32.dll")]
public static extern bool ReleaseCapture(); //释放鼠标捕捉 winuser.h
[DllImportAttribute("user32.dll")] //winuser.h
private static extern Boolean ShowWindow(IntPtr hWnd, Int32 nCmdShow); public int CurrentState=0; //0=hide 1=uptoshow 2=showing 3=downtohide public TaskbarForm()
{
InitializeComponent();
} public void SetBackgroundBitmap(Image image, Color transparencyColor)
{
BackgroundBitmap = new Bitmap(image);
Width = BackgroundBitmap.Width;
Height = BackgroundBitmap.Height;
Region = BitmapToRegion(BackgroundBitmap, transparencyColor);
} public Region BitmapToRegion(Bitmap bitmap, Color transparencyColor)
{
if (bitmap == null)
throw new ArgumentNullException("Bitmap", "Bitmap cannot be null!"); int height = bitmap.Height;
int width = bitmap.Width; GraphicsPath path = new GraphicsPath(); for (int j = 0; j < height; j++)
for (int i = 0; i < width; i++)
{
if (bitmap.GetPixel(i, j) == transparencyColor)
continue; int x0 = i; while ((i < width) && (bitmap.GetPixel(i, j) != transparencyColor))
i++; path.AddRectangle(new Rectangle(x0, j, i - x0, 1));
} Region region = new Region(path);
path.Dispose();
return region;
} protected void DrawText(Graphics grfx)
{
if (titleText != null && titleText.Length != 0)
{
StringFormat sf = new StringFormat();
sf.Alignment = StringAlignment.Near;
sf.LineAlignment = StringAlignment.Center;
sf.FormatFlags = StringFormatFlags.NoWrap;
sf.Trimming = StringTrimming.EllipsisCharacter;
grfx.DrawString(titleText, normalTitleFont, new SolidBrush(normalTitleColor), TitleRectangle, sf);
} if (contentText != null && contentText.Length != 0)
{
StringFormat sf = new StringFormat();
sf.Alignment = StringAlignment.Center;
sf.LineAlignment = StringAlignment.Center;
sf.FormatFlags = StringFormatFlags.MeasureTrailingSpaces;
sf.Trimming = StringTrimming.Word;
grfx.DrawString(contentText, normalContentFont, new SolidBrush(normalContentColor), ContentRectangle, sf);
}
} protected override void OnPaintBackground(PaintEventArgs e)
{
Graphics grfx = e.Graphics;
grfx.PageUnit = GraphicsUnit.Pixel; Graphics offScreenGraphics;
Bitmap offscreenBitmap; offscreenBitmap = new Bitmap(BackgroundBitmap.Width, BackgroundBitmap.Height);
offScreenGraphics = Graphics.FromImage(offscreenBitmap); if (BackgroundBitmap != null)
{
offScreenGraphics.DrawImage(BackgroundBitmap, 0, 0, BackgroundBitmap.Width, BackgroundBitmap.Height);
} DrawText(offScreenGraphics); grfx.DrawImage(offscreenBitmap, 0, 0);
} public void ShowForm(string ftitletext, string fcontenttext, Rectangle fRegionofFormTitle, Rectangle fRegionofFormTitlebar, Rectangle fRegionofFormContent, Rectangle fRegionofCloseBtn)
{
titleText = ftitletext;
contentText = fcontenttext;
WorkAreaRectangle = Screen.GetWorkingArea(WorkAreaRectangle);
this.Top = WorkAreaRectangle.Height + this.Height;
FormBorderStyle = FormBorderStyle.None;
WindowState = FormWindowState.Normal;
this.SetBounds(WorkAreaRectangle.Width - this.Width, WorkAreaRectangle.Height - currentTop, this.Width, this.Height);
CurrentState = 1;
timer1.Enabled = true;
TitleRectangle = fRegionofFormTitle;
TitlebarRectangle = fRegionofFormTitlebar;
ContentRectangle = fRegionofFormContent;
CloseBtnRectangle = fRegionofCloseBtn; ShowWindow(this.Handle, 4); //#define SW_SHOWNOACTIVATE 4
} private void timer1_Tick(object sender, EventArgs e)
{
if (CurrentState == 1)
{
this.SetBounds(WorkAreaRectangle.Width - this.Width, WorkAreaRectangle.Height - currentTop, this.Width, this.Height);
currentTop = currentTop + intervalValue;
if (this.Top <= WorkAreaRectangle.Height - this.Height)
{
timer1.Enabled = false;
CurrentState = 2;
timer2.Enabled = true; //显示停留计时
currentTop = 1;
}
}
else if (CurrentState==3)
{
this.SetBounds(WorkAreaRectangle.Width - this.Width, SavedTop + currentTop, this.Width, this.Height);
currentTop = currentTop + intervalValue;
if (this.Top >= WorkAreaRectangle.Height)
{
timer1.Enabled = false; this.Hide();
CurrentState = 0;
currentTop = 1;
}
}
} private void TaskbarForm_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
if (TitlebarRectangle.Contains(e.Location)) //单击标题栏时拖动
{
ReleaseCapture(); //释放鼠标捕捉
SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0); //发送左键点击的消息至该窗体(标题栏)
}
if (CloseBtnRectangle.Contains(e.Location)) //单击Close按钮关闭
{
this.Hide();
currentTop = 1;
}
if (ContentRectangle.Contains(e.Location )) //单击内容区域
{
System.Diagnostics.Process.Start("http://www.Rithia.com");
}
}
} private void timer2_Tick(object sender, EventArgs e)
{
timer2.Enabled = false;
CurrentState = 1;
currentTop = 1;
SavedTop = this.Top;
CurrentState = 3;
timer1.Enabled = true;
} private void TaskbarForm_MouseMove(object sender, MouseEventArgs e)
{
if (ContentRectangle.Contains(e.Location))
{
Cursor = Cursors.Hand;
}
else
Cursor = Cursors.Default;
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace TaskbarForm
{
public partial class Form1 : Form
{
private TaskbarForm tf; public Form1()
{
InitializeComponent();
tf = new TaskbarForm();
} private void button2_Click(object sender, EventArgs e)
{
Application.Exit();
} private void button1_Click(object sender, EventArgs e)
{
if (tf.CurrentState==0)
{
tf.Hide();
tf.SetBackgroundBitmap(new Bitmap("popup2.bmp"), Color.FromArgb(255, 0, 255)); Rectangle TitleRectangle = new Rectangle(2, 1, 70, 25);
Rectangle TitlebarRectangle = new Rectangle(1, 1, tf.Width , 25);
Rectangle ContentRectangle = new Rectangle(100, 41, 133, 68);
Rectangle ClosebtnRectangle = new Rectangle(tf.Width -25, 1, 25 , 25); tf.ShowForm("提示", "这是关于DemoOfTaskbarForm的提示内容。", TitleRectangle, TitlebarRectangle,ContentRectangle, ClosebtnRectangle);
}
} private void Form1_Load(object sender, EventArgs e)
{ }
}
}
2、如果在任务栏上显示,就用NotifyIcon控件,用notifyIcon1.ShowBalloonTip来显示消息