68 lines
1.9 KiB
C#
68 lines
1.9 KiB
C#
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();
|
||
}
|
||
}
|
||
}
|