• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            我希望你是我獨(dú)家記憶

            一段永遠(yuǎn)封存的記憶,隨風(fēng)而去
            posts - 263, comments - 31, trackbacks - 0, articles - 3
               :: 首頁 :: 新隨筆 ::  :: 聚合  :: 管理

            自定義鍵盤快捷鍵

            Posted on 2010-11-29 16:55 Hero 閱讀(709) 評(píng)論(0)  編輯 收藏 引用 所屬分類: C#積累
              1using System;
              2using System.Windows;
              3using System.Windows.Controls;
              4using System.Windows.Input;
              5using System.Windows.Media;
              6
              7namespace Petzold.CommandTheMenu
              8{
              9    public class CommandTheMenu : Window
             10    {
             11        TextBlock text;
             12
             13        [STAThread]
             14        public static void Main()
             15        {
             16            Application app = new Application();
             17            app.Run(new CommandTheMenu());
             18        }

             19        public CommandTheMenu()
             20        {
             21            Title = "Command the Menu";
             22
             23            // Create DockPanel.
             24            DockPanel dock = new DockPanel();
             25            Content = dock;
             26
             27            // Create Menu docked at top.
             28            Menu menu = new Menu();
             29            dock.Children.Add(menu);
             30            DockPanel.SetDock(menu, Dock.Top);
             31
             32            // Create TextBlock filling the rest.
             33            text = new TextBlock();
             34            text.Text = "Sample clipboard text";
             35            text.HorizontalAlignment = HorizontalAlignment.Center;
             36            text.VerticalAlignment = VerticalAlignment.Center;
             37            text.FontSize = 32;     // ie, 24 points
             38            text.TextWrapping = TextWrapping.Wrap;
             39            dock.Children.Add(text);
             40
             41            // Create Edit menu.
             42            MenuItem itemEdit = new MenuItem();
             43            itemEdit.Header = "_Edit";
             44            menu.Items.Add(itemEdit);
             45
             46            // Create items on Edit menu.
             47            MenuItem itemCut = new MenuItem();
             48            itemCut.Header = "Cu_t";
             49            itemCut.Command = ApplicationCommands.Cut;
             50            itemEdit.Items.Add(itemCut);
             51
             52            MenuItem itemCopy = new MenuItem();
             53            itemCopy.Header = "_Copy";
             54            itemCopy.Command = ApplicationCommands.Copy;
             55            itemEdit.Items.Add(itemCopy);
             56
             57            MenuItem itemPaste = new MenuItem();
             58            itemPaste.Header = "_Paste";
             59            itemPaste.Command = ApplicationCommands.Paste;
             60            itemEdit.Items.Add(itemPaste);
             61
             62            MenuItem itemDelete = new MenuItem();
             63            itemDelete.Header = "_Delete";
             64            itemDelete.Command = ApplicationCommands.Delete;
             65            itemEdit.Items.Add(itemDelete);
             66
             67            // Add command bindings to window collection.            
             68            CommandBindings.Add(new CommandBinding(ApplicationCommands.Cut,
             69                                        CutOnExecute, CutCanExecute));
             70            CommandBindings.Add(new CommandBinding(ApplicationCommands.Copy,
             71                                        CopyOnExecute, CutCanExecute));
             72            CommandBindings.Add(new CommandBinding(ApplicationCommands.Paste,
             73                                        PasteOnExecute, PasteCanExecute));
             74            CommandBindings.Add(new CommandBinding(ApplicationCommands.Delete,
             75                                        DeleteOnExecute, CutCanExecute));
             76
             77
             78
             79            添加自定義鍵盤快捷鍵
             92        }

             93
             94        void RestoreExecute( object sender, ExecutedRoutedEventArgs e )
             95        {
             96            this.text.Text = "John";
             97        }

             98
             99        void CutCanExecute(object sender, CanExecuteRoutedEventArgs args)
            100        {
            101            args.CanExecute = text.Text != null && text.Text.Length > 0;
            102        }

            103        void PasteCanExecute(object sender, CanExecuteRoutedEventArgs args)
            104        {
            105            args.CanExecute = Clipboard.ContainsText();
            106        }

            107        void CutOnExecute(object sender, ExecutedRoutedEventArgs args)
            108        {
            109            ApplicationCommands.Copy.Execute( nullthis );
            110            ApplicationCommands.Delete.Execute(nullthis);
            111        }

            112        void CopyOnExecute(object sender, ExecutedRoutedEventArgs args)
            113        {
            114            Clipboard.SetText(text.Text);
            115        }

            116        void PasteOnExecute(object sender, ExecutedRoutedEventArgs args)
            117        {
            118            text.Text = Clipboard.GetText();
            119        }

            120        void DeleteOnExecute(object sender, ExecutedRoutedEventArgs args)
            121        {
            122            text.Text = null;
            123        }

            124    }

            125}

            126
            久久免费视频观看| 亚洲色婷婷综合久久| 青青草原综合久久大伊人精品| 青青青国产精品国产精品久久久久| 99久久婷婷国产一区二区| 一本久久免费视频| 国产精品毛片久久久久久久| 一本久久综合亚洲鲁鲁五月天| 久久精品国产亚洲AV香蕉| 欧美久久亚洲精品| 热99re久久国超精品首页| 天天爽天天狠久久久综合麻豆| 久久e热在这里只有国产中文精品99| 久久精品国产亚洲αv忘忧草 | 久久久久久伊人高潮影院| 久久精品国产一区二区三区日韩| 国产精品久久久香蕉| 久久夜色精品国产www| 色综合久久88色综合天天| 久久精品国产亚洲av高清漫画| 欧美激情精品久久久久久久| 国产99久久久国产精免费| 69久久精品无码一区二区| 亚洲va久久久噜噜噜久久狠狠| 一级女性全黄久久生活片免费| 国产精品热久久无码av| 日本免费一区二区久久人人澡 | 亚洲AV无一区二区三区久久 | 久久99久久99小草精品免视看| 97久久国产综合精品女不卡| 婷婷久久五月天| 久久精品国产欧美日韩99热| 一本久久综合亚洲鲁鲁五月天亚洲欧美一区二区 | 亚洲AV成人无码久久精品老人| 亚洲中文字幕无码久久2017| 久久亚洲国产成人影院网站| 久久久久国产一级毛片高清版| 无码专区久久综合久中文字幕| 综合久久国产九一剧情麻豆| 久久狠狠爱亚洲综合影院 | 久久久久久国产精品美女|