Font.Size 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
public:
property float Size { float get(); };
public float Size { get; }
member this.Size : single
Public ReadOnly Property Size As Single
屬性值
這個 Font 的 Em 大小。
範例
下列程式碼範例示範如何使用 建 Font 構函式和 Size 、 SizeInPoints 和 Unit 屬性。 此範例的設計目的是要與 Windows Form 搭配使用,其中包含 ComboBox 以字串 「Bigger」 和 「Smaller」 填入的具名 ComboBox1
。 將下列程式碼貼到表單中,並將 ComboBox1_SelectedIndexChanged
方法與 SelectedIndexChanged 控制項的事件 ComboBox 產生關聯。
private:
void ComboBox1_SelectedIndexChanged(System::Object^ sender,
System::EventArgs^ e)
{
// Cast the sender object back to a ComboBox.
ComboBox^ ComboBox1 = (ComboBox^) sender;
// Retrieve the selected item.
String^ selectedString = (String^) ComboBox1->SelectedItem;
// Convert it to lowercase.
selectedString = selectedString->ToLower();
// Declare the current size.
float currentSize;
// If Bigger is selected, get the current size from the
// Size property and increase it. Reset the font to the
// new size, using the current unit.
if (selectedString == "bigger")
{
currentSize = Label1->Font->Size;
currentSize += 2.0F;
Label1->Font =gcnew System::Drawing::Font(Label1->Font->Name,
currentSize, Label1->Font->Style, Label1->Font->Unit);
}
// If Smaller is selected, get the current size, in
// points, and decrease it by 2. Reset the font with
// the new size in points.
if (selectedString == "smaller")
{
currentSize = Label1->Font->Size;
currentSize -= 2.0F;
Label1->Font = gcnew System::Drawing::Font(Label1->Font->Name,
currentSize, Label1->Font->Style);
}
}
private void ComboBox1_SelectedIndexChanged(System.Object sender,
System.EventArgs e)
{
// Cast the sender object back to a ComboBox.
ComboBox ComboBox1 = (ComboBox) sender;
// Retrieve the selected item.
string selectedString = (string) ComboBox1.SelectedItem;
// Convert it to lowercase.
selectedString = selectedString.ToLower();
// Declare the current size.
float currentSize;
// Switch on the selected item.
switch(selectedString)
{
// If Bigger is selected, get the current size from the
// Size property and increase it. Reset the font to the
// new size, using the current unit.
case "bigger":
currentSize = Label1.Font.Size;
currentSize += 2.0F;
Label1.Font = new Font(Label1.Font.Name, currentSize,
Label1.Font.Style, Label1.Font.Unit);
// If Smaller is selected, get the current size, in points,
// and decrease it by 1. Reset the font with the new size
// in points.
break;
case "smaller":
currentSize = Label1.Font.SizeInPoints;
currentSize -= 1;
Label1.Font = new Font(Label1.Font.Name, currentSize,
Label1.Font.Style);
break;
}
}
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
' Cast the sender object back to a ComboBox.
Dim ComboBox1 As ComboBox = CType(sender, ComboBox)
' Retrieve the selected item.
Dim selectedString As String = CType(ComboBox1.SelectedItem, String)
' Convert it to lowercase.
selectedString = selectedString.ToLower()
' Declare the current size.
Dim currentSize As Single
' Switch on the selected item.
Select Case selectedString
' If Bigger is selected, get the current size from the
' Size property and increase it. Reset the font to the
' new size, using the current unit.
Case "bigger"
currentSize = Label1.Font.Size
currentSize += 2.0F
Label1.Font = New Font(Label1.Font.Name, currentSize, _
Label1.Font.Style, Label1.Font.Unit)
' If Smaller is selected, get the current size, in points,
' and decrease it by 1. Reset the font with the new size
' in points.
Case "smaller"
currentSize = Label1.Font.SizeInPoints
currentSize -= 1
Label1.Font = New Font(Label1.Font.Name, currentSize, _
Label1.Font.Style)
End Select
End Sub