扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:刘涛 来源:天极网 2007年11月16日
关键字:
图二、阴影文本效果 |
// Assumes a PictureBox on the form named picText // with this code being the picText object’s // Paint method private: System::Void picText_Paint( System::Object * sender, System::Windows::Forms::PaintEventArgs * e) { // Test string String* textToDisplay = S"Test string"; // Obtain Graphics object Graphics* g = e->Graphics; // Create a Font object, Times New Roman, 25pt System::Drawing::Font* font = new System::Drawing::Font("Times New Roman", Convert::ToSingle(25), FontStyle::Regular); // Obtain the size of the text to be rendered SizeF textSize = g->MeasureString(textToDisplay, font); // Text will be centered on PictureBox control Single x = (picText->Width - textSize.Width) / 2; Single y = (picText->Height - textSize.Height) / 2; // Clear background g->Clear(Color::White); // 注意:使用系统"光照"画刷绘制阴影文本 g->DrawString(textToDisplay, font, SystemBrushes::ControlLight, x + 5, y + 5); // 使用系统默认的文本画刷绘制前端文本。 g->DrawString(textToDisplay, font, SystemBrushes::ControlText, x, y); } |
图三、块状文本效果 |
// Assumes a PictureBox on the form named picText // with this code being the picText object’s // Paint method private: System::Void picText_Paint( System::Object * sender, System::Windows::Forms::PaintEventArgs * e) { // Test string String* textToDisplay = S"Test string"; // Get drawing surface for PictureBox and clear background Graphics* g = e->Graphics; // Create a Font object System::Drawing::Font* font = new System::Drawing::Font("Times New Roman", Convert::ToSingle(25), FontStyle::Regular); // Obtain the size of the text to be rendered SizeF textSize = g->MeasureString(textToDisplay, font); // Text will be centered on Picture Box control Single x = (picText->Width - textSize.Width) / 2; Single y = (picText->Height - textSize.Height) / 2; // Clear background g->Clear(Color::White); // 从背景处开始反复绘制阴影文本 for (int i = Convert::ToInt32(5); i >= 0; i--) { g->DrawString(textToDisplay, font, SystemBrushes::ControlLight, x - i, y + i); } // 绘制前端文本 g->DrawString(textToDisplay, font, SystemBrushes::ControlText, x, y); } |
图四、浮雕效果 |
图五、雕刻效果 |
// Assumes a PictureBox on the form named picText // with this code being the picText object’s // Paint method private: System::Void picText_Paint( System::Object * sender, System::Windows::Forms::PaintEventArgs * e) { // Test string String* textToDisplay = S"Test string"; // Get drawing surface for PictureBox and clear background Graphics* g = e->Graphics; // Create a Font object System::Drawing::Font* font = new System::Drawing::Font("Times New Roman", Convert::ToSingle(25), FontStyle::Regular); // Obtain the size of the text to be rendered SizeF textSize = g->MeasureString(textToDisplay, font); // Text will be centered on Picture Box control Single x = (picText->Width - textSize.Width) / 2; Single y = (picText->Height - textSize.Height) / 2; // Clear background g->Clear(Color::White); // isEmbossed变量用来决定浮雕或雕刻效果 bool isEmbossed = false; g->DrawString(textToDisplay, font, SystemBrushes::ControlText, x + Convert::ToSingle( (isEmbossed? 1 : -1)), y + Convert::ToSingle( (isEmbossed ? 1 : -1))); // Draw the foreground text g->DrawString(textToDisplay, font, new SolidBrush(Color::White), x, y); |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者