本文整理汇总了C#中Font.GetHeight方法的典型用法代码示例。如果您正苦于以下问题:C# Font.GetHeight方法的具体用法?C# Font.GetHeight怎么用?C# Font.GetHeight使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Font
的用法示例。
在下文中一共展示了Font.GetHeight方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PrintPageEvent
static private void PrintPageEvent (object sender, PrintPageEventArgs e)
{
float lines_page, y;
int count = 0;
float left = e.MarginBounds.Left;
float top = e.MarginBounds.Top;
String line = null;
Font font = new Font ("Arial", 10);
float font_height = font.GetHeight (e.Graphics);
lines_page = e.MarginBounds.Height / font_height;
while (count < lines_page) {
line = stream.ReadLine ();
if (line == null)
break;
y = top + (count * font_height);
e.Graphics.DrawString (line, font, Brushes.Black, left, y, new StringFormat());
count++;
}
if (line != null)
e.HasMorePages = true;
else
e.HasMorePages = false;
}
示例2: resizeFont
private void resizeFont()
{
const int minFontSize = 7;
//определение подходящего шрифта по ширине control'a
float neededSizeX = (this.Width - this.Font.Size * 2) / this.Text.Length;
int tempSizeXInPoint = minFontSize;
while (true)
{
Graphics g = this.CreateGraphics();
Font tempFont = new Font(this.Font.FontFamily, tempSizeXInPoint);
int tempSize = (int)g.MeasureString(this.Text, tempFont).Width / this.Text.Length;
if (neededSizeX - tempSize < 0.5)
{
break;
}
tempSizeXInPoint++;
#region forDebug
if (tempSizeXInPoint == 300)
{
tempSizeXInPoint = 9;
break;
}
#endregion
}
//определение подходящего шрифта по высоте control'a
int tempSizeYInPoint = minFontSize;
while (true)
{
Graphics g = this.CreateGraphics();
Font tempFont = new Font(this.Font.FontFamily, tempSizeYInPoint);
if (this.Height - g.MeasureString(this.Text, tempFont).Height < 5)
{
break;
}
tempSizeYInPoint++;
#region forDebug
if (tempSizeYInPoint == 300)
{
tempSizeYInPoint = 9;
break;
}
#endregion
}
//выбор наиболее подходящего из двух найденых шрифтов
int resSize;
Font resFont;
if (tempSizeYInPoint > tempSizeXInPoint) // выбираем минимальный размер шрифта, т.к. главное что бы отобразилось все содержимое
{
resSize = tempSizeXInPoint;//размер определенный по ширине подошел
resFont = new Font(this.Font.FontFamily, resSize);
int numberOfLines = (int)((this.Height - 10) / resFont.GetHeight());//есть ли возможность разбить содержимое на несколько строк
if (numberOfLines > 1)
{
int tempResSize = resSize;
while (true)
{
Graphics g = this.CreateGraphics();
Font tempFont = new Font(this.Font.FontFamily, tempResSize);
numberOfLines = (int)((this.Height - 10) / tempFont.GetHeight());
if ((this.Width - tempResSize * 2) * numberOfLines - g.MeasureString(this.Text, tempFont).Width < 100)
{
break;
}
tempResSize++;
#region forDebug
if (tempResSize == 300)
{
tempResSize = 9;
break;
}
#endregion
}
//подходящий размер шрифта определен, теперь проверяем не слишком ли он мал
if (tempResSize < minFontSize + 2)
{
resFont = new Font(this.Font.FontFamily, minFontSize);
}
else if (tempResSize < 25)
{
resFont = new Font(this.Font.FontFamily, tempResSize - 1);
}
else // -1,-2 расходуется на погрешности отступов от краев control'a до текста
{
resFont = new Font(this.Font.FontFamily, tempResSize - 2);
}
}
}
else
{
resSize = tempSizeYInPoint; //размер определенный по высоте подошел
resFont = new Font(this.Font.FontFamily, resSize);
}
this.Font = resFont;
}
示例3: GetHeight
/// <summary>
/// Gets height for the font.
/// </summary>
/// <param name="font">Font whose height is calculated.</param>
/// <returns>Height of the font in inches.</returns>
public double GetHeight(Font font)
{
var multiplier = Application.Current.Host.Content.ScaleFactor / 100d;
return multiplier * font.GetHeight() / _display.Ydpi;
}
示例4: Show
public static string Show()
{
//define the image list to contain all the file type icons
ImageList imageList = new ImageList {
ColorDepth = ColorDepth.Depth32Bit,
ImageSize = new Size(32, 32)
};
imageList.Images.Add("asm", Icons.GetBitmap("filetype.asm", 32));
imageList.Images.Add("c", Icons.GetBitmap("filetype.c", 32));
imageList.Images.Add("cpp", Icons.GetBitmap("filetype.cpp", 32));
imageList.Images.Add("h", Icons.GetBitmap("filetype.h", 32));
imageList.Images.Add("cs", Icons.GetBitmap("filetype.cs", 32));
imageList.Images.Add("vb", Icons.GetBitmap("filetype.vb", 32));
imageList.Images.Add("unknown", Icons.GetBitmap("filetype.unknown", 32));
//get the screen size so we can set the form
//to fill 75% of the screen.
Size screenSize = Screen.FromPoint(Cursor.Position).WorkingArea.Size;
//create the form instance
Form form = new Form() {
Text = "Add solution item",
ShowIcon = false,
ShowInTaskbar = false,
StartPosition = FormStartPosition.CenterScreen,
FormBorderStyle = FormBorderStyle.FixedSingle,
MaximizeBox = false,
MinimizeBox = false,
Size = new Size(600, 400)
//(int)(screenSize.Width * 0.75),
//(int)(screenSize.Height * 0.75)),
};
//create a panel that would contain everything so
//we can easily get the actual working size we have
//for the window
Panel workingArea = new Panel() { Dock = DockStyle.Fill };
form.Controls.Add(workingArea);
//define the "add"/"cancel" buttons first so we can deturmine how
//big everything would be to match it
Button addButton = new Button() { Text = "Add" };
Button cancelButton = new Button() { Text = "Cancel" };
//deturmine the height of the input region
int padding = 5;
int inputRegionHeight = addButton.Height + (padding * 2);
#region create the the list
ListView list = new ListView() {
Location = Point.Empty,
Size = new Size(workingArea.Width, workingArea.Height - inputRegionHeight),
LargeImageList = imageList,
SmallImageList = imageList,
View = View.LargeIcon,
};
workingArea.Controls.Add(list);
addType(list, "asm", "c", "cpp", "h", "cs", "vb", "unknown");
list.Focus();
#endregion
#region add the buttons
Button[] buttons = { addButton, cancelButton };
//add the buttons and calculate there position to be
//displayed on the right side
int currentButtonX = 0;
for (int c = 0; c < buttons.Length; c++) {
currentButtonX += buttons[c].Width + padding;
int x = workingArea.Width - currentButtonX;
int y =
(workingArea.Height - inputRegionHeight) +
(inputRegionHeight / 2) - (buttons[c].Height / 2);
buttons[c].Location = new Point(x, y);
workingArea.Controls.Add(buttons[c]);
}
#endregion
#region Filename label
//define the label
Font filenameFont = new Font("Arial", 10, FontStyle.Bold);
Label filenameLabel = new Label() {
Text = "Filename:",
Font = filenameFont
};
//define the location of the label to be at the beginning and centered
//vertically.
int filenameX = padding;
int filenameY = (workingArea.Height - inputRegionHeight) +
(inputRegionHeight / 2) - (((int)filenameFont.GetHeight() + 1) / 2);
filenameLabel.Location = new Point(filenameX, filenameY);
workingArea.Controls.Add(filenameLabel);
//calculate the end position x position of the label
//so we know were to position the text box
int filenameEndX = 75;//filenameLabel.Width + (padding * 2);
//.........这里部分代码省略.........