(二十一)c#Winform自定义控件-气泡提示
官网
前提
入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章。
GitHub:https://github.com/kwwwvagaa/NetWinformControl
码云:https://gitee.com/kwwwvagaa/net_winform_custom_control.git
如果觉得写的还行,请点个 star 支持一下吧
欢迎前来交流探讨: 企鹅群568015492 idkey=6e08741ef16fe53bf0314c1c9e336c4f626047943a8b76bac062361bab6b4f8d">
目录
https://www.cnblogs.com/bfyx/p/11364884.html
准备工作
这个窗体继承子基类窗体FrmBase,如果你对FrmBase还不了解,请移步 (十七)c#Winform自定义控件-基类窗体 查看
气泡需要支持多个位置显示,也就是说四面八方都可以显示,并且支持样式,自定义大小,另外具有内置的4中模式(成功,错误,警告,正常)
开始
定义一些枚举
public enum TipsSizeMode
{
Small,
Medium,
Large,
None
}
public enum TipsState
{
Default = -,
Success = -,
Info = -,
Warning = -,
Error = -
}
添加Form,命名FrmTips,继承自FrmBase
属性
private ContentAlignment m_showAlign = ContentAlignment.BottomLeft; /// <summary>
/// 显示位置
/// </summary>
public ContentAlignment ShowAlign
{
get { return m_showAlign; }
set { m_showAlign = value; }
} private static List<FrmTips> m_lstTips = new List<FrmTips>(); private int m_CloseTime = ; public int CloseTime
{
get { return m_CloseTime; }
set
{
m_CloseTime = value;
if (value > )
timer1.Interval = value;
}
}
提供一些公共函数
#region 清理提示框
/// <summary>
/// 功能描述:清理提示框
/// 作 者:HZH
/// 创建日期:2019-02-28 15:11:03
/// 任务编号:POS
/// </summary>
public static void ClearTips()
{
for (int i = m_lstTips.Count - ; i >= ; i--)
{
FrmTips current = m_lstTips[i];
if (!current.IsDisposed)
{
current.Close();
current.Dispose();
}
}
m_lstTips.Clear();
}
#endregion /// <summary>
/// 重置倒计时
/// </summary>
public void ResetTimer()
{
if (m_CloseTime > )
{
timer1.Enabled = false;
timer1.Enabled = true;
}
}
提供的静态函数
#region 清理提示框
/// <summary>
/// 功能描述:清理提示框
/// 作 者:HZH
/// 创建日期:2019-02-28 15:11:03
/// 任务编号:POS
/// </summary>
public static void ClearTips()
{
for (int i = m_lstTips.Count - ; i >= ; i--)
{
FrmTips current = m_lstTips[i];
if (!current.IsDisposed)
{
current.Close();
current.Dispose();
}
}
m_lstTips.Clear();
}
#endregion private static KeyValuePair<string, FrmTips> m_lastTips = new KeyValuePair<string, FrmTips>(); public static FrmTips ShowTips(
Form frm,
string strMsg,
int intAutoColseTime = ,
bool blnShowCoseBtn = true,
ContentAlignment align = ContentAlignment.BottomLeft,
Point? point = null,
TipsSizeMode mode = TipsSizeMode.Small,
Size? size = null,
TipsState state = TipsState.Default)
{ if (m_lastTips.Key == strMsg + state && !m_lastTips.Value.IsDisposed && m_lastTips.Value.Visible)
{
m_lastTips.Value.ResetTimer();
return m_lastTips.Value;
}
else
{
FrmTips frmTips = new FrmTips();
switch (mode)
{
case TipsSizeMode.Small:
frmTips.Size = new Size(, );
break;
case TipsSizeMode.Medium:
frmTips.Size = new Size(, );
break;
case TipsSizeMode.Large:
frmTips.Size = new Size(, );
break;
case TipsSizeMode.None:
if (!size.HasValue)
{
frmTips.Size = new Size(, );
}
else
{
frmTips.Size = size.Value;
}
break;
}
frmTips.BackColor = Color.FromArgb((int)state); if (state == TipsState.Default)
{
frmTips.lblMsg.ForeColor = SystemColors.ControlText;
}
else
{
frmTips.lblMsg.ForeColor = Color.White;
}
switch (state)
{
case TipsState.Default:
frmTips.pctStat.Image = HZH_Controls.Properties.Resources.alarm;
break;
case TipsState.Success:
frmTips.pctStat.Image = HZH_Controls.Properties.Resources.success;
break;
case TipsState.Info:
frmTips.pctStat.Image = HZH_Controls.Properties.Resources.alarm;
break;
case TipsState.Warning:
frmTips.pctStat.Image = HZH_Controls.Properties.Resources.warning;
break;
case TipsState.Error:
frmTips.pctStat.Image = HZH_Controls.Properties.Resources.error;
break;
default:
frmTips.pctStat.Image = HZH_Controls.Properties.Resources.alarm;
break;
} frmTips.lblMsg.Text = strMsg;
frmTips.CloseTime = intAutoColseTime;
frmTips.btnClose.Visible = blnShowCoseBtn; frmTips.ShowAlign = align;
frmTips.Owner = frm;
FrmTips.m_lstTips.Add(frmTips);
FrmTips.ReshowTips();
frmTips.Show(frm);
if (frm != null && !frm.IsDisposed)
{
ControlHelper.SetForegroundWindow(frm.Handle);
}
//frmTips.BringToFront();
m_lastTips = new KeyValuePair<string, FrmTips>(strMsg + state, frmTips);
return frmTips;
}
} #region 刷新显示
/// <summary>
/// 功能描述:刷新显示
/// 作 者:HZH
/// 创建日期:2019-02-28 15:33:06
/// 任务编号:POS
/// </summary>
public static void ReshowTips()
{
lock (FrmTips.m_lstTips)
{
FrmTips.m_lstTips.RemoveAll(p => p.IsDisposed == true);
var enumerable = from p in FrmTips.m_lstTips
group p by new
{
p.ShowAlign
};
Size size = Screen.PrimaryScreen.Bounds.Size;
foreach (var item in enumerable)
{
List<FrmTips> list = FrmTips.m_lstTips.FindAll((FrmTips p) => p.ShowAlign == item.Key.ShowAlign);
for (int i = ; i < list.Count; i++)
{
FrmTips frmTips = list[i];
if (frmTips.InvokeRequired)
{
frmTips.BeginInvoke(new MethodInvoker(delegate()
{
switch (item.Key.ShowAlign)
{
case ContentAlignment.BottomCenter:
frmTips.Location = new Point((size.Width - frmTips.Width) / , size.Height - - (i + ) * (frmTips.Height + ));
break;
case ContentAlignment.BottomLeft:
frmTips.Location = new Point(, size.Height - - (i + ) * (frmTips.Height + ));
break;
case ContentAlignment.BottomRight:
frmTips.Location = new Point(size.Width - frmTips.Width - , size.Height - - (i + ) * (frmTips.Height + ));
break;
case ContentAlignment.MiddleCenter:
frmTips.Location = new Point((size.Width - frmTips.Width) / , size.Height - (size.Height - list.Count * (frmTips.Height + )) / - (i + ) * (frmTips.Height + ));
break;
case ContentAlignment.MiddleLeft:
frmTips.Location = new Point(, size.Height - (size.Height - list.Count * (frmTips.Height + )) / - (i + ) * (frmTips.Height + ));
break;
case ContentAlignment.MiddleRight:
frmTips.Location = new Point(size.Width - frmTips.Width - , size.Height - (size.Height - list.Count * (frmTips.Height + )) / - (i + ) * (frmTips.Height + ));
break;
case ContentAlignment.TopCenter:
frmTips.Location = new Point((size.Width - frmTips.Width) / , + (i + ) * (frmTips.Height + ));
break;
case ContentAlignment.TopLeft:
frmTips.Location = new Point(, + (i + ) * (frmTips.Height + ));
break;
case ContentAlignment.TopRight:
frmTips.Location = new Point(size.Width - frmTips.Width - , + (i + ) * (frmTips.Height + ));
break;
default:
break;
}
}));
}
else
{
switch (item.Key.ShowAlign)
{
case ContentAlignment.BottomCenter:
frmTips.Location = new Point((size.Width - frmTips.Width) / , size.Height - - (i + ) * (frmTips.Height + ));
break;
case ContentAlignment.BottomLeft:
frmTips.Location = new Point(, size.Height - - (i + ) * (frmTips.Height + ));
break;
case ContentAlignment.BottomRight:
frmTips.Location = new Point(size.Width - frmTips.Width - , size.Height - - (i + ) * (frmTips.Height + ));
break;
case ContentAlignment.MiddleCenter:
frmTips.Location = new Point((size.Width - frmTips.Width) / , size.Height - (size.Height - list.Count * (frmTips.Height + )) / - (i + ) * (frmTips.Height + ));
break;
case ContentAlignment.MiddleLeft:
frmTips.Location = new Point(, size.Height - (size.Height - list.Count * (frmTips.Height + )) / - (i + ) * (frmTips.Height + ));
break;
case ContentAlignment.MiddleRight:
frmTips.Location = new Point(size.Width - frmTips.Width - , size.Height - (size.Height - list.Count * (frmTips.Height + )) / - (i + ) * (frmTips.Height + ));
break;
case ContentAlignment.TopCenter:
frmTips.Location = new Point((size.Width - frmTips.Width) / , + (i + ) * (frmTips.Height + ));
break;
case ContentAlignment.TopLeft:
frmTips.Location = new Point(, + (i + ) * (frmTips.Height + ));
break;
case ContentAlignment.TopRight:
frmTips.Location = new Point(size.Width - frmTips.Width - , + (i + ) * (frmTips.Height + ));
break;
default:
break;
}
} }
}
}
}
#endregion public static FrmTips ShowTipsSuccess(Form frm, string strMsg)
{
return FrmTips.ShowTips(frm, strMsg, , false, ContentAlignment.BottomCenter, null, TipsSizeMode.Large, null, TipsState.Success);
} public static FrmTips ShowTipsError(Form frm, string strMsg)
{
return FrmTips.ShowTips(frm, strMsg, , false, ContentAlignment.BottomCenter, null, TipsSizeMode.Large, null, TipsState.Error);
} public static FrmTips ShowTipsInfo(Form frm, string strMsg)
{
return FrmTips.ShowTips(frm, strMsg, , false, ContentAlignment.BottomCenter, null, TipsSizeMode.Large, null, TipsState.Info);
}
public static FrmTips ShowTipsWarning(Form frm, string strMsg)
{
return FrmTips.ShowTips(frm, strMsg, , false, ContentAlignment.BottomCenter, null, TipsSizeMode.Large, null, TipsState.Warning);
}
一些事件处理
private void FrmTips_FormClosing(object sender, FormClosingEventArgs e)
{
if (m_lastTips.Value == this)
m_lastTips = new KeyValuePair<string, FrmTips>();
m_lstTips.Remove(this);
ReshowTips(); for (int i = Application.OpenForms.Count - ; i >= ; i--)
{
if (Application.OpenForms[i].IsDisposed || !Application.OpenForms[i].Visible || Application.OpenForms[i] is FrmTips)
{
continue;
}
else
{
Timer t = new Timer();
t.Interval = ;
var frm = Application.OpenForms[i];
t.Tick += (a, b) =>
{
t.Enabled = false;
if (!frm.IsDisposed)
ControlHelper.SetForegroundWindow(frm.Handle);
};
t.Enabled = true;
break;
}
}
} private void FrmTips_Load(object sender, EventArgs e)
{
if (m_CloseTime > )
{
this.timer1.Interval = m_CloseTime;
this.timer1.Enabled = true;
}
} private void timer1_Tick(object sender, EventArgs e)
{
this.timer1.Enabled = false;
this.Close();
} private void btnClose_MouseDown(object sender, MouseEventArgs e)
{
this.timer1.Enabled = false;
this.Close();
}
private void FrmTips_FormClosed(object sender, FormClosedEventArgs e)
{
this.Dispose();
GC.Collect();
}
最后看一下完整代码
// 版权所有 黄正辉 交流群:568015492 QQ:623128629
// 文件名称:FrmTips.cs
// 创建日期:2019-08-15 16:04:54
// 功能描述:FrmTips
// 项目地址:https://gitee.com/kwwwvagaa/net_winform_custom_control
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms; namespace HZH_Controls.Forms
{
public partial class FrmTips : FrmBase
{
private ContentAlignment m_showAlign = ContentAlignment.BottomLeft; /// <summary>
/// 显示位置
/// </summary>
public ContentAlignment ShowAlign
{
get { return m_showAlign; }
set { m_showAlign = value; }
} private static List<FrmTips> m_lstTips = new List<FrmTips>(); private int m_CloseTime = ; public int CloseTime
{
get { return m_CloseTime; }
set
{
m_CloseTime = value;
if (value > )
timer1.Interval = value;
}
} public FrmTips()
{
base.SetStyle(ControlStyles.UserPaint, true);
base.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
base.SetStyle(ControlStyles.DoubleBuffer, true);
InitializeComponent();
} #region 清理提示框
/// <summary>
/// 功能描述:清理提示框
/// 作 者:HZH
/// 创建日期:2019-02-28 15:11:03
/// 任务编号:POS
/// </summary>
public static void ClearTips()
{
for (int i = m_lstTips.Count - ; i >= ; i--)
{
FrmTips current = m_lstTips[i];
if (!current.IsDisposed)
{
current.Close();
current.Dispose();
}
}
m_lstTips.Clear();
}
#endregion /// <summary>
/// 重置倒计时
/// </summary>
public void ResetTimer()
{
if (m_CloseTime > )
{
timer1.Enabled = false;
timer1.Enabled = true;
}
}
private static KeyValuePair<string, FrmTips> m_lastTips = new KeyValuePair<string, FrmTips>(); public static FrmTips ShowTips(
Form frm,
string strMsg,
int intAutoColseTime = ,
bool blnShowCoseBtn = true,
ContentAlignment align = ContentAlignment.BottomLeft,
Point? point = null,
TipsSizeMode mode = TipsSizeMode.Small,
Size? size = null,
TipsState state = TipsState.Default)
{ if (m_lastTips.Key == strMsg + state && !m_lastTips.Value.IsDisposed && m_lastTips.Value.Visible)
{
m_lastTips.Value.ResetTimer();
return m_lastTips.Value;
}
else
{
FrmTips frmTips = new FrmTips();
switch (mode)
{
case TipsSizeMode.Small:
frmTips.Size = new Size(, );
break;
case TipsSizeMode.Medium:
frmTips.Size = new Size(, );
break;
case TipsSizeMode.Large:
frmTips.Size = new Size(, );
break;
case TipsSizeMode.None:
if (!size.HasValue)
{
frmTips.Size = new Size(, );
}
else
{
frmTips.Size = size.Value;
}
break;
}
frmTips.BackColor = Color.FromArgb((int)state); if (state == TipsState.Default)
{
frmTips.lblMsg.ForeColor = SystemColors.ControlText;
}
else
{
frmTips.lblMsg.ForeColor = Color.White;
}
switch (state)
{
case TipsState.Default:
frmTips.pctStat.Image = HZH_Controls.Properties.Resources.alarm;
break;
case TipsState.Success:
frmTips.pctStat.Image = HZH_Controls.Properties.Resources.success;
break;
case TipsState.Info:
frmTips.pctStat.Image = HZH_Controls.Properties.Resources.alarm;
break;
case TipsState.Warning:
frmTips.pctStat.Image = HZH_Controls.Properties.Resources.warning;
break;
case TipsState.Error:
frmTips.pctStat.Image = HZH_Controls.Properties.Resources.error;
break;
default:
frmTips.pctStat.Image = HZH_Controls.Properties.Resources.alarm;
break;
} frmTips.lblMsg.Text = strMsg;
frmTips.CloseTime = intAutoColseTime;
frmTips.btnClose.Visible = blnShowCoseBtn; frmTips.ShowAlign = align;
frmTips.Owner = frm;
FrmTips.m_lstTips.Add(frmTips);
FrmTips.ReshowTips();
frmTips.Show(frm);
if (frm != null && !frm.IsDisposed)
{
ControlHelper.SetForegroundWindow(frm.Handle);
}
//frmTips.BringToFront();
m_lastTips = new KeyValuePair<string, FrmTips>(strMsg + state, frmTips);
return frmTips;
}
} #region 刷新显示
/// <summary>
/// 功能描述:刷新显示
/// 作 者:HZH
/// 创建日期:2019-02-28 15:33:06
/// 任务编号:POS
/// </summary>
public static void ReshowTips()
{
lock (FrmTips.m_lstTips)
{
FrmTips.m_lstTips.RemoveAll(p => p.IsDisposed == true);
var enumerable = from p in FrmTips.m_lstTips
group p by new
{
p.ShowAlign
};
Size size = Screen.PrimaryScreen.Bounds.Size;
foreach (var item in enumerable)
{
List<FrmTips> list = FrmTips.m_lstTips.FindAll((FrmTips p) => p.ShowAlign == item.Key.ShowAlign);
for (int i = ; i < list.Count; i++)
{
FrmTips frmTips = list[i];
if (frmTips.InvokeRequired)
{
frmTips.BeginInvoke(new MethodInvoker(delegate()
{
switch (item.Key.ShowAlign)
{
case ContentAlignment.BottomCenter:
frmTips.Location = new Point((size.Width - frmTips.Width) / , size.Height - - (i + ) * (frmTips.Height + ));
break;
case ContentAlignment.BottomLeft:
frmTips.Location = new Point(, size.Height - - (i + ) * (frmTips.Height + ));
break;
case ContentAlignment.BottomRight:
frmTips.Location = new Point(size.Width - frmTips.Width - , size.Height - - (i + ) * (frmTips.Height + ));
break;
case ContentAlignment.MiddleCenter:
frmTips.Location = new Point((size.Width - frmTips.Width) / , size.Height - (size.Height - list.Count * (frmTips.Height + )) / - (i + ) * (frmTips.Height + ));
break;
case ContentAlignment.MiddleLeft:
frmTips.Location = new Point(, size.Height - (size.Height - list.Count * (frmTips.Height + )) / - (i + ) * (frmTips.Height + ));
break;
case ContentAlignment.MiddleRight:
frmTips.Location = new Point(size.Width - frmTips.Width - , size.Height - (size.Height - list.Count * (frmTips.Height + )) / - (i + ) * (frmTips.Height + ));
break;
case ContentAlignment.TopCenter:
frmTips.Location = new Point((size.Width - frmTips.Width) / , + (i + ) * (frmTips.Height + ));
break;
case ContentAlignment.TopLeft:
frmTips.Location = new Point(, + (i + ) * (frmTips.Height + ));
break;
case ContentAlignment.TopRight:
frmTips.Location = new Point(size.Width - frmTips.Width - , + (i + ) * (frmTips.Height + ));
break;
default:
break;
}
}));
}
else
{
switch (item.Key.ShowAlign)
{
case ContentAlignment.BottomCenter:
frmTips.Location = new Point((size.Width - frmTips.Width) / , size.Height - - (i + ) * (frmTips.Height + ));
break;
case ContentAlignment.BottomLeft:
frmTips.Location = new Point(, size.Height - - (i + ) * (frmTips.Height + ));
break;
case ContentAlignment.BottomRight:
frmTips.Location = new Point(size.Width - frmTips.Width - , size.Height - - (i + ) * (frmTips.Height + ));
break;
case ContentAlignment.MiddleCenter:
frmTips.Location = new Point((size.Width - frmTips.Width) / , size.Height - (size.Height - list.Count * (frmTips.Height + )) / - (i + ) * (frmTips.Height + ));
break;
case ContentAlignment.MiddleLeft:
frmTips.Location = new Point(, size.Height - (size.Height - list.Count * (frmTips.Height + )) / - (i + ) * (frmTips.Height + ));
break;
case ContentAlignment.MiddleRight:
frmTips.Location = new Point(size.Width - frmTips.Width - , size.Height - (size.Height - list.Count * (frmTips.Height + )) / - (i + ) * (frmTips.Height + ));
break;
case ContentAlignment.TopCenter:
frmTips.Location = new Point((size.Width - frmTips.Width) / , + (i + ) * (frmTips.Height + ));
break;
case ContentAlignment.TopLeft:
frmTips.Location = new Point(, + (i + ) * (frmTips.Height + ));
break;
case ContentAlignment.TopRight:
frmTips.Location = new Point(size.Width - frmTips.Width - , + (i + ) * (frmTips.Height + ));
break;
default:
break;
}
} }
}
}
}
#endregion private void FrmTips_FormClosing(object sender, FormClosingEventArgs e)
{
if (m_lastTips.Value == this)
m_lastTips = new KeyValuePair<string, FrmTips>();
m_lstTips.Remove(this);
ReshowTips(); for (int i = Application.OpenForms.Count - ; i >= ; i--)
{
if (Application.OpenForms[i].IsDisposed || !Application.OpenForms[i].Visible || Application.OpenForms[i] is FrmTips)
{
continue;
}
else
{
Timer t = new Timer();
t.Interval = ;
var frm = Application.OpenForms[i];
t.Tick += (a, b) =>
{
t.Enabled = false;
if (!frm.IsDisposed)
ControlHelper.SetForegroundWindow(frm.Handle);
};
t.Enabled = true;
break;
}
}
} private void FrmTips_Load(object sender, EventArgs e)
{
if (m_CloseTime > )
{
this.timer1.Interval = m_CloseTime;
this.timer1.Enabled = true;
}
} private void timer1_Tick(object sender, EventArgs e)
{
this.timer1.Enabled = false;
this.Close();
} private void btnClose_MouseDown(object sender, MouseEventArgs e)
{
this.timer1.Enabled = false;
this.Close();
} public static FrmTips ShowTipsSuccess(Form frm, string strMsg)
{
return FrmTips.ShowTips(frm, strMsg, , false, ContentAlignment.BottomCenter, null, TipsSizeMode.Large, null, TipsState.Success);
} public static FrmTips ShowTipsError(Form frm, string strMsg)
{
return FrmTips.ShowTips(frm, strMsg, , false, ContentAlignment.BottomCenter, null, TipsSizeMode.Large, null, TipsState.Error);
} public static FrmTips ShowTipsInfo(Form frm, string strMsg)
{
return FrmTips.ShowTips(frm, strMsg, , false, ContentAlignment.BottomCenter, null, TipsSizeMode.Large, null, TipsState.Info);
}
public static FrmTips ShowTipsWarning(Form frm, string strMsg)
{
return FrmTips.ShowTips(frm, strMsg, , false, ContentAlignment.BottomCenter, null, TipsSizeMode.Large, null, TipsState.Warning);
} private void FrmTips_FormClosed(object sender, FormClosedEventArgs e)
{
this.Dispose();
GC.Collect();
} } public enum TipsSizeMode
{
Small,
Medium,
Large,
None
}
public enum TipsState
{
Default = -,
Success = -,
Info = -,
Warning = -,
Error = -
}
}
namespace HZH_Controls.Forms
{
partial class FrmTips
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null; /// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
} #region Windows Form Designer generated code /// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FrmTips));
this.lblMsg = new System.Windows.Forms.Label();
this.btnClose = new System.Windows.Forms.PictureBox();
this.pctStat = new System.Windows.Forms.PictureBox();
this.timer1 = new System.Windows.Forms.Timer(this.components);
((System.ComponentModel.ISupportInitialize)(this.btnClose)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pctStat)).BeginInit();
this.SuspendLayout();
//
// lblMsg
//
this.lblMsg.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.lblMsg.BackColor = System.Drawing.Color.Transparent;
this.lblMsg.Font = new System.Drawing.Font("微软雅黑", 12F);
this.lblMsg.Location = new System.Drawing.Point(, );
this.lblMsg.Name = "lblMsg";
this.lblMsg.Size = new System.Drawing.Size(, );
this.lblMsg.TabIndex = ;
this.lblMsg.Text = "提示信息";
this.lblMsg.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// btnClose
//
this.btnClose.Anchor = System.Windows.Forms.AnchorStyles.Right;
this.btnClose.BackColor = System.Drawing.Color.Transparent;
this.btnClose.Image = global::HZH_Controls.Properties.Resources.qty_delete;
this.btnClose.Location = new System.Drawing.Point(, );
this.btnClose.Name = "btnClose";
this.btnClose.Size = new System.Drawing.Size(, );
this.btnClose.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
this.btnClose.TabIndex = ;
this.btnClose.TabStop = false;
this.btnClose.MouseDown += new System.Windows.Forms.MouseEventHandler(this.btnClose_MouseDown);
//
// pctStat
//
this.pctStat.Anchor = System.Windows.Forms.AnchorStyles.Left;
this.pctStat.BackColor = System.Drawing.Color.Transparent;
this.pctStat.Image = global::HZH_Controls.Properties.Resources.alarm;
this.pctStat.Location = new System.Drawing.Point(, );
this.pctStat.Name = "pctStat";
this.pctStat.Size = new System.Drawing.Size(, );
this.pctStat.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
this.pctStat.TabIndex = ;
this.pctStat.TabStop = false;
//
// timer1
//
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// FrmTips
//
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)()))), ((int)(((byte)()))), ((int)(((byte)()))));
this.ClientSize = new System.Drawing.Size(, );
this.Controls.Add(this.btnClose);
this.Controls.Add(this.lblMsg);
this.Controls.Add(this.pctStat);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.IsFullSize = false;
this.IsShowRegion = true;
this.Name = "FrmTips";
this.ShowIcon = false;
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
this.Text = "FrmTips";
this.TopMost = true;
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.FrmTips_FormClosing);
this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.FrmTips_FormClosed);
this.Load += new System.EventHandler(this.FrmTips_Load);
((System.ComponentModel.ISupportInitialize)(this.btnClose)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pctStat)).EndInit();
this.ResumeLayout(false); } #endregion private System.Windows.Forms.PictureBox pctStat;
private System.Windows.Forms.Label lblMsg;
private System.Windows.Forms.PictureBox btnClose;
private System.Windows.Forms.Timer timer1;
}
}
用处及效果
用处:向用户提示一些信息,但是这些信息又不是非常重要,不需要用户确定的时候可以用到这个东西
效果:
调用示例
FrmTips.ShowTipsError(this, "Error提示信息");
FrmTips.ShowTipsInfo(this, "Info提示信息");
FrmTips.ShowTipsSuccess(this, "Success提示信息");
FrmTips.ShowTipsWarning(this, "Warning提示信息");
最后的话
如果你喜欢的话,请到 https://gitee.com/kwwwvagaa/net_winform_custom_control 点个星 星吧
(二十一)c#Winform自定义控件-气泡提示的更多相关文章
- (三十二)c#Winform自定义控件-表格
前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. 开源地址:https://gitee.com/kwwwvagaa/net_winform_custom_control ...
- (八十二)c#Winform自定义控件-穿梭框
前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. GitHub:https://github.com/kwwwvagaa/NetWinformControl 码云:ht ...
- (四十二)c#Winform自定义控件-进度条扩展
前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. GitHub:https://github.com/kwwwvagaa/NetWinformControl 码云:ht ...
- (二)c#Winform自定义控件-按钮
前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. 开源地址:https://gitee.com/kwwwvagaa/net_winform_custom_control ...
- (二十二)c#Winform自定义控件-半透明窗体
前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. 开源地址:https://gitee.com/kwwwvagaa/net_winform_custom_control ...
- (五十一)c#Winform自定义控件-文字提示-HZHControls
官网 http://www.hzhcontrols.com 前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. GitHub:https://github.com/kww ...
- (十二)c#Winform自定义控件-分页控件
前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. 开源地址:https://gitee.com/kwwwvagaa/net_winform_custom_control ...
- (五十二)c#Winform自定义控件-LED数字
前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. GitHub:https://github.com/kwwwvagaa/NetWinformControl 码云:ht ...
- (六十二)c#Winform自定义控件-警灯(工业)
前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. GitHub:https://github.com/kwwwvagaa/NetWinformControl 码云:ht ...
随机推荐
- python接口自动化(二十九)--html测试报告通过邮件发出去——上(详解)
简介 前边几篇,已经教小伙伴们掌握了如何生成HTML的测试报告,那么生成测试报告,我们也不能放在那里不管了,这样即使你报告在漂亮,领导也看不到.因此如果想向领导汇报工作,不仅需要提供更直观的测试报告. ...
- 七牛云图床和Markdown使用
七牛云图床和Markdown使用 1.图床是什么? 图床一般是指储存图片的服务器,有国内和国外之分.国外的图床由于有空间距离等因素决定访问速度很慢影响图片显示速度.国内也分为单线空间.多线空间和cdn ...
- 20131228-sql命令
开始 --cmd net start mssqlservernetnet stop mssqlserver
- 【bfs基础】①
bfs,即广度优先搜索,主要通过队列(queue)进行操作. 稍微解释一下,队列是一种基础数据结构,其形态类似于一支长长的队伍,大概如下: 在C++中,队列的头文件定义为:#include<qu ...
- py+selenium 无法定位ShowModalDialog模态窗口【已解决】
问题:无法定位弹出的模态窗口. 前瞻: 模态窗口:关闭之前,无法操作其他窗口. 但是selenium无法定位到这类窗口,百度说是目前selenium不支持处理模态窗口. 目标:定位到窗口里面的元素,完 ...
- 自定义SSL证书实现单双向ssl认证记录
自定义SSL证书: 1.ca证书 #openssl genrsa -out ca.key 2048 #openssl req -new -key ca.key -out ca.csr #openssl ...
- pytorch实现yolov3(5) 实现端到端的目标检测
torch实现yolov3(1) torch实现yolov3(2) torch实现yolov3(3) torch实现yolov3(4) 前面4篇已经实现了network的forward,并且将netw ...
- MapReduce之提交job源码分析 FileInputFormat源码解析
MapReduce之提交job源码分析 job 提交流程源码详解 //runner 类中提交job waitForCompletion() submit(); // 1 建立连接 connect(); ...
- 如何让Git适应敏捷开发流程?
一旦涉及到版本控制系统,Git实际上代表敏捷开发的水平.Git作为一款强大的开源系统,有较强的灵活性,可以按需匹配任何开发团队的工作流程.而这种分布式相比较集中式来说,可以赋予系统更好的性能特征,且允 ...
- 关于 64位系统 java连接access 报错java.sql.SQLException: [Microsoft][ODBC 驱动程序管理器] 未发现数据源名称并且未指定默认驱动程序
报错的原因是url = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=E:/公司/2000.mdb"; 这样是不行 ...