有没有一种方法可以使用windows 10上显示的消息,当以我自己的方式执行shutdown.exe -c "something"时显示?Windows 10内置的消息窗口:x1c 0d1x我想做的是使用这种类型的内置消息,并从我的C#应用程序调用它,包含其他信息,我想编辑标题和描述文本。这是可能的吗?
shutdown.exe -c "something"
编辑:
澄清一下:我不想关闭系统,我只是想把这条信息用于其他目的,而不是关闭!
41zrol4v1#
我已经建立了一个迷你图书馆,你可以使用,请参阅github repo弹出窗口示例
的数据这样称呼它
using SmartScreenMessagePopupDialog;SmartScreenMessageDialog customWindow = new SmartScreenMessageDialog("Welcome", "Hi there, this is an example", true);customWindow.Show();
using SmartScreenMessagePopupDialog;
SmartScreenMessageDialog customWindow = new SmartScreenMessageDialog("Welcome", "Hi there, this is an example", true);
customWindow.Show();
字符串
SmartScreenMessagePopupDialog
ConsoleApp1
如果你不想要整个项目,这里是对话框的源代码。您需要System.Drawing.dll和System.Windows.Forms.dll
System.Drawing.dll
System.Windows.Forms.dll
using System;using System.Drawing;using System.Windows;using System.Windows.Forms;using static System.Windows.Forms.VisualStyles.VisualStyleElement.Window;namespace SmartScreenMessagePopupDialog{ public class SmartScreenMessageDialog { private Form customForm; private string mTitle; private string mMessage; private Boolean mShowOkayButton; public SmartScreenMessageDialog(string title, string message, Boolean showOkayButton = true) { Screen primaryScreen = Screen.PrimaryScreen; int screenWidth = primaryScreen.Bounds.Width; int screenHeight = primaryScreen.Bounds.Height; this.mTitle = title; this.mMessage = message; this.mShowOkayButton = showOkayButton; customForm = new Form(); customForm.BackColor = Color.FromArgb(0x01, 0x67, 0xB2); customForm.FormBorderStyle = FormBorderStyle.None; customForm.Text = this.mTitle; customForm.Size = new System.Drawing.Size(800, 360); int centerX = ((screenWidth / 2) - (customForm.Size.Width / 2)); int centerY = ((screenHeight / 2) - (customForm.Size.Height / 2)); customForm.Location = new System.Drawing.Point(centerX, centerY); Label myTitle = new Label(); myTitle.Text = this.mTitle; myTitle.Location = new Point(32, 32); myTitle.ForeColor = Color.White; myTitle.Size = new Size(customForm.Size.Width - 32, 64); myTitle.Font = new Font(myTitle.Font.FontFamily, 22, FontStyle.Bold); customForm.Controls.Add(myTitle); Label myMessage = new Label(); myMessage.Text = this.mMessage; myMessage.Location = new Point(32, myTitle.Size.Height + 32); myMessage.ForeColor = Color.White; myMessage.Size = new Size(customForm.Size.Width - 32, 200); myMessage.Font = new Font(myMessage.Font.FontFamily, 12, FontStyle.Regular); customForm.Controls.Add(myMessage); if (showOkayButton) { Button closeButton = new Button(); closeButton.Text = "Okay"; closeButton.Size = new System.Drawing.Size(100, 32); int xFactor = 32; int yFactor = 32; closeButton.FlatStyle = FlatStyle.Flat; closeButton.FlatAppearance.BorderSize = 1; closeButton.FlatAppearance.BorderColor = Color.White; closeButton.ForeColor = Color.White; closeButton.Location = new System.Drawing.Point(customForm.Size.Width - (closeButton.Size.Width + xFactor), customForm.Size.Height - (closeButton.Size.Height + yFactor)); closeButton.Click += (sender, e) => { customForm.Close(); }; customForm.Controls.Add(closeButton); } } public void Show() { this.customForm.ShowDialog(); } }}
using System;
using System.Drawing;
using System.Windows;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Window;
namespace SmartScreenMessagePopupDialog
{
public class SmartScreenMessageDialog
private Form customForm;
private string mTitle;
private string mMessage;
private Boolean mShowOkayButton;
public SmartScreenMessageDialog(string title, string message, Boolean showOkayButton = true)
Screen primaryScreen = Screen.PrimaryScreen;
int screenWidth = primaryScreen.Bounds.Width;
int screenHeight = primaryScreen.Bounds.Height;
this.mTitle = title;
this.mMessage = message;
this.mShowOkayButton = showOkayButton;
customForm = new Form();
customForm.BackColor = Color.FromArgb(0x01, 0x67, 0xB2);
customForm.FormBorderStyle = FormBorderStyle.None;
customForm.Text = this.mTitle;
customForm.Size = new System.Drawing.Size(800, 360);
int centerX = ((screenWidth / 2) - (customForm.Size.Width / 2));
int centerY = ((screenHeight / 2) - (customForm.Size.Height / 2));
customForm.Location = new System.Drawing.Point(centerX, centerY);
Label myTitle = new Label();
myTitle.Text = this.mTitle;
myTitle.Location = new Point(32, 32);
myTitle.ForeColor = Color.White;
myTitle.Size = new Size(customForm.Size.Width - 32, 64);
myTitle.Font = new Font(myTitle.Font.FontFamily, 22, FontStyle.Bold);
customForm.Controls.Add(myTitle);
Label myMessage = new Label();
myMessage.Text = this.mMessage;
myMessage.Location = new Point(32, myTitle.Size.Height + 32);
myMessage.ForeColor = Color.White;
myMessage.Size = new Size(customForm.Size.Width - 32, 200);
myMessage.Font = new Font(myMessage.Font.FontFamily, 12, FontStyle.Regular);
customForm.Controls.Add(myMessage);
if (showOkayButton)
Button closeButton = new Button();
closeButton.Text = "Okay";
closeButton.Size = new System.Drawing.Size(100, 32);
int xFactor = 32;
int yFactor = 32;
closeButton.FlatStyle = FlatStyle.Flat;
closeButton.FlatAppearance.BorderSize = 1;
closeButton.FlatAppearance.BorderColor = Color.White;
closeButton.ForeColor = Color.White;
closeButton.Location = new System.Drawing.Point(customForm.Size.Width - (closeButton.Size.Width + xFactor), customForm.Size.Height - (closeButton.Size.Height + yFactor));
closeButton.Click += (sender, e) =>
customForm.Close();
};
customForm.Controls.Add(closeButton);
}
public void Show()
this.customForm.ShowDialog();
型
1条答案
按热度按时间41zrol4v1#
我已经建立了一个迷你图书馆,你可以使用,请参阅github repo
弹出窗口示例
的数据
这样称呼它
字符串
info(repo info)
SmartScreenMessagePopupDialog
中的库ConsoleApp1
中测试应用程序来源
如果你不想要整个项目,这里是对话框的源代码。
您需要
System.Drawing.dll
和System.Windows.Forms.dll
型