Jon*_*han 2 c# windows windows-10
shutdown.exe -c "something"有没有办法使用 Windows 10 上以我自己的方式执行时显示的消息?
我想要做的是使用这种类型的内置消息并从我的 C# 应用程序调用它,其中包含我想要编辑标题和描述文本的其他信息。这是可能吗?
编辑:
澄清一下:我不想关闭系统。我只想将该消息用于其他目的,而根本不关闭!
我已经构建了一个您可以使用的迷你库,请参阅github 存储库
弹出窗口示例
像这样称呼它
using SmartScreenMessagePopupDialog;
SmartScreenMessageDialog customWindow = new SmartScreenMessageDialog("Welcome", "Hi there, this is an example", true);
customWindow.Show();
Run Code Online (Sandbox Code Playgroud)
SmartScreenMessagePopupDialogConsoleApp1如果您不想要整个项目,这里是对话框的源代码
你确实需要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();
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
88 次 |
| 最近记录: |