怎么样能实现这样的效果?
有好几个Label,里面的内容可以根据页面调整自动换行,应该是吧AutoSize设false,然后Anchor设置成top,right和left,这样可以实现遂改变换行,可是label的高度该怎样控制呢,使它可以适应,也不会挡住下面另外一个label!
两个图片说明题目意思,效果没有达到!写了一小段测试实验了一下,始终不能成功! private void Form1_Load(object sender, EventArgs e)
{
string sqlcon = "Data Source=PC20130329;Initial Catalog=Exam;Integrated Security=True";
SqlConnection con = new SqlConnection(sqlcon); int x = this.ClientRectangle.Width; string sql="select * from Question";
SqlCommand command = new SqlCommand(sql,con); con.Open();
SqlDataReader dataReader = command.ExecuteReader();
dataReader.Read();
string ss = (string)dataReader["Question"]; Label ques = new Label();
ques.Parent = panel;
ques.Font = new Font("宋体", 14);
ques.Width = x;
ques.Height = 100;
ques.AutoSize = false;
ques.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right|AnchorStyles.Bottom;
ques.Location = new Point(0, 0);
ques.BorderStyle = BorderStyle.FixedSingle;
ques.Text = ss; Label ques0 = new Label();
ques0.Parent = panel;
ques0.Width = x;
/*//////高度
int meihang=x/20;
int a = ss.Length;
int hang =( a % meihang == 0 ? (a / meihang) : ((a / meihang)+1));
ques0.Height = hang * 20;
*//////////
ques0.AutoSize = false;
ques0.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Bottom;
int y = ques.Location.Y + ques.Size.Height + 20;
ques0.Location = new Point(0,180);
ques0.BorderStyle = BorderStyle.FixedSingle;
ques0.Text = ss;
ques0.Font = new Font("宋体", 14);
dataReader.Close();
con.Close();
con.Dispose(); }
C#Label换行
有好几个Label,里面的内容可以根据页面调整自动换行,应该是吧AutoSize设false,然后Anchor设置成top,right和left,这样可以实现遂改变换行,可是label的高度该怎样控制呢,使它可以适应,也不会挡住下面另外一个label!
两个图片说明题目意思,效果没有达到!写了一小段测试实验了一下,始终不能成功! private void Form1_Load(object sender, EventArgs e)
{
string sqlcon = "Data Source=PC20130329;Initial Catalog=Exam;Integrated Security=True";
SqlConnection con = new SqlConnection(sqlcon); int x = this.ClientRectangle.Width; string sql="select * from Question";
SqlCommand command = new SqlCommand(sql,con); con.Open();
SqlDataReader dataReader = command.ExecuteReader();
dataReader.Read();
string ss = (string)dataReader["Question"]; Label ques = new Label();
ques.Parent = panel;
ques.Font = new Font("宋体", 14);
ques.Width = x;
ques.Height = 100;
ques.AutoSize = false;
ques.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right|AnchorStyles.Bottom;
ques.Location = new Point(0, 0);
ques.BorderStyle = BorderStyle.FixedSingle;
ques.Text = ss; Label ques0 = new Label();
ques0.Parent = panel;
ques0.Width = x;
/*//////高度
int meihang=x/20;
int a = ss.Length;
int hang =( a % meihang == 0 ? (a / meihang) : ((a / meihang)+1));
ques0.Height = hang * 20;
*//////////
ques0.AutoSize = false;
ques0.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Bottom;
int y = ques.Location.Y + ques.Size.Height + 20;
ques0.Location = new Point(0,180);
ques0.BorderStyle = BorderStyle.FixedSingle;
ques0.Text = ss;
ques0.Font = new Font("宋体", 14);
dataReader.Close();
con.Close();
con.Dispose(); }
C#Label换行
什么意思?能说的具体一些吗?使用一个panel,设置dock位fill吗?
label的Dock设置为Top,然后用Graphics的MeasureString,计算label的高度
能不能讲一下MeasureString的用法,看msdn不太懂,谢谢了!!!