基于C#的字体设计器
来源:互联网 发布:阿里巴巴直接传淘宝 编辑:程序博客网 时间:2024/05/17 00:05
在参考别人相关代码的基础上,博主开发了基于C#的字体设计器,基本实现了常规的字体设计的需要,下面是详细的代码:
Font font = new Font("宋体", 9, FontStyle.Regular); //默认的字体
string[] styleArray = { "常规", "粗体", "斜体", "粗体 倾斜" }; //字体效果
string[] sizeArray = { "8", "9", "10", "11", "12", "14", "16", "18", "20", "22", "24", "26", "28", "36", "48",
"初号", "小初", "一号", "小一", "二号", "小二", "三号", "小三", "四号", "小四", "五号",
"小五", "六号", "小六", "七号", "八号" };
int[] sizeIntArray = { 8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28, 36, 48, 42, 36, 26, 24, 22,
18, 16, 15, 14, 12, 10, 9, 8, 7, 6, 5 };
System.Drawing.Text.InstalledFontCollection collection = new InstalledFontCollection();
FontFamily[] fontFamily = collection.Families;
foreach(var f in fontFamily)
{
if(f.IsStyleAvailable(FontStyle.Regular))
{
listBox1.Items.Add(f.Name);
}
} //将字体名称加入下拉列表
int index = 0;
for (int i = 0; i < listBox1.Items.Count; i++)
{
if(listBox1.Items[i].ToString().Equals("宋体"))
{
index = i;
break;
}
}
for (int i = 0; i < styleArray.Length; i++)
{
listBox2.Items.Add(styleArray[i]);
}
for(int i=0;i<sizeArray.Length;i++)
{
listBox3.Items.Add(sizeArray[i]);
}
textBox1.Text = "宋体";
textBox2.Text = "常规";
textBox3.Text = "9";
listBox1.SetSelected(index, true); //listBox1的默认选中项为宋体
listBox2.SetSelected(0, true); //listBox2的默认选中项为常规
listBox3.SetSelected(1, true); //listBox1的默认选中项为9号字体
label4.Font = font; //示例的文字
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
textBox1.Text = listBox1.SelectedItem.ToString();
font = new Font(textBox1.Text, fontSize(textBox3.Text), fontStyle(textBox2.Text));
label4.Font = font;
}
private void listBox2_SelectedIndexChanged(object sender, EventArgs e)
{
textBox2.Text = listBox2.SelectedItem.ToString();
font = new Font(textBox1.Text, fontSize(textBox3.Text), fontStyle(textBox2.Text));
label4.Font = font;
}
private void listBox3_SelectedIndexChanged(object sender, EventArgs e)
{
textBox3.Text = listBox3.SelectedItem.ToString();
font = new Font(textBox1.Text, fontSize(textBox3.Text), fontStyle(textBox2.Text));
label4.Font = font;
}
//设置字形
private FontStyle fontStyle(string value)
{
FontStyle f = new FontStyle();
switch (value)
{
case "常规":
f = FontStyle.Regular;
break;
case "粗体":
f = FontStyle.Bold;
break;
case "斜体":
f = FontStyle.Italic;
break;
case "粗体 倾斜":
f = FontStyle.Bold | FontStyle.Italic;
break;
}
return f;
}
//设置字体大小
private int fontSize(string value)
{
int size = 0;
for(int i=0;i<sizeArray.Length;i++)
{
if(value.Equals(sizeArray[i]))
{
size = sizeIntArray[i];
break;
}
}
return size;
}
下面是运行的效果:
- 基于C#的字体设计器
- C#字体的设置
- 一个字体的设计
- 网页设计的字体
- 基于C#的Windows定时关机系统的设计
- 用C#实现基于查寻字符串的文件行查询器(3)-设计与实现
- 发布基于C#与Flash通信的游戏设计器完整源代码
- 视觉设计的字体选择
- 字体设计是网页设计的根本
- GTK+(基于DirectFB)的字体处理
- GTK+(基于DirectFB)的字体处理
- 基于libsvm的手写字体识别
- 基于Qt的FreeType字体轮廓解析
- 基于Qt的FreeType字体轮廓解析
- 基于Qt的FreeType字体轮廓解析
- 基于手写字体的识别系统
- 基于C# 的HTML解析器
- 基于C#的雅虎数据下载器
- 开发swt/jface工程的buildpath加载jar包的相关问题
- 对xsd文件的操作 生成java实体并解析生成的xml
- Oracle视图操作教程详解(4)
- IOS中关于日期的操作
- K-SVD, BM3D等
- 基于C#的字体设计器
- (1) array of string/struct: qsort bsearch
- 【ACM】杭电1036:Average is not Fast Enough!
- 八皇后问题
- 发送POST请求代码---java转oc/c++
- spring3mvc与struts2的区别
- (5) hashtable <key, data> : hcreate hdestroy hsearch
- 内存管理——堆栈等内存的分布
- java的IO流转载