The Font dialog box allows a user to select a font and
apply it to a text-based document, paragraph or word.
To create a Font dialog box in MS .Net application, you can use
the FontDialog class. |
|
- Start Microsoft Visual Studio .NET
- On the Start Page, click New Project (alternatively, on the main
menu, you can click File -> New -> Project...)
- On the New Project dialog box, in the Project Types tree list, click
Visual C++ Projects
- In the Templates list, click Managed C++ Empty Project
- In the Name edit box, replace the <Enter name> content with
The Font Dialog Box
- In the Location combo box, accept the suggestion or type your own.
If you don't have any, type C:\Programs\MSVC.NET
- Click OK
- On the main menu, click Project -> Add New Item...
- In the Add New Item dialog box, in the Templates list, click C++
File
- In the Name box, replace <Enter name> with Main and click OK
- Replace the contents of the empty file with the following:
#using <mscorlib.dll>
#using <System.dll>
#using <System.Drawing.dll>
#using <System.Windows.Forms.dll>
using namespace System;
using namespace System::Drawing;
using namespace System::Windows::Forms;
__gc class SimpleForm : public Form
{
public:
SimpleForm();
private:
// Declare a pointer to TextBox
TextBox *Editor;
FontDialog *dlgFont;
Button *btnFont;
void btnFontClick(Object *Sender, EventArgs *Args);
};
SimpleForm::SimpleForm()
{
this->Text = S"Font Dialog Box";
this->Size = Drawing::Size(460, 320);
// Initialize the declared TextBox variable
Editor = new TextBox();
Editor->AcceptsReturn = true;
Editor->AcceptsTab = true;
Editor->Multiline = true;
Editor->ScrollBars = ScrollBars::Vertical;
Editor->WordWrap = true;
Editor->Size = Drawing::Size(350, 300);
Editor->Dock = DockStyle::Left;
this->Controls->Add(Editor);
btnFont = new Button;
btnFont->Location = Point(365, 8);
btnFont->Text = S"&Close";
btnFont->Click += new EventHandler(this, btnFontClick);
this->Controls->Add(btnFont);
dlgFont = new FontDialog;
}
void SimpleForm::btnFontClick(Object *Sender, EventArgs *Args)
{
if( dlgFont->ShowDialog() == DialogResult::OK )
Editor->Font = dlgFont->Font;
}
int __stdcall WinMain()
{
SimpleForm * FM = new SimpleForm();
Application::Run(FM);
return 0;
}
|
- Test the application.
|
|