(C#)GDI+绘制垂直文字
2013-05-14 08:51
344 查看
有时候在应用程序C# GDI+绘图中需要使用到垂直文字,在网上搜索一下。
有两种方法:1.使用坐标轴旋转实现。
2.使用StringFormat实现。
![](https://img-blog.csdn.net/20130514084425899)
参考 :http://www.codeproject.com/Articles/19774/Extended-Vertical-Label-Control-in-C-NET#_rating
http://www.cnblogs.com/peterzb/archive/2009/06/07/1498173.html
有两种方法:1.使用坐标轴旋转实现。
2.使用StringFormat实现。
1.使用坐标轴旋转实现。
这种方法比较常见,也是比较实用的方法。但对于我个人来说,使用这种方法有一定的不便。首先这种方法使用时需要注意坐标,因为坐标轴旋转,坐标也需要旋转,这需要计算。protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) { float vlblControlWidth; float vlblControlHeight; float vlblTransformX; float vlblTransformY; Color controlBackColor = BackColor; Pen labelBorderPen; SolidBrush labelBackColorBrush; if (_transparentBG) { labelBorderPen = new Pen(Color.Empty, 0); labelBackColorBrush = new SolidBrush(Color.Empty); } else { labelBorderPen = new Pen(controlBackColor, 0); labelBackColorBrush = new SolidBrush(controlBackColor); } SolidBrush labelForeColorBrush = new SolidBrush(base.ForeColor); base.OnPaint(e); vlblControlWidth = this.Size.Width; vlblControlHeight = this.Size.Height; e.Graphics.DrawRectangle(labelBorderPen, 0, 0, vlblControlWidth, vlblControlHeight); e.Graphics.FillRectangle(labelBackColorBrush, 0, 0, vlblControlWidth, vlblControlHeight); e.Graphics.TextRenderingHint = this._renderMode; e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; if (this.TextDrawMode == DrawMode.BottomUp) { vlblTransformX = 0; vlblTransformY = vlblControlHeight; e.Graphics.TranslateTransform(vlblTransformX, vlblTransformY); e.Graphics.RotateTransform(270); e.Graphics.DrawString(labelText, Font, labelForeColorBrush, 0, 0); } else { vlblTransformX = vlblControlWidth; vlblTransformY = vlblControlHeight; e.Graphics.TranslateTransform(vlblControlWidth, 0); e.Graphics.RotateTransform(90); e.Graphics.DrawString(labelText, Font, labelForeColorBrush, 0, 0, StringFormat.GenericTypographic); } }
2.使用StringFormat实现。
使用这种方法不需要旋转坐标轴,比较方便。StringFormat sf = new StringFormat(); sf.FormatFlags = StringFormatFlags.DirectionVertical; g.DrawString("深度", new System.Drawing.Font("微软雅黑", 16, FontStyle.Regular), Brushes.Black, new PointF(15, staPoint.Y + 5), sf);
3.比较
使用坐标轴变换来绘制垂直文字,相对复杂,但其适用的地方多。使用StringFormat方法比较方便,但局限性比较大。当然,也可以自定义一个垂向Lable控件。参考 :http://www.codeproject.com/Articles/19774/Extended-Vertical-Label-Control-in-C-NET#_rating
http://www.cnblogs.com/peterzb/archive/2009/06/07/1498173.html
相关文章推荐
- C#利用GDI+绘制旋转文字等效果实例
- C#中使用GDI+绘制辉光效果文字
- C#利用GDI+绘制旋转文字等效果
- 用GDI+怎么实现绘制倾斜文字
- .net环境用GDI+绘制倾斜文字
- C# 学习笔记一(图形绘制基础1 GDI+)
- C#中使用GDI+绘制形状时自动缩放文本
- c#(mobile) 绘制文字自动换行的实现
- GDI+ C# 画图 、 输出文字
- C#常用GDI+文字操作汇总
- GDI+测算文字绘制范围
- C#+OpenGL+FreeType显示3D文字(3) - 用PointSprite绘制文字
- C#利用GDI+绘制旋转文字,矩形内可以根据布局方式排列文本
- C#中基于GDI+(Graphics)图像处理系列之文字或者图片水印(透明、任意角度旋转)
- csharp,c#,gdi+绘制米字框
- IOS开发 图形绘制,绘制线条,矩形,和垂直和居中绘制文字
- 【转】VB6 GDI+ 入门教程(4)—— 文字绘制
- Gdi+绘制半透明文字并保存为透明背景图片
- C#利用GDI绘制常见图形和文字
- c#(mobile) 绘制文字自动换行的实现