轻松实现旋转显示文本
2024-07-21 02:18:31
供稿:网友
//本程序显示如何旋转显示文本,代码很简单,不过个人觉得做学习用还是不错的!
//作者: i.posei(ipqn)
//欢迎访问 www.kunwsoft.com
using system;
using system.drawing;
using system.collections;
using system.componentmodel;
using system.windows.forms;
using system.data;
using system.drawing.drawing2d;
using system.drawing.text;
namespace eddy
{
public class form1:system.windows.forms.form
{
/// 必需的设计器变量。
private system.componentmodel.container components = null;
public form1()
{
initializecomponent();
}
protected override void dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.dispose();
}
}
base.dispose( disposing );
}
private void initializecomponent()
{
this.autoscalebasesize = new system.drawing.size(6, 14);
this.clientsize = new system.drawing.size(520, 520);
this.name = "form1";
this.text = "旋转显示文本";
this.paint += new system.windows.forms.painteventhandler(this.form1_paint);
}
[stathread]
static void main()
{
application.run(new form1());
}
private void form1_paint(object sender,system.windows.forms.painteventargs e)
{
//声明并且初始化graphics对象
graphics g=e.graphics;
g.smoothingmode=smoothingmode.antialias;
string str="c#学习笔记 kunwsoft.com";
for(int i=0;i<360;i=i+10)
{
g.translatetransform(260,260);
//将指定旋转应用于g的变换矩阵
g.rotatetransform(i);
brush mybrush=brushes.red;
font drawfont = new font("宋体", 12);
g.drawstring(str,drawfont,mybrush,60,0);
g.resettransform();
}
}
}
}