.net 自定义 MessageBox 文本突出显示
为什么?
我用 C# 构建了一个简单的自定义 MessageBox 作为对话框。当我通过 Show() 显示消息框时,消息文本不会突出显示。当我通过 ShowDialog() 显示此消息框时,文本突出显示。
我不想突出显示我的文本。有什么想法或想法吗?
public partial class MyMessageBox : Form
{
private String mCaption;
private String mMessage;
public MyMessageBox( Form anOwner, String aCaption, String aMessage )
{
InitializeComponent();
mCaption = aCaption;
Owner = anOwner;
mMessage = aMessage;
}
private void btnCancelRequest_Click( object sender, EventArgs e )
{
( (AddressForm)Owner ).RequestCancelled();
}
private void btnOk_Click( object sender, EventArgs e )
{
CloseDialog();
}
public void CloseDialog()
{
Close();
}
// Called from the Address Form
public void HideCancelRequestButton()
{
btnCancelRequest.Visible = false;
}
private void MyMessageBox_Activated( object sender, EventArgs e )
{
Text = mCaption;
txtMessage.Text = mMessage;
}
}
Why?
I built a simple custom MessageBox as as a Dialog in C#. When I show the message boxvia Show(), the message text is not highlighted. When I show this messagebox vi ShowDialog(), the text is highlighted.
I don't want my text to be highlighted. Any thoughts or ideas?
public partial class MyMessageBox : Form
{
private String mCaption;
private String mMessage;
public MyMessageBox( Form anOwner, String aCaption, String aMessage )
{
InitializeComponent();
mCaption = aCaption;
Owner = anOwner;
mMessage = aMessage;
}
private void btnCancelRequest_Click( object sender, EventArgs e )
{
( (AddressForm)Owner ).RequestCancelled();
}
private void btnOk_Click( object sender, EventArgs e )
{
CloseDialog();
}
public void CloseDialog()
{
Close();
}
// Called from the Address Form
public void HideCancelRequestButton()
{
btnCancelRequest.Visible = false;
}
private void MyMessageBox_Activated( object sender, EventArgs e )
{
Text = mCaption;
txtMessage.Text = mMessage;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
虽然我不明白为什么文本会突出显示,但您可以通过显式指定文本框选择长度来避免这种情况:
尽管正如杰里米评论的那样,这可能是更好地使用标签,除非您实际上期望用户输入。
While I don't see why the text would be highlighted, you could avoid this by explicitly specifying the textbox selection length:
though as Jeremy commented, this may be a better use of a label unless you're actually expecting user input.