关于messagebox窗口的问题

flyxiaoyao 2009-12-08 03:38:08
请问下,messagebox 中根据文字自动多少,而自动调整窗口大小是如何实现的?
...全文
123 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
t6786780 2009-12-08
  • 打赏
  • 举报
回复
messageBox窗体是自动的, 也就是说你的文字有多少他就会放大多少, 如果你要限制其内容的话可以自己重写一下MessageBox窗体. 继承Form窗体然后自定义其中的内容.
walkghost 2009-12-08
  • 打赏
  • 举报
回复
貌似默认情况下窗体大小是自动适应文字的。
wangyue4 2009-12-08
  • 打赏
  • 举报
回复
默认就是自动的吧
CNBeing 2009-12-08
  • 打赏
  • 举报
回复

Control ctl = new Control();
int width = TextRenderer.MeasureText("MessageString", ctl.Font).Width;
CNBeing 2009-12-08
  • 打赏
  • 举报
回复
[code=C#]
Control ctl = new Control();
int width = TextRenderer.MeasureText("MessageString", ctl.Font).Width;
[code]
ddsxd19 2009-12-08
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 hhc123 的回复:]
MessageBox.Show(...........);不是自动的吗?
[/Quote]
好像是的,字越少框越小。。。
wartim 2009-12-08
  • 打赏
  • 举报
回复
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Xml;

namespace WindowsApplication210
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();

Label L = new Label();
L.Parent = this;
L.AutoSize = true;

for (int i = 0; i < 100; i++)
L.Text += "a";

this.AutoSize = true;
}
}
}
hhc123 2009-12-08
  • 打赏
  • 举报
回复
MessageBox.Show(...........);不是自动的吗?
cstester 2009-12-08
  • 打赏
  • 举报
回复
一个字几个像素自己算, 在窗体构造里面,重新设置下窗体大小,就哦了.

比如 :

调用的窗体:
MessageForm mfrm = new MessageForm("这是消息的内容");

mfrm.ShowDialog();


MessageForm

//关键部分,构造:
public MessageForm(string arg)
{
InitializeComponent();
//默认的宽度,至少为100px
int width = 100;
//假定一个字 为5像素,超过10个字,自动改变大小
if(arg.Length >=10)
{
width += (are.Length -10)*5;
}
this.Location = new Point(this.Height,width);

}



110,502

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧