我正在csharp中为较小的设备编辑程序,弹出的消息太小。所以,我想让它们更大。当前代码使用“messageHandler”使窗口弹出文本。以下是我要看的内容:
this.messageHandler("Parameters Loaded", "Parameters Loaded Successfully");
所以,我想让字体更大,因为使字体更大应该使文本和可能更大的窗口。我读到也许我应该尝试创建一个新课程,但我对如何继续学习感到困惑。谢谢。
编辑:
我认为这是最初的定义:
private void messageHandler(string title, Exception ex)
{
this.messageHandler(title, ex.Message);
}
我相信我正在使用WinForms。
答案 0 :(得分:1)
我明白了。基本上我创建了一个扩展表单的新类。然后我将任何文本或变量传递给我在该表单中创建的按钮和文本框。然后我用自己的函数替换了某些“messageHandler”调用,该函数使用了该类。以下是我在课堂上使用的函数示例:
//Message or exception box with an okay button
public void okNewMessageBox(string title, string message)
{
NewMessageBox msgResized = new NewMessageBox(title, message);
msgResized.StartPosition = FormStartPosition.CenterScreen;
msgResized.Show();
}
这是一个类文件,其中一个文本框设置为只读,一个okay按钮关闭窗口:
using System;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
using System.Runtime.InteropServices;
public class NewMessageBox : Form
{
private TextBox textBoxMessage;
private Button buttonOK;
public NewMessageBox(string title, string message)
{
InitializeComponent();
this.Text = title;
this.textBoxMessage.Text = message;
this.Deactivate += MyDeactivateHandler;
this.textBoxMessage.ReadOnly = true;
}
private void InitializeComponent()
{
this.buttonOK = new System.Windows.Forms.Button();
this.textBoxMessage = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// buttonOK
//
this.buttonOK.Location = new System.Drawing.Point(171, 161);
this.buttonOK.Name = "buttonOK";
this.buttonOK.Size = new System.Drawing.Size(107, 44);
this.buttonOK.TabIndex = 0;
this.buttonOK.Text = "OK";
this.buttonOK.UseVisualStyleBackColor = true;
this.buttonOK.Click += new System.EventHandler(this.buttonOK_Click);
//
// textBoxMessage
//
this.textBoxMessage.Font = new System.Drawing.Font("Microsoft Sans Serif", 20.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.textBoxMessage.Location = new System.Drawing.Point(29, 36);
this.textBoxMessage.Name = "textBoxMessage";
this.textBoxMessage.ReadOnly = true;
this.textBoxMessage.Size = new System.Drawing.Size(411, 38);
this.textBoxMessage.TabIndex = 1;
//
// NewMessageBox
//
this.ClientSize = new System.Drawing.Size(468, 236);
this.Controls.Add(this.textBoxMessage);
this.Controls.Add(this.buttonOK);
this.Name = "NewMessageBox";
this.Load += new System.EventHandler(this.NewMessageBox_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
public string message { get; set; }
private void buttonOK_Click(object sender, EventArgs e)
{
this.Close();
}
protected void MyDeactivateHandler(object sender, EventArgs e)
{
this.Close();
}
private void NewMessageBox_Load(object sender, EventArgs e)
{
}
}