Files
FATrace/FATrace.App/frmMessage.cs
2026-01-28 15:04:16 +08:00

68 lines
1.9 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace FATrace.App
{
public partial class frmMessage : Form
{
public frmMessage()
{
InitializeComponent();
StartPosition = FormStartPosition.CenterParent;
FormBorderStyle = FormBorderStyle.FixedDialog;
ShowInTaskbar = false;
AcceptButton = btnTrue;
CancelButton = bntCancel;
}
/// <summary>
/// 显示确认对话框OK/Cancel
/// </summary>
/// <param name="message">提示内容</param>
/// <param name="title">标题</param>
/// <param name="owner">父窗口</param>
/// <returns>DialogResult.OK 表示确认DialogResult.Cancel 表示取消</returns>
public static DialogResult ShowConfirm(string message, string title = "确认操作", IWin32Window? owner = null)
{
using (var f = new frmMessage())
{
if (!string.IsNullOrWhiteSpace(title))
f.Text = title;
f.SetMessageText(message);
return owner == null ? f.ShowDialog() : f.ShowDialog(owner);
}
}
/// <summary>
/// 设置提示文本。
/// </summary>
/// <param name="message">提示内容</param>
private void SetMessageText(string message)
{
lblMessage.Text = (message ?? string.Empty).Trim();
}
private void btnTrue_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.OK;
Close();
}
private void bntCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
}
}