📄 form1.h
字号:
#pragma once
namespace GDIPlusReflectedText
{
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace System::Drawing::Drawing2D;
/// <summary>
/// Summary for Form1
///
/// WARNING: If you change the name of this class, you will need to change the
/// 'Resource File Name' property for the managed resource compiler tool
/// associated with all .resx files this class depends on. Otherwise,
/// the designers will not be able to interact properly with localized
/// resources associated with this form.
/// </summary>
public __gc class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
}
protected:
void Dispose(Boolean disposing)
{
if (disposing && components)
{
components->Dispose();
}
__super::Dispose(disposing);
}
private: System::Windows::Forms::Button * btnContactMe;
private: System::Windows::Forms::Button * btnClose;
private: System::Windows::Forms::GroupBox * groupBox1;
private: System::Windows::Forms::TextBox * txtToDisplay;
private: System::Windows::Forms::Label * label1;
private: System::Windows::Forms::Button * btnArticleList;
private: System::Windows::Forms::PictureBox * picText;
private: System::Windows::Forms::Button * btnDisplayText;
protected:
String* textToDisplay;
private:
/// <summary>
/// Required designer variable.
/// </summary>
System::ComponentModel::Container * components;
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
this->btnContactMe = new System::Windows::Forms::Button();
this->btnClose = new System::Windows::Forms::Button();
this->groupBox1 = new System::Windows::Forms::GroupBox();
this->txtToDisplay = new System::Windows::Forms::TextBox();
this->label1 = new System::Windows::Forms::Label();
this->btnArticleList = new System::Windows::Forms::Button();
this->picText = new System::Windows::Forms::PictureBox();
this->btnDisplayText = new System::Windows::Forms::Button();
this->groupBox1->SuspendLayout();
this->SuspendLayout();
//
// btnContactMe
//
this->btnContactMe->Location = System::Drawing::Point(340, 40);
this->btnContactMe->Name = S"btnContactMe";
this->btnContactMe->Size = System::Drawing::Size(80, 23);
this->btnContactMe->TabIndex = 13;
this->btnContactMe->Text = S"Contact &Me";
this->btnContactMe->Click += new System::EventHandler(this, btnContactMe_Click);
//
// btnClose
//
this->btnClose->DialogResult = System::Windows::Forms::DialogResult::Cancel;
this->btnClose->Location = System::Drawing::Point(340, 8);
this->btnClose->Name = S"btnClose";
this->btnClose->Size = System::Drawing::Size(80, 23);
this->btnClose->TabIndex = 15;
this->btnClose->Text = S"Cl&ose";
this->btnClose->Click += new System::EventHandler(this, btnClose_Click);
//
// groupBox1
//
this->groupBox1->Controls->Add(this->txtToDisplay);
this->groupBox1->Controls->Add(this->label1);
this->groupBox1->Location = System::Drawing::Point(4, 0);
this->groupBox1->Name = S"groupBox1";
this->groupBox1->Size = System::Drawing::Size(320, 88);
this->groupBox1->TabIndex = 11;
this->groupBox1->TabStop = false;
this->groupBox1->Text = S"Display Settings";
//
// txtToDisplay
//
this->txtToDisplay->Location = System::Drawing::Point(80, 24);
this->txtToDisplay->Name = S"txtToDisplay";
this->txtToDisplay->Size = System::Drawing::Size(224, 20);
this->txtToDisplay->TabIndex = 1;
this->txtToDisplay->Text = S"Tom Archer";
//
// label1
//
this->label1->Location = System::Drawing::Point(16, 24);
this->label1->Name = S"label1";
this->label1->Size = System::Drawing::Size(56, 23);
this->label1->TabIndex = 0;
this->label1->Text = S"Te&xt:";
this->label1->TextAlign = System::Drawing::ContentAlignment::MiddleRight;
//
// btnArticleList
//
this->btnArticleList->Location = System::Drawing::Point(340, 64);
this->btnArticleList->Name = S"btnArticleList";
this->btnArticleList->Size = System::Drawing::Size(80, 23);
this->btnArticleList->TabIndex = 14;
this->btnArticleList->Text = S"Article &List";
this->btnArticleList->Click += new System::EventHandler(this, btnArticleList_Click);
//
// picText
//
this->picText->BackColor = System::Drawing::Color::White;
this->picText->BorderStyle = System::Windows::Forms::BorderStyle::Fixed3D;
this->picText->Location = System::Drawing::Point(4, 96);
this->picText->Name = S"picText";
this->picText->Size = System::Drawing::Size(320, 160);
this->picText->TabIndex = 16;
this->picText->TabStop = false;
this->picText->Paint += new System::Windows::Forms::PaintEventHandler(this, picText_Paint);
//
// btnDisplayText
//
this->btnDisplayText->Location = System::Drawing::Point(340, 96);
this->btnDisplayText->Name = S"btnDisplayText";
this->btnDisplayText->Size = System::Drawing::Size(80, 23);
this->btnDisplayText->TabIndex = 12;
this->btnDisplayText->Text = S"Display &Text";
this->btnDisplayText->Click += new System::EventHandler(this, btnDisplayText_Click);
//
// Form1
//
this->AutoScaleBaseSize = System::Drawing::Size(5, 13);
this->CancelButton = this->btnClose;
this->ClientSize = System::Drawing::Size(424, 261);
this->Controls->Add(this->btnContactMe);
this->Controls->Add(this->btnClose);
this->Controls->Add(this->groupBox1);
this->Controls->Add(this->btnArticleList);
this->Controls->Add(this->picText);
this->Controls->Add(this->btnDisplayText);
this->Name = S"Form1";
this->Text = S"Managed Extensions - Using GDI+ to Render Reflected Text";
this->groupBox1->ResumeLayout(false);
this->ResumeLayout(false);
}
private: System::Void btnClose_Click(System::Object * sender, System::EventArgs * e)
{ this->Close(); }
private: System::Void btnContactMe_Click(System::Object * sender, System::EventArgs * e)
{
System::Diagnostics::Process::Start(S"IExplore.exe", S"http://www.ArcherConsultingGroup.com/default.asp?id=1011");
}
private: System::Void btnArticleList_Click(System::Object * sender, System::EventArgs * e)
{
System::Diagnostics::Process::Start(S"IExplore.exe", S"http://www.codeguru.com/columns/DotNetTips");
}
private: System::Void btnDisplayText_Click(System::Object * sender, System::EventArgs * e)
{
// Set up internal display values
textToDisplay = txtToDisplay->Text;
// Cause a repaint of the PictureBox
picText->Invalidate();
}
private: System::Void picText_Paint(System::Object * sender, System::Windows::Forms::PaintEventArgs * e)
{
if (textToDisplay)
{
// Obtain the Graphics object
Graphics* g = e->Graphics;
// Instantiate the Font object based on the
// user-supplied Font size
System::Drawing::Font* font =
new System::Drawing::Font("Times New Roman",
Convert::ToSingle(40),
FontStyle::Regular);
// Obtain the size of the text to be rendered
SizeF textSize = g->MeasureString(textToDisplay, font);
// Clear the Picture Box control
g->Clear(Color::White);
// Text will be centered on Picture Box control
Single x = (picText->Width - textSize.Width) / 2;
Single y = (picText->Height - (textSize.Height*1.5)) /2;
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));
}
}
};
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -