110,502
社区成员
发帖
与我相关
我的任务
分享
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;
}
}
}
MessageForm mfrm = new MessageForm("这是消息的内容");
mfrm.ShowDialog();
//关键部分,构造:
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);
}