Windows Compact Framework 自定义弹出通知
Windows Compact Framework custom popup notification
我一直在尝试为我的 windows 创建弹出通知,类似于 android 中的祝酒词。
- 它不应该关心活动来自
- 它应该始终在顶部(在它处于活动状态的时间内)
- 它不应该阻止当前活动的表单
- 点击槽就好了
我知道 Microsoft.WindowsCE.Forms.Notification,但它与应用程序的风格不太相配,我尝试创建继承 Notification 的自定义 class,但我找不到重新设计它的方法。我也尝试创建最顶层的表单,但这也不起作用,除非我使用 ShowDialog,否则根本不会显示表单,但随后它将自动调整到屏幕 size.Here 是我计划的方式示例从以下位置创建:
Form frm = new Form();
frm.TopMost = true;
Label lbl = new Label();
lbl.Text = "TEST";
lbl.Parent = frm;
frm.Bounds = new Rectangle(15, 15, 150, 150);
frm.WindowState = FormWindowState.Normal;
frm.FormBorderStyle = FormBorderStyle.None;
frm.AutoScaleMode = AutoScaleMode.None;
frm.Show();
并非所有平台都支持 Microsoft.WindowsCE.Forms.Notification
。您可能希望坚持自己的实施。关于这一点,这就是我要做的(未测试):
创建一个 Class 库项目。然后添加一个表格。现在添加一个 Label 控件和一个 Button 控件,如下所示:
编辑表单的属性:
ControlBox = false
FormBorderStyle = FixedDialog
TopMost = true
在表单中添加以下代码:
public partial class FormNotification : Form
{
private Timer timer;
public int Duration { get; private set;}
public FormNotification(string message, int duration)
{
InitializeComponent();
this.labelMessage.Text = message;
this.Duration = duration;
this.timer = new Timer();
this.timer.Interval = 1000;
this.timer.Tick += new EventHandler(timer_Tick);
}
void timer_Tick(object sender, EventArgs e)
{
if (Duration <= 0)
this.Close();
this.Duration--;
}
private void buttonHide_Click(object sender, EventArgs e)
{
this.Close();
}
private void FormNotification_Load(object sender, EventArgs e)
{
this.timer.Enabled = true;
}
}
现在添加一个class:
已更新
public class CNotification
{
public CNotification()
{
}
public static void Show(Form owner, string message, int duration)
{
FormNotification formNotification = new FormNotification(message, duration);
formNotification.Owner = owner;
formNotification.Show();
}
}
终于用起来像:
已更新
// assuming call from a form
CNotification.Show(this, "Hello World", 5);
扩展想法
- 提供对表单控件的访问
- 指定位置和大小
- 添加图标。
- 更改通知的不透明度
我一直在尝试为我的 windows 创建弹出通知,类似于 android 中的祝酒词。
- 它不应该关心活动来自
- 它应该始终在顶部(在它处于活动状态的时间内)
- 它不应该阻止当前活动的表单
- 点击槽就好了
我知道 Microsoft.WindowsCE.Forms.Notification,但它与应用程序的风格不太相配,我尝试创建继承 Notification 的自定义 class,但我找不到重新设计它的方法。我也尝试创建最顶层的表单,但这也不起作用,除非我使用 ShowDialog,否则根本不会显示表单,但随后它将自动调整到屏幕 size.Here 是我计划的方式示例从以下位置创建:
Form frm = new Form();
frm.TopMost = true;
Label lbl = new Label();
lbl.Text = "TEST";
lbl.Parent = frm;
frm.Bounds = new Rectangle(15, 15, 150, 150);
frm.WindowState = FormWindowState.Normal;
frm.FormBorderStyle = FormBorderStyle.None;
frm.AutoScaleMode = AutoScaleMode.None;
frm.Show();
Microsoft.WindowsCE.Forms.Notification
。您可能希望坚持自己的实施。关于这一点,这就是我要做的(未测试):
创建一个 Class 库项目。然后添加一个表格。现在添加一个 Label 控件和一个 Button 控件,如下所示:
编辑表单的属性:
ControlBox = false
FormBorderStyle = FixedDialog
TopMost = true
在表单中添加以下代码:
public partial class FormNotification : Form
{
private Timer timer;
public int Duration { get; private set;}
public FormNotification(string message, int duration)
{
InitializeComponent();
this.labelMessage.Text = message;
this.Duration = duration;
this.timer = new Timer();
this.timer.Interval = 1000;
this.timer.Tick += new EventHandler(timer_Tick);
}
void timer_Tick(object sender, EventArgs e)
{
if (Duration <= 0)
this.Close();
this.Duration--;
}
private void buttonHide_Click(object sender, EventArgs e)
{
this.Close();
}
private void FormNotification_Load(object sender, EventArgs e)
{
this.timer.Enabled = true;
}
}
现在添加一个class:
已更新
public class CNotification
{
public CNotification()
{
}
public static void Show(Form owner, string message, int duration)
{
FormNotification formNotification = new FormNotification(message, duration);
formNotification.Owner = owner;
formNotification.Show();
}
}
终于用起来像:
已更新
// assuming call from a form
CNotification.Show(this, "Hello World", 5);
扩展想法
- 提供对表单控件的访问
- 指定位置和大小
- 添加图标。
- 更改通知的不透明度