[英]Create modeless child form in C#
我目前正在開發一個桌面應用程序(主窗體),該應用程序上載數據以便執行一些基本計算。
我希望在用戶上傳文件后(例如“上傳已完成”)彈出一個Box。 此Box應具有2個特征:
我已經找到第二點的解決方案,但是我仍然必須創建要彈出的表單。 因為我不希望它具有按鈕,所以MessageBox不太適合。
我知道我可以創建如下的無模式表單:
Public class test
{
Form f = new Form();
f.show()
}
從那開始,如何插入與messageBox樣式非常相似的字符串文本和字符串標題?
謝謝
我認為這可以讓您了解如何開始
public class MyDialog: Form
{
public MyDialog(string prompt, int timeout)
{
RichTextBox rtb = new RichTextBox();
rtb.Dock = DockStyle.Fill;
rtb.Font = new Font("Times new Roman", 14f, FontStyle.Bold);
rtb.Text = prompt;
this.Controls.Add(rtb);
var _Timer = new System.Windows.Forms.Timer()
{
Enabled = true,
Interval = timeout
};
_Timer.Tick += (s, e) => this.Close();
this.Show();
}
}
您需要做的就是創建如下所示的表單
var f = new MyDialog("It works", 5000);
首先,您可以創建一個表單,如下所示,它相當於您的消息框。
然后,您可以像這樣更改新的Form2
構造函數:
public partial class Form2 : Form
{
public Form2(string title, string message)
{
InitializeComponent();
this.Text = title;
label1.Text = message;
}
}
this.Text
是您的標題,然后使用label1.Text
設置標簽文本。
然后,在啟動新表單時,請執行以下操作:
private void button1_Click(object sender, EventArgs e)
{
Form2 f2 = new Form2("header","message");
f2.Show();
}
這就是您將得到的:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.