Control.FontChanged 이벤트
Font 속성 값이 변경되면 발생합니다.
네임스페이스: System.Windows.Forms
어셈블리: System.Windows.Forms(system.windows.forms.dll)
구문
‘선언
Public Event FontChanged As EventHandler
‘사용 방법
Dim instance As Control
Dim handler As EventHandler
AddHandler instance.FontChanged, handler
public event EventHandler FontChanged
public:
event EventHandler^ FontChanged {
void add (EventHandler^ value);
void remove (EventHandler^ value);
}
/** @event */
public void add_FontChanged (EventHandler value)
/** @event */
public void remove_FontChanged (EventHandler value)
JScript에서는 이벤트를 사용할 수 있지만 새로 선언할 수는 없습니다.
설명
이 이벤트는 Font 속성이 프로그래밍 방식으로 수정되거나 사용자 상호 작용에 의해 변경되면 발생합니다.
이벤트 처리에 대한 자세한 내용은 이벤트 사용을 참조하십시오.
예제
다음 코드 예제는 Text 속성 값이 변경될 때 실행되는 이벤트 처리기입니다. Control 클래스에는 해당 PropertyName 값이 변경될 때 발생하는 PropertyNameChanged 이름 패턴의 여러 메서드가 있습니다. 여기서 PropertyName은 해당 속성의 이름을 나타냅니다.
다음 코드 예제에서는 통화 데이터가 표시되는 TextBox의 ForeColor를 변경합니다. 다음 예제에서는 텍스트를 10진수로 변환하고 이 숫자가 음수이면 ForeColor를 Color.Red로, 이 숫자가 양수이면 Color.Black로 변경합니다. 이 예제를 실행하려면 TextBox가 포함된 Form이 있어야 합니다.
Private Sub currencyTextBox_TextChanged(sender As Object, _
e As EventArgs) Handles currencyTextBox.TextChanged
Try
' Convert the text to a Double and determine if it is a negative number.
If Double.Parse(currencyTextBox.Text) < 0 Then
' If the number is negative, display it in Red.
currencyTextBox.ForeColor = Color.Red
Else
' If the number is not negative, display it in Black.
currencyTextBox.ForeColor = Color.Black
End If
Catch
' If there is an error, display the text using the system colors.
currencyTextBox.ForeColor = SystemColors.ControlText
End Try
End Sub
private void currencyTextBox_TextChanged(object sender, EventArgs e)
{
try
{
// Convert the text to a Double and determine if it is a negative number.
if(double.Parse(currencyTextBox.Text) < 0)
{
// If the number is negative, display it in Red.
currencyTextBox.ForeColor = Color.Red;
}
else
{
// If the number is not negative, display it in Black.
currencyTextBox.ForeColor = Color.Black;
}
}
catch
{
// If there is an error, display the text using the system colors.
currencyTextBox.ForeColor = SystemColors.ControlText;
}
}
private:
void currencyTextBox_TextChanged( Object^ /*sender*/, EventArgs^ /*e*/ )
{
try
{
// Convert the text to a Double and determine if it is a negative number.
if ( Double::Parse( currencyTextBox->Text ) < 0 )
{
// If the number is negative, display it in Red.
currencyTextBox->ForeColor = Color::Red;
}
else
{
// If the number is not negative, display it in Black.
currencyTextBox->ForeColor = Color::Black;
}
}
catch ( Exception^ )
{
// If there is an error, display the text using the system colors.
currencyTextBox->ForeColor = SystemColors::ControlText;
}
}
private void currencyTextBox_TextChanged(Object sender, EventArgs e)
{
try {
// Convert the text to a Double and determine if it is a
// negative number.
if (System.Double.Parse(currencyTextBox.get_Text()) < 0) {
// If the number is negative, display it in Red.
currencyTextBox.set_ForeColor(Color.get_Red());
}
else {
// If the number is not negative, display it in Black.
currencyTextBox.set_ForeColor(Color.get_Black());
}
}
catch (System.Exception exp) {
// If there is an error, display the text using the system colors.
currencyTextBox.set_ForeColor(SystemColors.get_ControlText());
}
} //currencyTextBox_TextChanged
플랫폼
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.
버전 정보
.NET Framework
2.0, 1.1, 1.0에서 지원
참고 항목
참조
Control 클래스
Control 멤버
System.Windows.Forms 네임스페이스
OnFontChanged
Control.Font 속성
Font