다음을 통해 공유


MenuItem.Click 이벤트

정의

MenuItem을 클릭하면 발생합니다.

public:
 event System::Windows::RoutedEventHandler ^ Click;
public event System.Windows.RoutedEventHandler Click;
member this.Click : System.Windows.RoutedEventHandler 
Public Custom Event Click As RoutedEventHandler 

이벤트 유형

예제

다음 예제는 TextBox에서 텍스트를 조작하는 Menu를 만듭니다. Menu에는 Command, IsCheckable, Header 속성과 Checked, Unchecked, Click 이벤트를 사용하는MenuItem 개체가 포함되어 있습니다.

<Menu>
  <MenuItem Header="_Edit">
    <MenuItem Command="ApplicationCommands.Copy"/>
    <MenuItem Command="ApplicationCommands.Cut"/>
    <MenuItem Command="ApplicationCommands.Paste"/>
  </MenuItem>
  <MenuItem Header="_Font">
    <MenuItem Header="_Bold" IsCheckable="True"
              Checked="Bold_Checked"
              Unchecked="Bold_Unchecked"/>
    <MenuItem Header="_Italic" IsCheckable="True"
              Checked="Italic_Checked"
              Unchecked="Italic_Unchecked"/>
    <Separator/>
    <MenuItem Header="I_ncrease Font Size"
              Click="IncreaseFont_Click"/>
    <MenuItem Header="_Decrease Font Size"
              Click="DecreaseFont_Click"/>
  </MenuItem>
</Menu>
<TextBox Name="textBox1" TextWrapping="Wrap"
         Margin="2">
  The quick brown fox jumps over the lazy dog.
</TextBox>

private void Bold_Checked(object sender, RoutedEventArgs e)
{
    textBox1.FontWeight = FontWeights.Bold;
}

private void Bold_Unchecked(object sender, RoutedEventArgs e)
{
    textBox1.FontWeight = FontWeights.Normal;
}

private void Italic_Checked(object sender, RoutedEventArgs e)
{
    textBox1.FontStyle = FontStyles.Italic;
}

private void Italic_Unchecked(object sender, RoutedEventArgs e)
{
    textBox1.FontStyle = FontStyles.Normal;
}

private void IncreaseFont_Click(object sender, RoutedEventArgs e)
{
    if (textBox1.FontSize < 18)
    {
        textBox1.FontSize += 2;
    }
}

private void DecreaseFont_Click(object sender, RoutedEventArgs e)
{
    if (textBox1.FontSize > 10)
    {
        textBox1.FontSize -= 2;
    }
}

Private Sub Bold_Checked(ByVal sender As Object, ByVal e As RoutedEventArgs)
    textBox1.FontWeight = FontWeights.Bold
End Sub

Private Sub Bold_Unchecked(ByVal sender As Object, ByVal e As RoutedEventArgs)
    textBox1.FontWeight = FontWeights.Normal
End Sub

Private Sub Italic_Checked(ByVal sender As Object, ByVal e As RoutedEventArgs)
    textBox1.FontStyle = FontStyles.Italic
End Sub

Private Sub Italic_Unchecked(ByVal sender As Object, ByVal e As RoutedEventArgs)
    textBox1.FontStyle = FontStyles.Normal
End Sub

Private Sub IncreaseFont_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
    If textBox1.FontSize < 18 Then
        textBox1.FontSize += 2
    End If
End Sub

Private Sub DecreaseFont_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
    If textBox1.FontSize > 10 Then
        textBox1.FontSize -= 2
    End If
End Sub

설명

Click 에 하위 메뉴가 MenuItem 있는 경우 이벤트가 발생하지 않습니다.

라우팅 이벤트 정보

식별자 필드 ClickEvent
라우팅 전략 버블링
대리자 RoutedEventHandler

적용 대상