我想在Windows窗体应用程序,Visual Studio 2010(C++)中旋转一段文字或数字90°。是否有捷径可寻?如何在Windows Forms/C++中旋转文本或数字90°?
回答
String theString = "90 Degree Rotated Text";
SizeF sz = e.Graphics.VisibleClipBounds.Size;
//Offset the coordinate system so that point (0, 0) is at the center of the desired area.
e.Graphics.TranslateTransform(sz.Width/2, sz.Height/2);
//Rotate the Graphics object.
e.Graphics.RotateTransform(90);
sz = e.Graphics.MeasureString(theString, this.Font);
//Offset the Drawstring method so that the center of the string matches the center.
e.Graphics.DrawString(theString, this.Font,
Brushes.Black, -(sz.Width/2), -(sz.Height/2));
//Reset the graphics object Transformations.
e.Graphics.ResetTransform();
从here
这不是C++ –
OOPS,我只注意到了Winforms标签.. 我这个应该有帮助.. http://www.codeproject.com/Articles/740/Simple-text-rotation – Pankaj
嗨,非常感谢你为了您的答案,我在哪里放置代码?我在这个事件private:System :: Void label37_Paint(System :: Object^sender,System :: Windows :: Forms :: PaintEventArgs^e){}中试过它,它没有工作。 Windows窗体不明白e。非常感谢你! – Weiwei
复制您必须创建一个LOGFONT并与lfEscapement的价值观和lfOrientation玩,就像这样:
SetGraphicsMode(hdc, GM_ADVANCED);
LOGFONT font = {0};
font.lfHeight = 0;
font.lfWidth = 0;
font.lfEscapement = 900; // here
font.lfOrientation = 900; // and here
font.lfWeight = 0;
font.lfItalic = false;
font.lfUnderline = false;
font.lfStrikeOut = false;
font.lfCharSet = DEFAULT_CHARSET;
font.lfOutPrecision = OUT_DEFAULT_PRECIS;
font.lfClipPrecision = CLIP_DEFAULT_PRECIS;
font.lfQuality = CLEARTYPE_QUALITY;
font.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
auto newfont = CreateFontIndirect(&font);
auto oldfont = SelectObject(hdc, newfont);
/* do actual drawing here */
SelectObject(hdc, oldfont);
SetGraphicsMode(hdc, GM_COMPATIBLE);
DeleteObject(newfont);
- 1. 如何在jasper报告中将文本字段旋转90度?
- 2. 在iOS中将文本旋转90度
- 3. 表中的90度文字旋转
- 4. 如何在父元素的中间放置90°旋转文本
- 5. 如何在Windows 8/IE10中90°旋转HTML/Javascript中的图像或对象?
- 6. 如何旋转TeeChart 90度
- 7. 如何旋转StageVideo 90度
- 8. Android的旋转按钮文本90度
- 9. 使用GDI将文本旋转90度
- 10. 垂直对齐90度旋转文字
- 11. 仅使用CSS旋转90°的文本
- 12. 旋转文字/格90度(静态)
- 13. 旋转CALayer 90度?
- 14. 如何旋转UITextField 90度以便文本垂直?
- 15. 如何将FullCalendar事件文本旋转90度为垂直
- 16. CGAffineTransform旋转90度
- 17. 如何在Y轴上向左或向右旋转90度?
- 18. 旋转台90度
- 19. matrix.postRotate(90)在图像旋转
- 20. 在IE8中旋转文本90度不起作用
- 21. 在IE和Firefox中垂直显示文本(旋转90度)
- 22. 我如何在php中将二维数组旋转90度
- 23. 旋转HTML特殊字符或文本
- 24. 如何正确居中旋转(90)文本在自举col-md-1
- 25. 旋转PDF文件n度,其中n不是90的倍数
- 26. 如何顺时针旋转90度(swift3)
- 27. 如何旋转线形90度?
- 28. 如何将输出旋转90度?
- 29. 如何旋转TextView 90度并显示
- 30. 如何旋转90度的UIImage?
* [C#标签的垂直的可能的复制在Windows窗体](http://stackoverflow.com/questions/1371943/c-sharp-vertical-label-in-a-windows-forms)*。 –