求大神指导,C#怎么用代码定义Lable字体的样式和大小(visual studio 2010)
我想做一个音乐播放器,效果相做成这样,现在遇到问题就是不知道如何用代码定义Lable的字体样式和大小,背景色也不能实现为透明classzhuanji{//publicst...
我想做一个音乐播放器,效果相做成这样,现在遇到问题就是不知道如何用代码定义Lable的字体样式和大小,背景色也不能实现为透明
class zhuanji
{
//public static string ListName = "";
public ArrayList muscLst = new ArrayList();
public void AddMusic(danqu music)
{
muscLst.Add(music);
}
}
class danqu
{
public string danquName;
}
class MyForm
{
public int Width;
public int Height;
}
}
labzj.Image = Image.FromFile(Application.StartupPath + @"\beijing.jpg");
MyForm my = new MyForm();
my.Width = 340;
my.Height = 519;
this.Size = new System.Drawing.Size(my.Width, my.Height);
danqu music = new danqu();
music.danquName = "十二新作 (2012-12-28)";
list.AddMusic(music);
for (int i = 0; i < list.muscLst.Count; i++)
{
Label lbl = new Label();
FontFamily myFontFamily = new FontFamily("楷体"); //采用哪种字体
Font myFont = new Font(myFontFamily, 30); //字是那种字体(楷体)
this.lab1.Font = new Font(myFontFamily, 14);//设置字体为楷体,大小为14
lbl.Text = ((danqu)list.muscLst[i]).danquName;
int x = 20;
int y = 20;
lbl.Location = new Point(x, y + 50 * i);
this.Controls.Add(lbl);
lab1.AutoSize = false;
this.BackColor = Color.Transparent;
} 展开
class zhuanji
{
//public static string ListName = "";
public ArrayList muscLst = new ArrayList();
public void AddMusic(danqu music)
{
muscLst.Add(music);
}
}
class danqu
{
public string danquName;
}
class MyForm
{
public int Width;
public int Height;
}
}
labzj.Image = Image.FromFile(Application.StartupPath + @"\beijing.jpg");
MyForm my = new MyForm();
my.Width = 340;
my.Height = 519;
this.Size = new System.Drawing.Size(my.Width, my.Height);
danqu music = new danqu();
music.danquName = "十二新作 (2012-12-28)";
list.AddMusic(music);
for (int i = 0; i < list.muscLst.Count; i++)
{
Label lbl = new Label();
FontFamily myFontFamily = new FontFamily("楷体"); //采用哪种字体
Font myFont = new Font(myFontFamily, 30); //字是那种字体(楷体)
this.lab1.Font = new Font(myFontFamily, 14);//设置字体为楷体,大小为14
lbl.Text = ((danqu)list.muscLst[i]).danquName;
int x = 20;
int y = 20;
lbl.Location = new Point(x, y + 50 * i);
this.Controls.Add(lbl);
lab1.AutoSize = false;
this.BackColor = Color.Transparent;
} 展开
展开全部
Label1.Attributes["style"] = "font-family:'微软雅黑','黑体','华文细黑'";
追问
我太菜了,没看懂,有其他方法吗,类似这样的 FontFamily myFontFamily = new FontFamily("楷体"); //采用哪种字体
追答
这个就是啊!使用Attributes属性可以为label加入任何你想要的属性,给你代码自己看吧
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
在后端这样
void btn_Click(object sender, EventArgs e)
{
Label1.Attributes["style"] = "font-family:'微软雅黑','黑体','华文细黑'";
}
btn_Click是一个按钮的点击事件
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询