Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Class1.cs #1907

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -131,163 +131,164 @@ public void Method41(PaintEventArgs e)
public void Method51(PaintEventArgs e)
{
// <snippet51>
PointF pointF = new PointF(10, 0);
SolidBrush solidBrush = new SolidBrush(Color.Black);

int count = 0;
string familyName = "";
string familyNameAndStyle;
FontFamily[] fontFamilies;
PrivateFontCollection privateFontCollection = new PrivateFontCollection();

// Add three font files to the private collection.
privateFontCollection.AddFontFile("D:\\systemroot\\Fonts\\Arial.ttf");
privateFontCollection.AddFontFile("D:\\systemroot\\Fonts\\CourBI.ttf");
privateFontCollection.AddFontFile("D:\\systemroot\\Fonts\\TimesBD.ttf");
PointF pointF = new PointF(10, 0);
SolidBrush solidBrush = new SolidBrush(Color.Black);

// Get the array of FontFamily objects.
fontFamilies = privateFontCollection.Families;

// How many objects in the fontFamilies array?
count = fontFamilies.Length;
int count = 0;
string familyName = "";
string familyNameAndStyle;
FontFamily[] fontFamilies;

// Display the name of each font family in the private collection
// along with the available styles for that font family.
for (int j = 0; j < count; ++j)
{
// Get the font family name.
familyName = fontFamilies[j].Name;

// Is the regular style available?
if (fontFamilies[j].IsStyleAvailable(FontStyle.Regular))
{
familyNameAndStyle = "";
familyNameAndStyle = familyNameAndStyle + familyName;
familyNameAndStyle = familyNameAndStyle + " Regular";

Font regFont = new Font(
familyName,
16,
FontStyle.Regular,
GraphicsUnit.Pixel);

e.Graphics.DrawString(
familyNameAndStyle,
regFont,
solidBrush,
pointF);

pointF.Y += regFont.Height;
}

// Is the bold style available?
if (fontFamilies[j].IsStyleAvailable(FontStyle.Bold))
{
familyNameAndStyle = "";
familyNameAndStyle = familyNameAndStyle + familyName;
familyNameAndStyle = familyNameAndStyle + " Bold";

Font boldFont = new Font(
familyName,
16,
FontStyle.Bold,
GraphicsUnit.Pixel);

e.Graphics.DrawString(familyNameAndStyle, boldFont, solidBrush, pointF);

pointF.Y += boldFont.Height;
}
// Is the italic style available?
if (fontFamilies[j].IsStyleAvailable(FontStyle.Italic))
{
familyNameAndStyle = "";
familyNameAndStyle = familyNameAndStyle + familyName;
familyNameAndStyle = familyNameAndStyle + " Italic";

Font italicFont = new Font(
familyName,
16,
FontStyle.Italic,
GraphicsUnit.Pixel);

e.Graphics.DrawString(
familyNameAndStyle,
italicFont,
solidBrush,
pointF);

pointF.Y += italicFont.Height;
}

// Is the bold italic style available?
if (fontFamilies[j].IsStyleAvailable(FontStyle.Italic) &&
fontFamilies[j].IsStyleAvailable(FontStyle.Bold))
{
familyNameAndStyle = "";
familyNameAndStyle = familyNameAndStyle + familyName;
familyNameAndStyle = familyNameAndStyle + "BoldItalic";

Font italicFont = new Font(
familyName,
16,
FontStyle.Italic | FontStyle.Bold,
GraphicsUnit.Pixel);

e.Graphics.DrawString(
familyNameAndStyle,
italicFont,
solidBrush,
pointF);

pointF.Y += italicFont.Height;
}
// Is the underline style available?
if (fontFamilies[j].IsStyleAvailable(FontStyle.Underline))
{
familyNameAndStyle = "";
familyNameAndStyle = familyNameAndStyle + familyName;
familyNameAndStyle = familyNameAndStyle + " Underline";

Font underlineFont = new Font(
familyName,
16,
FontStyle.Underline,
GraphicsUnit.Pixel);

e.Graphics.DrawString(
familyNameAndStyle,
underlineFont,
solidBrush,
pointF);

pointF.Y += underlineFont.Height;
}

// Is the strikeout style available?
if (fontFamilies[j].IsStyleAvailable(FontStyle.Strikeout))
using (var privateFontCollection = new PrivateFontCollection)
{
familyNameAndStyle = "";
familyNameAndStyle = familyNameAndStyle + familyName;
familyNameAndStyle = familyNameAndStyle + " Strikeout";

Font strikeFont = new Font(
familyName,
16,
FontStyle.Strikeout,
GraphicsUnit.Pixel);

e.Graphics.DrawString(
familyNameAndStyle,
strikeFont,
solidBrush,
pointF);

pointF.Y += strikeFont.Height;
}

// Separate the families with white space.
pointF.Y += 10;
} // for
// Add three font files to the private collection.
privateFontCollection.AddFontFile("D:\\systemroot\\Fonts\\Arial.ttf");
privateFontCollection.AddFontFile("D:\\systemroot\\Fonts\\CourBI.ttf");
privateFontCollection.AddFontFile("D:\\systemroot\\Fonts\\TimesBD.ttf");

// Get the array of FontFamily objects.
fontFamilies = privateFontCollection.Families;

// How many objects in the fontFamilies array?
count = fontFamilies.Length;

// Display the name of each font family in the private collection
// along with the available styles for that font family.
for (int j = 0; j < count; ++j)
{
// Get the font family name.
familyName = fontFamilies[j].Name;

// Is the regular style available?
if (fontFamilies[j].IsStyleAvailable(FontStyle.Regular))
{
familyNameAndStyle = "";
familyNameAndStyle = familyNameAndStyle + familyName;
familyNameAndStyle = familyNameAndStyle + " Regular";

Font regFont = new Font(
familyName,
16,
FontStyle.Regular,
GraphicsUnit.Pixel);

e.Graphics.DrawString(
familyNameAndStyle,
regFont,
solidBrush,
pointF);

pointF.Y += regFont.Height;
}

// Is the bold style available?
if (fontFamilies[j].IsStyleAvailable(FontStyle.Bold))
{
familyNameAndStyle = "";
familyNameAndStyle = familyNameAndStyle + familyName;
familyNameAndStyle = familyNameAndStyle + " Bold";

Font boldFont = new Font(
familyName,
16,
FontStyle.Bold,
GraphicsUnit.Pixel);

e.Graphics.DrawString(familyNameAndStyle, boldFont, solidBrush, pointF);

pointF.Y += boldFont.Height;
}
// Is the italic style available?
if (fontFamilies[j].IsStyleAvailable(FontStyle.Italic))
{
familyNameAndStyle = "";
familyNameAndStyle = familyNameAndStyle + familyName;
familyNameAndStyle = familyNameAndStyle + " Italic";

Font italicFont = new Font(
familyName,
16,
FontStyle.Italic,
GraphicsUnit.Pixel);

e.Graphics.DrawString(
familyNameAndStyle,
italicFont,
solidBrush,
pointF);

pointF.Y += italicFont.Height;
}

// Is the bold italic style available?
if (fontFamilies[j].IsStyleAvailable(FontStyle.Italic) &&
fontFamilies[j].IsStyleAvailable(FontStyle.Bold))
{
familyNameAndStyle = "";
familyNameAndStyle = familyNameAndStyle + familyName;
familyNameAndStyle = familyNameAndStyle + "BoldItalic";

Font italicFont = new Font(
familyName,
16,
FontStyle.Italic | FontStyle.Bold,
GraphicsUnit.Pixel);

e.Graphics.DrawString(
familyNameAndStyle,
italicFont,
solidBrush,
pointF);

pointF.Y += italicFont.Height;
}
// Is the underline style available?
if (fontFamilies[j].IsStyleAvailable(FontStyle.Underline))
{
familyNameAndStyle = "";
familyNameAndStyle = familyNameAndStyle + familyName;
familyNameAndStyle = familyNameAndStyle + " Underline";

Font underlineFont = new Font(
familyName,
16,
FontStyle.Underline,
GraphicsUnit.Pixel);

e.Graphics.DrawString(
familyNameAndStyle,
underlineFont,
solidBrush,
pointF);

pointF.Y += underlineFont.Height;
}

// Is the strikeout style available?
if (fontFamilies[j].IsStyleAvailable(FontStyle.Strikeout))
{
familyNameAndStyle = "";
familyNameAndStyle = familyNameAndStyle + familyName;
familyNameAndStyle = familyNameAndStyle + " Strikeout";

Font strikeFont = new Font(
familyName,
16,
FontStyle.Strikeout,
GraphicsUnit.Pixel);

e.Graphics.DrawString(
familyNameAndStyle,
strikeFont,
solidBrush,
pointF);

pointF.Y += strikeFont.Height;
}

// Separate the families with white space.
pointF.Y += 10;
} // for
// </snippet51>
}
// d3a4a223-9492-4b54-9afd-db1c31c3cefd
Expand Down
Loading