Check the CheckBox based on key pressed states : CheckBox « Windows Presentation Foundation « C# / C Sharp

Home
C# / C Sharp
1.2D Graphics
2.Class Interface
3.Collections Data Structure
4.Components
5.Data Types
6.Database ADO.net
7.Design Patterns
8.Development Class
9.Event
10.File Stream
11.Generics
12.GUI Windows Form
13.Language Basics
14.LINQ
15.Network
16.Office
17.Reflection
18.Regular Expressions
19.Security
20.Services Event
21.Thread
22.Web Services
23.Windows
24.Windows Presentation Foundation
25.XML
26.XML LINQ
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source
C# / C Sharp » Windows Presentation Foundation » CheckBoxScreenshots 
Check the CheckBox based on key pressed states
Check the CheckBox based on key pressed states
  

<Window x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="WPF" Height="170" Width="200">
    <StackPanel HorizontalAlignment="Center">
        <UniformGrid Columns="2">
            <UniformGrid.Resources>
                <Style TargetType="{x:Type CheckBox}">
                    <Setter Property="IsHitTestVisible" Value="False" />
                    <Setter Property="Margin" Value="5" />
                </Style>
            </UniformGrid.Resources>
            <CheckBox Content="LeftControl" Name="chkLControl"/>
            <CheckBox Content="RightControl" Name="chkRControl"/>

        </UniformGrid>
        <Button Content="Check Keyboard" Margin="10" Click="Button_Click"/>
    </StackPanel>
</Window>

//File:Window.xaml.cs
using System;
using System.Windows;
using System.Windows.Input;

namespace WpfApplication1
{
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();
            CheckKeyboardState();
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            CheckKeyboardState();
        }
        private void CheckKeyboardState()
        {
            chkLControl.IsChecked = Keyboard.IsKeyDown(Key.LeftCtrl);
            chkRControl.IsChecked = Keyboard.IsKeyDown(Key.RightCtrl);
            
        }
    }
}

   
    
  
Related examples in the same category
1.Three-State CheckBoxThree-State CheckBox
2.A CheckBox with a skew transformationA CheckBox with a skew transformation
3.Add CheckBox to StackPanelAdd CheckBox to StackPanel
4.Customized CheckBoxCustomized CheckBox
5.CheckBox StyleCheckBox Style
6.CheckBox checked event listenerCheckBox checked event listener
7.Handles CheckBox Indeterminate events when a CheckBox changes to a indeterminate state.Handles CheckBox Indeterminate events when a CheckBox changes to a indeterminate state.
8.Handle CheckBox Unchecked eventsHandle CheckBox Unchecked events
9.Handle CheckBox checked events
10.Use Linq to get checked CheckBoxUse Linq to get checked CheckBox
11.CheckBox ListCheckBox List
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.