TFontQuality (C++)

From RAD Studio Code Examples
Jump to: navigation, search

Description

The following example demostrates the use of Vcl.Graphics.TFont.Quality. The sample uses a memo, three buttons for font (a TFontDialog component is also needed on the form) and font size changing, and seven buttons, one for each font quality. Optional, for better visibility of the button the sample uses two TGroupBox components to separate the font quality buttons from the font and font size buttons.

Code

// From Font_Quality.h:

#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <Dialogs.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published:	// IDE-managed Components
	TGroupBox *GroupBox2;
	TGroupBox *GroupBox1;
	TMemo *Memo1;
	TButton *Button1;
	TButton *Button2;
	TButton *Button3;
	TButton *Button4;
	TButton *Button5;
	TButton *Button6;
	TButton *Button7;
	TButton *Button8;
	TButton *Button9;
	TButton *Button10;
	TFontDialog *FontDialog1;
	void __fastcall Button1Click(TObject *Sender);
	void __fastcall Button2Click(TObject *Sender);
	void __fastcall Button3Click(TObject *Sender);
	void __fastcall Button4Click(TObject *Sender);
	void __fastcall Button5Click(TObject *Sender);
	void __fastcall Button6Click(TObject *Sender);
	void __fastcall Button7Click(TObject *Sender);
	void __fastcall Button8Click(TObject *Sender);
	void __fastcall Button9Click(TObject *Sender);
	void __fastcall Button10Click(TObject *Sender);
private:	// User declarations
public:		// User declarations
	__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------

// From Font_Quality.cpp:

// puting a text in the memo from the begining
__fastcall TForm1::TForm1(TComponent* Owner)
	: TForm(Owner)
{
  Memo1->Text = "This is a memo";
}

 //buttons for changing the font quality
void __fastcall TForm1::Button1Click(TObject *Sender)
{
  Memo1->Font->Quality = fqDefault;
}

void __fastcall TForm1::Button2Click(TObject *Sender)
{
  Memo1->Font->Quality = fqDraft;
}

void __fastcall TForm1::Button3Click(TObject *Sender)
{
  Memo1->Font->Quality = fqProof;
}

void __fastcall TForm1::Button4Click(TObject *Sender)
{
  Memo1->Font->Quality = fqNonAntialiased;
}

void __fastcall TForm1::Button5Click(TObject *Sender)
{
  Memo1->Font->Quality = fqAntialiased;
}

void __fastcall TForm1::Button6Click(TObject *Sender)
{
  Memo1->Font->Quality = fqClearType;
}

void __fastcall TForm1::Button7Click(TObject *Sender)
{
  Memo1->Font->Quality = fqClearTypeNatural;
}

//open a font dialog and let the user to set the font
void __fastcall TForm1::Button8Click(TObject *Sender)
{
  if (FontDialog1->Execute())
	Memo1->Font->Assign(FontDialog1->Font);
}

//buttons for font size changing (some of the fonts do not support font size changing or may not have specific sizes)
void __fastcall TForm1::Button9Click(TObject *Sender)
{
  Memo1->Font->Size = Memo1->Font->Size + 1;
}

void __fastcall TForm1::Button10Click(TObject *Sender)
{
  Memo1->Font->Size = Memo1->Font->Size - 1;
}

Uses