在C#中使用Windows 10关闭消息

hs1ihplo  于 2023-11-21  发布在  Windows
关注(0)|答案(1)|浏览(155)

有没有一种方法可以使用windows 10上显示的消息,当以我自己的方式执行shutdown.exe -c "something"时显示?
Windows 10内置的消息窗口:x1c 0d1x
我想做的是使用这种类型的内置消息,并从我的C#应用程序调用它,包含其他信息,我想编辑标题和描述文本。这是可能的吗?

编辑:

澄清一下:我不想关闭系统,我只是想把这条信息用于其他目的,而不是关闭!

41zrol4v

41zrol4v1#

我已经建立了一个迷你图书馆,你可以使用,请参阅github repo
弹出窗口示例


的数据
这样称呼它

  1. using SmartScreenMessagePopupDialog;
  2. SmartScreenMessageDialog customWindow = new SmartScreenMessageDialog("Welcome", "Hi there, this is an example", true);
  3. customWindow.Show();

字符串

info(repo info)

  • SmartScreenMessagePopupDialog中的库
  • ConsoleApp1中测试应用程序

来源

如果你不想要整个项目,这里是对话框的源代码。
您需要System.Drawing.dllSystem.Windows.Forms.dll

  1. using System;
  2. using System.Drawing;
  3. using System.Windows;
  4. using System.Windows.Forms;
  5. using static System.Windows.Forms.VisualStyles.VisualStyleElement.Window;
  6. namespace SmartScreenMessagePopupDialog
  7. {
  8. public class SmartScreenMessageDialog
  9. {
  10. private Form customForm;
  11. private string mTitle;
  12. private string mMessage;
  13. private Boolean mShowOkayButton;
  14. public SmartScreenMessageDialog(string title, string message, Boolean showOkayButton = true)
  15. {
  16. Screen primaryScreen = Screen.PrimaryScreen;
  17. int screenWidth = primaryScreen.Bounds.Width;
  18. int screenHeight = primaryScreen.Bounds.Height;
  19. this.mTitle = title;
  20. this.mMessage = message;
  21. this.mShowOkayButton = showOkayButton;
  22. customForm = new Form();
  23. customForm.BackColor = Color.FromArgb(0x01, 0x67, 0xB2);
  24. customForm.FormBorderStyle = FormBorderStyle.None;
  25. customForm.Text = this.mTitle;
  26. customForm.Size = new System.Drawing.Size(800, 360);
  27. int centerX = ((screenWidth / 2) - (customForm.Size.Width / 2));
  28. int centerY = ((screenHeight / 2) - (customForm.Size.Height / 2));
  29. customForm.Location = new System.Drawing.Point(centerX, centerY);
  30. Label myTitle = new Label();
  31. myTitle.Text = this.mTitle;
  32. myTitle.Location = new Point(32, 32);
  33. myTitle.ForeColor = Color.White;
  34. myTitle.Size = new Size(customForm.Size.Width - 32, 64);
  35. myTitle.Font = new Font(myTitle.Font.FontFamily, 22, FontStyle.Bold);
  36. customForm.Controls.Add(myTitle);
  37. Label myMessage = new Label();
  38. myMessage.Text = this.mMessage;
  39. myMessage.Location = new Point(32, myTitle.Size.Height + 32);
  40. myMessage.ForeColor = Color.White;
  41. myMessage.Size = new Size(customForm.Size.Width - 32, 200);
  42. myMessage.Font = new Font(myMessage.Font.FontFamily, 12, FontStyle.Regular);
  43. customForm.Controls.Add(myMessage);
  44. if (showOkayButton)
  45. {
  46. Button closeButton = new Button();
  47. closeButton.Text = "Okay";
  48. closeButton.Size = new System.Drawing.Size(100, 32);
  49. int xFactor = 32;
  50. int yFactor = 32;
  51. closeButton.FlatStyle = FlatStyle.Flat;
  52. closeButton.FlatAppearance.BorderSize = 1;
  53. closeButton.FlatAppearance.BorderColor = Color.White;
  54. closeButton.ForeColor = Color.White;
  55. closeButton.Location = new System.Drawing.Point(customForm.Size.Width - (closeButton.Size.Width + xFactor), customForm.Size.Height - (closeButton.Size.Height + yFactor));
  56. closeButton.Click += (sender, e) =>
  57. {
  58. customForm.Close();
  59. };
  60. customForm.Controls.Add(closeButton);
  61. }
  62. }
  63. public void Show()
  64. {
  65. this.customForm.ShowDialog();
  66. }
  67. }
  68. }

展开查看全部

相关问题