Sometimes you need to use vertical text in the application C # GDI + drawing and search online.
There are two methods: 1. Use axis rotation.
2. Use stringformat.
1. Use axis rotation. This method is common and practical. However, it is inconvenient for me to use this method. First, pay attention to the coordinates when using this method. Because the coordinate axes are rotated, the coordinates also need to be rotated, which requires calculation.
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. Use stringformat. It is convenient to use this method without rotating the coordinate axis.
Stringformat Sf = new stringformat (); SF. formatflags = stringformatflags. directionvertical; G. drawstring ("depth", new system. drawing. font ("", 16, fontstyle. regular), brushes. black, new pointf (15, stapoint. Y + 5), SF );3. It is relatively complicated to use coordinate axis transformation to draw vertical text, but it is applicable in many places. It is convenient to use the stringformat method, but it has many limitations. Of course, you can also customize a vertical lable control.
Reference: 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