public partial class MessageForm : Form
{
public MessageForm()
{
InitializeComponent();
} 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 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 )) //单击内容区域
{
//UtilTool.setBool(true);
//ElectronRemindForm f = new ElectronRemindForm();
//f.ShowDialog();
}
}
} 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;
}
}
类似于这种右下角弹窗的,改下弹出位置,打下就行了
{
public MessageForm()
{
InitializeComponent();
} 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 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 )) //单击内容区域
{
//UtilTool.setBool(true);
//ElectronRemindForm f = new ElectronRemindForm();
//f.ShowDialog();
}
}
} 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;
}
}
类似于这种右下角弹窗的,改下弹出位置,打下就行了
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货