环境:c#2008 windows编程,不是WEB的,SQl2005
要求根据数据表中的记录自动生成一组按钮,按钮上显示这条记录的图片和文字,要求文字位于图片下方,文字字号为9号
我目前写的如下
Button ButtUser;
ButtUser = new Button();
//buttUser 按钮设计
ButtUser.BackColor = Color.Transparent;
ButtUser.FlatStyle = FlatStyle.Flat;
ButtUser.FlatAppearance.BorderSize=0;
ButtUser.ForeColor = Color.Black;
//ButtUser.Font.Size = 9;
//ButtUser.ImageAlign = 0;
//ButtUser.TextImageRelation.ImageAboveText; ButtUser.Width = 56;
ButtUser.Height = 58;
//对按钮设置数据
ButtUser.Text = sqlreader[1].ToString(); //给按钮写入用户名
//ButtUser.Image = sqlreader[2]; //给按钮添加图片
ButtUser.Click += new System.EventHandler(ButtUser_Click);
ButtUser.Location = new System.Drawing.Point(24, 21); //设置按钮位置
现在我不会设置字体大小和图片文字的位置,请知道的达人帮忙,不胜感谢
要求根据数据表中的记录自动生成一组按钮,按钮上显示这条记录的图片和文字,要求文字位于图片下方,文字字号为9号
我目前写的如下
Button ButtUser;
ButtUser = new Button();
//buttUser 按钮设计
ButtUser.BackColor = Color.Transparent;
ButtUser.FlatStyle = FlatStyle.Flat;
ButtUser.FlatAppearance.BorderSize=0;
ButtUser.ForeColor = Color.Black;
//ButtUser.Font.Size = 9;
//ButtUser.ImageAlign = 0;
//ButtUser.TextImageRelation.ImageAboveText; ButtUser.Width = 56;
ButtUser.Height = 58;
//对按钮设置数据
ButtUser.Text = sqlreader[1].ToString(); //给按钮写入用户名
//ButtUser.Image = sqlreader[2]; //给按钮添加图片
ButtUser.Click += new System.EventHandler(ButtUser_Click);
ButtUser.Location = new System.Drawing.Point(24, 21); //设置按钮位置
现在我不会设置字体大小和图片文字的位置,请知道的达人帮忙,不胜感谢
Button btn = new Button();
btn.ImageAlign = ContentAlignment.TopCenter;
btn.Image = ??;
btn.Size = new Size(button2.Image.Width, button2.Image.Height + 20);
btn.TextAlign = ContentAlignment.BottomCenter;
btn.Font = new Font("宋体", 9F);
btn.Name = "btn";
btn.Location=new Point(100,100);
btn.Click += new System.EventHandler(btn_click);
this.Controls.Add(btn);
private void btn_click(object sender, System.EventArgs e)
{
Button btn= (Button)sender;
}
button1.Font = new System.Drawing.Font("宋体",9);
button1.ImageAlign=ContentAlignment.TopCenter;
button1.Image = System.Drawing.Image.FromFile(@"C:xx.jpg");
button1.TextAlign = ContentAlignment.BottomCenter;
添加图片有很多方式啊 这是其中一种button1.Image = System.Drawing.Image.FromFile(@"C:xx.jpg");
MemoryStream ms = new MemoryStream(byteArrayIn);
button1.Image= Image.FromStream(ms);