扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:刘涛 来源:天极网 2007年11月16日
关键字:
图:显示倾斜文本的例子程序界面 |
public __gc class Form1 : public System::Windows::Forms::Form { ... protected: String* textToDisplay; Decimal fontSize; Decimal shearSize; ... private: System::Void btnDisplayText_Click(System::Object * sender, System::EventArgs * e) { // Set up internal display values textToDisplay = txtToDisplay->Text; fontSize = spnFontSize->Value; shearSize = spnShear->Value; // Invalidate the control picText->Invalidate(); } |
private: System::Void picText_Paint(System::Object * sender, System::Windows::Forms::PaintEventArgs * e) { if (textToDisplay) { } } |
Graphics* g = e->Graphics; |
System::Drawing::Font* font = new System::Drawing::Font("Times New Roman", Convert::ToSingle(fontSize), FontStyle::Regular); |
SizeF textSize = g->MeasureString(textToDisplay, font); |
g->Clear(SystemColors::Control); |
Single x = (picText->Width - textSize.Width) / 2; Single y = (picText->Height - textSize.Height) / 2; |
g->TranslateTransform(x, y); |
Matrix* transform = g->Transform; |
transform->Shear(Convert::ToSingle(shearSize), 0); |
g->Transform = transform; |
g->DrawString(textToDisplay, font, Brushes::Black, 0, 0); |
g->TranslateTransform(x, y); |
int lineAscent = font->FontFamily->GetCellAscent(font->Style); int lineSpacing = font->FontFamily->GetLineSpacing(font->Style); Single lineHeight = font->GetHeight(g); Single cy = lineHeight * lineAscent / lineSpacing; |
g->DrawString(textToDisplay, font, Brushes::Black, 0, 0); |
g->ScaleTransform(1, -1.0F); |
g->DrawString(textToDisplay, font, Brushes::Gray, 0, -(cy*2)); |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者