C#编写的艺术字类实例代码
程序员文章站
2024-01-24 13:38:04
废话不多说了,直接给大家上代码了,具体代码如下所示:
代码如下:
using system;
using system.collections.generic...
废话不多说了,直接给大家上代码了,具体代码如下所示:
代码如下:
using system; using system.collections.generic; using system.componentmodel; using system.drawing; using system.drawing.text; using system.drawing.drawing2d; using system.data; using system.text; using system.windows.forms; public partial class wordart : usercontrol//这是一个艺术字的控件 { //文本属性 private string _text = "wordart"; public string caption { get { return _text; } set { _text = value; } } //字体以及大小 private font _wordartfont = new font("宋体",15); public font wordartfont { get { return _wordartfont; } set { _wordartfont = value; } } //颜色 private color _wordartforecolor = color.blueviolet; public color wordartforecolor { get { return _wordartforecolor; } set { _wordartforecolor = value; } } //阴影的颜色 private color _wordartbackcolor = color.gray; public color wordartbackcolor { set { _wordartbackcolor = value; } get { return _wordartbackcolor; } } //文本输出质量:呈现模式和平滑效果 private textrenderinghint _textrenderinghint = textrenderinghint.cleartypegridfit; public textrenderinghint wordarttextrenderinghint { get { return _textrenderinghint; } set { _textrenderinghint = value; } } public smoothingmode _smoothingmode = smoothingmode.antialias; public smoothingmode wordartsmoothingmode { get { return _smoothingmode; } set { _smoothingmode = value; } } public wordart() { initializecomponent(); } //艺术字的形式:阴影,浮雕…… private wordarteffectstyle _wordarteffect=wordarteffectstyle.projection;//投影为默认形式; public wordarteffectstyle wordarteffect { get { return _wordarteffect; } set { _wordarteffect = value; } } protected override void onpaint(painteventargs e) { base.onpaint(e); graphics g = this.creategraphics(); brush backbrush=new solidbrush(this.wordartbackcolor); brush forebrush=new solidbrush(this.wordartforecolor); sizef size = g.measurestring(this.caption, this.wordartfont); single posx = (this.width - convert.toint16(size.width)) / 2; single posy = (this.height - convert.toint16(size.height)) / 2; switch (this.wordarteffect) { case wordarteffectstyle.projection://投影效果 //设置文本输出质量 g.textrenderinghint = this.wordarttextrenderinghint; g.smoothingmode = this.wordartsmoothingmode; matrix matrix = new matrix(); //投射 matrix.shear(-1.5f, 0.0f); //缩放 matrix.scale(1, 0.5f); //平移 matrix.translate(120, 75); //对绘图平面坐标实施变换 g.transform = matrix;
代码到此结束了,希望对大家有所帮助!