FontDialog.MaxSize 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置用户可选择的最大磅值。
public:
property int MaxSize { int get(); void set(int value); };
public int MaxSize { get; set; }
member this.MaxSize : int with get, set
Public Property MaxSize As Integer
属性值
用户可选择的最大磅值。 默认值为 0。
示例
下面的代码示例演示如何使用 MinSize、 MaxSizeShowEffects 和 FontMustExist 成员并处理 Apply 事件。 若要运行此示例,请将以下代码粘贴到包含FontDialog命名和Button命名 FontDialog1
Button1
的窗体中。
void Button1_Click( System::Object^ sender, System::EventArgs^ e )
{
// Set FontMustExist to true, which causes message box error
// if the user enters a font that does not exist.
FontDialog1->FontMustExist = true;
// Associate the method handling the Apply event with the event.
FontDialog1->Apply += gcnew System::EventHandler( this, &Form1::FontDialog1_Apply );
// Set a minimum and maximum size to be
// shown in the FontDialog.
FontDialog1->MaxSize = 32;
FontDialog1->MinSize = 18;
// Show the Apply button in the dialog.
FontDialog1->ShowApply = true;
// Do not show effects such as Underline
// and Bold.
FontDialog1->ShowEffects = false;
// Save the existing font.
System::Drawing::Font^ oldFont = this->Font;
//Show the dialog, and get the result
System::Windows::Forms::DialogResult result = FontDialog1->ShowDialog();
// If the OK button in the Font dialog box is clicked,
// set all the controls' fonts to the chosen font by calling
// the FontDialog1_Apply method.
if ( result == ::DialogResult::OK )
{
FontDialog1_Apply( this->Button1, gcnew System::EventArgs );
}
// If Cancel is clicked, set the font back to
// the original font.
else
// If Cancel is clicked, set the font back to
// the original font.
if ( result == ::DialogResult::Cancel )
{
this->Font = oldFont;
System::Collections::IEnumerator^ myEnum = this->Controls->GetEnumerator();
while ( myEnum->MoveNext() )
{
Control^ containedControl = safe_cast<Control^>(myEnum->Current);
containedControl->Font = oldFont;
}
}
}
// Handle the Apply event by setting all controls' fonts to
// the chosen font.
void FontDialog1_Apply( Object^ sender, System::EventArgs^ e )
{
this->Font = FontDialog1->Font;
System::Collections::IEnumerator^ myEnum1 = this->Controls->GetEnumerator();
while ( myEnum1->MoveNext() )
{
Control^ containedControl = safe_cast<Control^>(myEnum1->Current);
containedControl->Font = FontDialog1->Font;
}
}
private void Button1_Click(System.Object sender, System.EventArgs e)
{
// Set FontMustExist to true, which causes message box error
// if the user enters a font that does not exist.
FontDialog1.FontMustExist = true;
// Associate the method handling the Apply event with the event.
FontDialog1.Apply += new System.EventHandler(FontDialog1_Apply);
// Set a minimum and maximum size to be
// shown in the FontDialog.
FontDialog1.MaxSize = 32;
FontDialog1.MinSize = 18;
// Show the Apply button in the dialog.
FontDialog1.ShowApply = true;
// Do not show effects such as Underline
// and Bold.
FontDialog1.ShowEffects = false;
// Save the existing font.
System.Drawing.Font oldFont = this.Font;
//Show the dialog, and get the result
DialogResult result = FontDialog1.ShowDialog();
// If the OK button in the Font dialog box is clicked,
// set all the controls' fonts to the chosen font by calling
// the FontDialog1_Apply method.
if (result == DialogResult.OK)
{
FontDialog1_Apply(this.Button1, new System.EventArgs());
}
// If Cancel is clicked, set the font back to
// the original font.
else if (result == DialogResult.Cancel)
{
this.Font = oldFont;
foreach ( Control containedControl in this.Controls)
{
containedControl.Font = oldFont;
}
}
}
// Handle the Apply event by setting all controls' fonts to
// the chosen font.
private void FontDialog1_Apply(object sender, System.EventArgs e)
{
this.Font = FontDialog1.Font;
foreach ( Control containedControl in this.Controls )
{
containedControl.Font = FontDialog1.Font;
}
}
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
' Set FontMustExist to true, which causes message box error
' if the user enters a font that does not exist.
FontDialog1.FontMustExist = True
' Set a minimum and maximum size to be
' shown in the FontDialog.
FontDialog1.MaxSize = 32
FontDialog1.MinSize = 18
' Show the Apply button in the dialog.
FontDialog1.ShowApply = True
' Do not show effects such as Underline
' and Bold.
FontDialog1.ShowEffects = False
' Save the existing font.
Dim oldFont As System.Drawing.Font = Me.Font
' Show the dialog and save the result.
Dim result As DialogResult = FontDialog1.ShowDialog()
' If The OK button in the Font dialog box is clicked,
' set all the controls' fonts to the chosen font by
' calling the FontDialog1_Apply method.
If result = DialogResult.OK Then
FontDialog1_Apply(Me.Button1, New System.EventArgs)
' If the Cancel button is clicked, set the controls'
' fonts back to the original font.
ElseIf (result = DialogResult.Cancel) Then
Dim containedControl As Control
For Each containedControl In Me.Controls
containedControl.Font = oldFont
Next
End If
End Sub
' Handle the Apply event by setting all controls' fonts to
' the chosen font.
Private Sub FontDialog1_Apply(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles FontDialog1.Apply
Me.Font = FontDialog1.Font
Dim containedControl As Control
For Each containedControl In Me.Controls
containedControl.Font = FontDialog1.Font
Next
End Sub
注解
为了使最大和最小大小设置生效, MaxSize 必须大于 MinSize,并且两者都必须大于 0。
尝试将此属性设置为小于 0 的值将导致使用值 0。 如果设置为MaxSize小于 的值,MinSize则设置为 MaxSizeMinSize。 将 和 MaxSize 设置为MinSize相同值的效果是将大小选择限制为单个字号。
当点大小为 0 时,没有字号限制。