Пример #1
0
        public MainForm()
        {
            InitializeComponent();

            // generate map
            map = new MazeGenerator().Create(65, 25);

            p = new Player(this, map);
            p.SetXY(1, 1);
            s = new Cubi(this, map, p);
            //s.SetXY(65 - 2, 25 - 2);
            s.SetXY(4, 3);

            // draw map
            var bitMapMap = map.AsBitmap(p, s);

            // add to window
            MainBitmap.Image = bitMapMap;

            // init key handlers
            sw = new Stopwatch(); sw.Start();

            this.KeyPreview = true;

            eh = new PreviewKeyDownEventHandler(PreviewKeyDownHandler);
            this.PreviewKeyDown += eh;
        }
Пример #2
0
        void Init(
            ListView listView,
            List <T> objectList,
            Object owner, String name,
            ShowDataProc showDataProc,
            CreateObjectProc createObjectProc)
        {
            mListView         = listView;
            mObjectList       = objectList;
            mOwner            = owner;
            mName             = name;
            mShowDataProc     = showDataProc;
            mCreateObjectProc = createObjectProc;

            mDoubleClickHandler         = new EventHandler(listView_DoubleClick);
            mPreviewKeyDownEventHandler = new PreviewKeyDownEventHandler(listView_PreviewKeyDown);

            listView.DoubleClick    += mDoubleClickHandler;
            listView.PreviewKeyDown += mPreviewKeyDownEventHandler;

            if (mShowDataProc == null)
            {
                mListView.Columns.Clear();
                mListView.Columns.Add("Index");

                foreach (var propertyInfo in typeof(T).GetProperties())
                {
                    mListView.Columns.Add(propertyInfo.Name).Tag = propertyInfo;
                }
            }
        }
Пример #3
0
        //protected override void OnKeyDown(KeyEventArgs e)
        //{
        //	base.OnKeyDown(e);
        //	switch (e.KeyCode)
        //	{
        //		case Keys.Up:
        //			break;
        //		case Keys.Down:
        //			break;
        //	}
        //}
        public Control doCombo(Control panel, int x, int y, byte[] textBank, List <int> items, byte[] buffer, int address, int numOfBits)
        {
            pnl          = panel;
            AutoEllipsis = true;             //If false: If text string too long and lacking spaces, text can disappear.
            Location     = new Point(x, y);
            //bn.Width = 180;
            Size = new Size(180, 20);
            Font = Globals.font;             //new Font("Lucida Console", 8, FontStyle.Regular, GraphicsUnit.Point, 0);
            //bn.DropDownStyle = ComboBoxStyle.DropDownList;
            //bn.Items.AddRange(items);
            pnl.Controls.Add(this);
            //ctrls.Add(this);
            //itemsL = items.ToList();
            buf       = buffer;
            addr      = address;        //offsets.Add(offset);
            bits      = numOfBits;      //bits.Add(numOfBits);
            TextAlign = ContentAlignment.MiddleLeft;
            //bn.SelectedIndexChanged += new EventHandler(comboChanged);
            //cmb.DrawMode = DrawMode.OwnerDrawFixed;
            //return cmb;

            txt        = textBank;
            this.items = items;

            PreviewKeyDown += new PreviewKeyDownEventHandler(comboKeyDown);
            //bn.MouseClick += new MouseEventHandler(nudrc);
            Click += test;
            return(this);
        }
Пример #4
0
 public LevelBase()
 {
     InitializeComponent();
     gameState       = "Running";
     balloonManager  = new BalloonManager(this);
     PreviewKeyDown += new PreviewKeyDownEventHandler(LevelBase_PreviewKeyDown);
 }
Пример #5
0
        protected virtual void OnPreviewKeyDown(PreviewKeyDownEventArgs e)
        {
            PreviewKeyDownEventHandler handler = (PreviewKeyDownEventHandler)this.Events[PreviewKeyDownEventKey];

            if (handler != null)
            {
                handler(this, e);
            }
        }
Пример #6
0
        /// <summary>
        /// 편집모드에서 엔터를 쳤을 때의 액션목록입니다.
        /// </summary>

        public EasyGridViewParent()
            : base()
        {
            _editingControlEvent = new PreviewKeyDownEventHandler(EditingControl_PreviewKeyDown);
            Now        = new PositionOnList(-1, -1);
            Before     = new PositionOnList(-1, -1);
            _editables = new List <bool?>();
            _itemTypes = new List <ItemTypes>();
        }
Пример #7
0
        /// <summary>
        /// Extends BeginInvoke so that when a state object is not needed, null does not need to be passed.
        /// <example>
        /// previewkeydowneventhandler.BeginInvoke(sender, e, callback);
        /// </example>
        /// </summary>
        public static IAsyncResult BeginInvoke(this PreviewKeyDownEventHandler previewkeydowneventhandler, Object sender, PreviewKeyDownEventArgs e, AsyncCallback callback)
        {
            if (previewkeydowneventhandler == null)
            {
                throw new ArgumentNullException("previewkeydowneventhandler");
            }

            return(previewkeydowneventhandler.BeginInvoke(sender, e, callback, null));
        }
Пример #8
0
        protected virtual void OnPreviewKeyDown(PreviewKeyDownEventArgs e)
        {
            PreviewKeyDownEventHandler handler1 = (PreviewKeyDownEventHandler)this.Events[RadTextBoxItem.PreviewKeyDownEventKey];

            if (handler1 != null)
            {
                handler1(this, e);
            }
        }
Пример #9
0
 // Constructor
 public ScriptEditorForm()
 {
     InitializeComponent();
     editor.Initialize(this);
     KeyPreview      = true;
     PreviewKeyDown += new PreviewKeyDownEventHandler(ScriptEditorForm_PreviewKeyDown);
     KeyDown        += new KeyEventHandler(ScriptEditorForm_KeyDown);
     KeyUp          += new KeyEventHandler(ScriptEditorForm_KeyDown);
 }
Пример #10
0
        protected virtual void OnPreviewKeyDown(PreviewKeyDownEventArgs e)
        {
            PreviewKeyDownEventHandler downEventHandler = (PreviewKeyDownEventHandler)this.Events[RadWebBrowserItem.PreviewKeyDownEventKey];

            if (downEventHandler == null)
            {
                return;
            }
            downEventHandler((object)this, e);
        }
Пример #11
0
 private void AttachEvents()
 {
     MouseDoubleClick += new MouseEventHandler(MapControl_MouseDoubleClick);
     MouseWheel       += new MouseEventHandler(MapControl_MouseWheel);
     Disposed         += new EventHandler(MapControl_Disposed);
     MouseDown        += new MouseEventHandler(MapControl_MouseDown);
     MouseMove        += new MouseEventHandler(MapControl_MouseMove);
     MouseUp          += new MouseEventHandler(MapControl_MouseUp);
     PreviewKeyDown   += new PreviewKeyDownEventHandler(MapControl_PreviewKeyDown);
     SizeChanged      += new EventHandler(AgileMapControl_SizeChanged);
 }
Пример #12
0
 public Size ChangeFormSize(bool _check,
                            CCWin.SkinControl.ChatListBox control,
                            ChatListBox.ChatListClickEventHandler fuc,
                            KeyEventHandler keydownfuc,
                            KeyEventHandler keyupfuc,
                            PreviewKeyDownEventHandler keyprefuc,
                            Form_Main mainForm)
 {
     CreateRelevantForm(_check, control, fuc, keydownfuc, keyupfuc, keyprefuc, mainForm);
     return((_check == false) ? bigsize : smallsize);
 }
Пример #13
0
        public GUIEditor(GUI guiToEdit, List<MenuCommand> toolbarIcons) : this() 
        {
            _gui = guiToEdit;
            _selected = new List<GUIControl>();
            _groups = new List<GUIControlGroup>();

            _toolbarIcons = toolbarIcons;
            
            PreviewKeyDown += new PreviewKeyDownEventHandler(GUIEditor_PreviewKeyDown);
            
            _drawSnapPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
        }
Пример #14
0
        public GUIEditor(GUI guiToEdit, List <MenuCommand> toolbarIcons) : this()
        {
            _gui      = guiToEdit;
            _selected = new List <GUIControl>();
            _groups   = new List <GUIControlGroup>();

            _toolbarIcons = toolbarIcons;

            PreviewKeyDown += new PreviewKeyDownEventHandler(GUIEditor_PreviewKeyDown);

            _drawSnapPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
        }
        private void RemoveEvent()
        {
            FieldInfo f1 = typeof(Control).GetField("EventPreviewKeyDown",
                                                    BindingFlags.Static | BindingFlags.NonPublic);

            object       obj = f1.GetValue(Browser);
            PropertyInfo pi  = Browser.GetType().GetProperty("Events",
                                                             BindingFlags.NonPublic | BindingFlags.Instance);

            EventHandlerList list = (EventHandlerList)pi.GetValue(Browser, null);

            _oldKeyDown = (PreviewKeyDownEventHandler)list[obj];
            list.RemoveHandler(obj, list[obj]);
        }
Пример #16
0
 private void CreateRelevantForm(bool _check,
                                 CCWin.SkinControl.ChatListBox control,
                                 ChatListBox.ChatListClickEventHandler fuc,
                                 KeyEventHandler keydownfuc,
                                 KeyEventHandler keyupfuc,
                                 PreviewKeyDownEventHandler keyprefuc,
                                 Form_Main mainform)
 {
     if (_check == true)
     {
         //Form_MapListBoxShow Form_Temp =
         //    new Form_MapListBoxShow(mainform);
         //Form_Temp.Show();
     }
     else
     {
     }
 }
Пример #17
0
        /// <summary>
        /// Initializes the control.
        /// </summary>
        protected override void OnCreateControl()
        {
            // Don't initialize the graphics device if we are running in the designer.
            if (!DesignMode)
            {
                graphicsDeviceService = new GraphicsDeviceService(Handle,
                                                                  ClientSize.Width, ClientSize.Height);

                // Give derived classes a chance to initialize themselves.
                Initialize();

                graphics.Device = graphicsDeviceService.GraphicsDevice;
                graphics.InitializeDevice();

                PreviewKeyDown += new PreviewKeyDownEventHandler(GraphicsDeviceControl_PreviewKeyDown);
            }

            base.OnCreateControl();
        }
        /// <summary>
        /// Initializes the control.
        /// </summary>
        protected override void OnCreateControl()
        {
            // Don't initialize the graphics device if we are running in the designer.
            if (!DesignMode)
            {
                graphicsDeviceService = new GraphicsDeviceService(Handle,
                    ClientSize.Width, ClientSize.Height);

                // Give derived classes a chance to initialize themselves.
                Initialize();

                graphics.Device = graphicsDeviceService.GraphicsDevice;
                graphics.InitializeDevice();

                PreviewKeyDown += new PreviewKeyDownEventHandler(GraphicsDeviceControl_PreviewKeyDown);
            }

            base.OnCreateControl();
        }
Пример #19
0
        public MainForm()
        {
            InitializeComponent();

            // init key handlers
            turnTimer = new Stopwatch(); turnTimer.Start();

            this.KeyPreview = true;

            eh = new PreviewKeyDownEventHandler(PreviewKeyDownHandler);
            this.PreviewKeyDown += eh;

            // don't let the feedback / inventory windows become selected
            feedbackBox.Enter   += DenyFocus;
            miniInventory.Enter += DenyFocus;

            Refs.mf      = this;
            defaultFocus = this.ActiveControl;
        }
Пример #20
0
        /// <summary>
        /// 初始化<see cref="XButton"/>的实例
        /// </summary>
        public XButton()
        {
            StartColor = Color.White;
            EndColor   = Color.FromArgb(232, 232, 232);

            CheckedStartColor = Color.FromArgb(109, 169, 255);
            CheckedEndColor   = Color.FromArgb(83, 128, 252);
            CheckedForeColor  = Color.White;

            HoldingStartColor = Color.FromArgb(109, 169, 255);
            HoldingEndColor   = Color.FromArgb(83, 128, 252);
            HoldingForeColor  = Color.White;

            ForeColor = Color.FromArgb(80, 80, 80);
            Font      = new Font("微软雅黑", 8, FontStyle.Regular, GraphicsUnit.Point);

            BorderColor = Color.FromArgb(212, 212, 212);
            BorderWidth = 1;

            DefaultButtonBorderColor = Color.FromArgb(64, 192, 255);
            DefaultButtonBorderWidth = 2;

            _shortcutFont = new Font(Font, FontStyle.Underline | Font.Style);

            _enableLinearGradientColor = true;
            _enableRoundedRectangle    = true;

            _displayStyle = XButtonDisplayStyle.Text;

            DropDownItems.AfterItemAdded   += DropDownItemAdded;
            DropDownItems.AfterItemRemoved += DropDownItemRemoved;

            _parentKeyDownEventHandler = (s1, e1) =>
            {
                if ((char)e1.KeyCode == _shortcut)
                {
                    PerformClick();
                }
            };

            SetStyle(ControlStyles.DoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint, true);
        }
Пример #21
0
        public GUIEditor(GUI guiToEdit, List <MenuCommand> toolbarIcons) : this()
        {
            _gui      = guiToEdit;
            _selected = new List <GUIControl>();
            _groups   = new List <GUIControlGroup>();

            _toolbarIcons        = toolbarIcons;
            sldZoomLevel.Maximum = ZOOM_MAX_VALUE / ZOOM_STEP_VALUE;
            sldZoomLevel.Value   = 100 / ZOOM_STEP_VALUE;

            PreviewKeyDown          += new PreviewKeyDownEventHandler(GUIEditor_PreviewKeyDown);
            MouseWheel              += new MouseEventHandler(GUIEditor_MouseWheel);
            bgPanel.MouseWheel      += new MouseEventHandler(GUIEditor_MouseWheel);
            sldZoomLevel.MouseWheel += new MouseEventHandler(GUIEditor_MouseWheel);

            _drawSnapPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;

            SetZoomSliderToDefault();
            UpdateScrollableWindowSize();
        }
Пример #22
0
 public void Read(Action <string> callback)
 {
     barCodeCallback            = callback;
     handler                    = new PreviewKeyDownEventHandler(MainWindow_PreviewKeyDown);
     formWindow.PreviewKeyDown += handler;
 }
Пример #23
0
        void prepareEditor()
        {
            switch (objType)
            {
            case TypeCode.Boolean:
                editorKeyDown = (s, e) => {
                    if (e.KeyCode == Keys.Y)
                    {
                        editorBool = true;
                    }
                    else if (e.KeyCode == Keys.N)
                    {
                        editorBool = false;
                    }
                };
                break;

            case TypeCode.Char:
            case TypeCode.Byte:
            case TypeCode.UInt16:
            case TypeCode.UInt32:
            case TypeCode.UInt64:
            case TypeCode.SByte:
            case TypeCode.Int16:
            case TypeCode.Int32:
            case TypeCode.Int64:
            case TypeCode.Single:
            case TypeCode.Double:
            case TypeCode.Decimal:
                objType.GetLimits(out var mi, out var ma);
                numMin = Convert.ToDecimal(mi);
                numMax = Convert.ToDecimal(ma);
                decimal num()
                {
                    decimal n = 0;
                    string  t = editor.Text;

                    if (!string.IsNullOrWhiteSpace(t))
                    {
                        n = (decimal)Convert.ChangeType(t, TypeCode.Decimal);
                    }
                    return(n);
                }

                editorNum     = num();
                editorKeyDown = (s, e) => {
                    decimal n2, n = 0;
                    string  result = null;
                    try {
                        n2        = n = num();
                        editorNum = n;
                        Keys k = e.KeyCode;
                        if (k == Keys.Up || k == Keys.Oemplus)
                        {
                            n += 1 * (e.Control ? 5 : 1);
                        }
                        else if (k == Keys.Down || k == Keys.OemMinus)
                        {
                            n -= 1 * (e.Control ? 5 : 1);
                        }
                        else if (k == Keys.PageUp)
                        {
                            n += 4 * (e.Control ? 5 : 1);
                        }
                        else if (k == Keys.PageDown)
                        {
                            n -= 4 * (e.Control ? 5 : 1);
                        }
                        else if (e.Control && k == Keys.Back)
                        {
                            keyDel = false;
                        }
                        else if (e.Control && k == Keys.Delete)
                        {
                            keyDel = true;
                        }
                        if (n < numMin)
                        {
                            n = numMin;
                        }
                        else if (n > numMax)
                        {
                            n = numMax;
                        }
                        if (e.IsInputKey = (n != n2))
                        {
                            result = n.ToString();    //Convert.ChangeType(n, objType).ToString();
                        }
                    } catch (OverflowException oe) {
                        var type = (Type)oe.TargetSite.GetType().GetProperty("ReturnType")
                                   .GetMethod.Invoke(oe.TargetSite, new object[0]);
                        var limit = type.GetField(n >= 0 ? "MaxValue" : "MinValue").GetValue(null);
                        result = limit.ToString();
                    } catch (Exception) {
                        result = Convert.ChangeType(editorNum, objType).ToString();
                    }
                    if (result != null)
                    {
                        editor.SuspendDrawing();
                        managedKey  = true;
                        editor.Text = result;
                        editor.ResumeDrawing();
                    }
                };
                editorLeave = (s, e) => {
                    object r;
                    bool   ok = Core.TryChangeType(editor.Text, objType, out r) ||
                                Core.TryChangeType(editorNum, objType, out r);
                    var si = editTarget.SubItems[editSubIndex];
                    editor.Text = (ok ? r : (si is LVSI_Ex x ? x.Value : si.Text)).ToString();
                };
                break;
            }

            switch (objType)
            {
            case TypeCode.Boolean:
                editorTransformer = (AutoTextBox from, StringBuilder text, ref int caret) => {
                    if (text.Length < 1)
                    {
                        return;
                    }
                    if (editorBool == true)
                    {
                        text.Clear();
                        text.Append(YES);
                    }
                    else if (editorBool == false)
                    {
                        text.Clear();
                        text.Append(NO);
                    }
                    caret = text.Length;
                };
                break;

            case TypeCode.Char:
                editorTransformer = (AutoTextBox from, StringBuilder text, ref int caret) => {
                    if (text.Length > 1)
                    {
                        text.Remove(0, text.Length - 1);
                    }
                    else
                    {
                        text.Append('\0');
                    }
                    caret = text.Length;
                };
                break;

            case TypeCode.Byte:
            case TypeCode.UInt16:
            case TypeCode.UInt32:
            case TypeCode.UInt64:
                editorTransformer = (AutoTextBox from, StringBuilder text, ref int caret)
                                    => selectiveNumber(validUnsigned, from, text, ref caret);
                break;

            case TypeCode.SByte:
            case TypeCode.Int16:
            case TypeCode.Int32:
            case TypeCode.Int64:
                editorTransformer = (AutoTextBox from, StringBuilder text, ref int caret)
                                    => selectiveNumber(validSigned, from, text, ref caret);
                break;

            case TypeCode.Single:
            case TypeCode.Double:
            case TypeCode.Decimal:
                editorTransformer = (AutoTextBox from, StringBuilder text, ref int caret)
                                    => selectiveNumber(validFloating, from, text, ref caret);
                break;
            }
        }
Пример #24
0
 private void Form1_Load(object sender, EventArgs e)
 {
     pictureBox1.Paint += new PaintEventHandler(pictureBox1_Paint);
     PreviewKeyDown    += new PreviewKeyDownEventHandler(Form1_PreviewKeyDown);
     Shown             += new EventHandler(Form1_Shown);
 }
Пример #25
0
        /// <summary>
        /// Добавление флеш-баннера на форму
        /// </summary>
        /// <param name="flash"></param>
        /// <param name="bannerList"></param>
        /// <param name="f"></param>
        /// <param name="tar"></param>
        public static void AddBanner(zeus.HelperClass.zBanner flash, ref AxShockwaveFlashObjects.AxShockwaveFlash banner, ref System.Windows.Forms.Form f, PreviewKeyDownEventHandler tar)
        {
            string location = flash.location;
            string size     = flash.size;
            string src      = flash.src;

            int X      = int.Parse(location.Split(';')[0]);
            int Y      = int.Parse(location.Split(';')[1]);
            int width  = int.Parse(size.Split(';')[0]);
            int height = int.Parse(size.Split(';')[1]);

            AxShockwaveFlashObjects.AxShockwaveFlash fl = new AxShockwaveFlashObjects.AxShockwaveFlash();
            fl.Stop();
            fl.Size     = new Size(width, height);
            fl.Location = new Point(X, Y);
            fl.Movie    = Ipaybox.StartupPath + @"\" + src;

            fl.PreviewKeyDown += tar;
            f.Controls.Add(fl);
        }
Пример #26
0
        public void StartEditing(ListViewItem item, int subIndex)
        {
            //Debug.WriteLine($@"start editing;");
            var e = new SubItemEditingEA(item, subIndex);

            SubItemEditing?.Invoke(this, e);
            var    sub = item.SubItems[subIndex];
            string value;
            bool   hide = false;

            if (sub is LVSI_Ex x)
            {
                var o = x.Value;
                objType = o?.GetType().GetInterfaces()
                          .Where(i => i.Name == "IConvertible").Count() >= 1
                        ? Convert.GetTypeCode(o)
                        : TypeCode.Object;
                if (o is bool b)
                {
                    value = b ? YES : NO;
                }
                else
                {
                    value = o?.ToString() ?? "";
                }
                hide = x.ShouldBeHidden;
            }
            else
            {
                value   = sub.Text;
                objType = TypeCode.String;
            }
            item.EnsureVisible();

            Rectangle subRect = GetSubItemBounds(item, subIndex);

            if (subRect.X < 0)
            {
                subRect.Width += subRect.X;
                subRect.X      = 0;
            }
            if (subRect.X + subRect.Width > Width)
            {
                subRect.Width = Width - subRect.Left;
            }
            subRect.Offset(Left, Top);

            oldForm = FindForm();
            oldForm?.Controls.Add(editor);
            Point origin = Point.Empty;
            Point pPos   = Parent.PointToScreen(origin);
            Point ePPos  = oldForm.PointToScreen(origin);
            var   align  = Columns[subIndex].TextAlign;

            if (align == HorizontalAlignment.Left)
            {
                subRect.X     += 3;
                subRect.Width -= 3;
            }
            else if (align == HorizontalAlignment.Right)
            {
                subRect.X     += 1;
                subRect.Width -= 4;
            }
            subRect.Y      += 2;
            subRect.Height -= 3;
            subRect.Offset(pPos.X - ePPos.X, pPos.Y - ePPos.Y);
            if (subIndex == 0 && item.ImageList != null)
            {
                int iconRes = 20;
                subRect.X     += iconRes - 1;
                subRect.Width -= iconRes;
            }
            SelectedItems.Clear();
            item.Selected = true;
            editTarget    = item;
            editSubIndex  = subIndex;

            editor.TextAlign    = align;
            editor.PasswordChar = hide ? '\u25CF' : '\0';
            editor.Bounds       = subRect;
            editor.Font         = item.Font;
            editorLeave         = null;
            editorKeyDown       = null;
            editorTransformer   = null;
            editor.Text         = value;
            prepareEditor();
            editor.Visible = true;
            editor.BringToFront();
            editor.Focus();
        }
Пример #27
0
 public KeyControllerConcreteSubject()
 {
     _keyDownPreviewHandler = new PreviewKeyDownEventHandler(this.OnPreviewKeydown);
     _keyDownHandler        = new KeyEventHandler(this.CapturedKeydown);
 }
Пример #28
0
        static void Main(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException += (o, e) =>
            {
                MessageBox.Show(e.ExceptionObject.ToString(), "发生错误!");
            };

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            List <UinstallItem> itemList = PrepareUinstallList();

            Form form = new Form();

            form.Text          = "软件卸载助手 v1.0";
            form.Size          = new Size(800, 500);
            form.StartPosition = FormStartPosition.CenterScreen;

            DataGridView grid = new DataGridView();

            grid.Dock                     = DockStyle.Fill;
            grid.ReadOnly                 = true;
            grid.SelectionMode            = DataGridViewSelectionMode.FullRowSelect;
            grid.MultiSelect              = false;
            grid.AutoSizeColumnsMode      = DataGridViewAutoSizeColumnsMode.None;
            grid.RowHeadersVisible        = false;
            grid.AllowUserToResizeRows    = false;
            grid.AllowUserToResizeColumns = false;
            grid.CellBorderStyle          = DataGridViewCellBorderStyle.RaisedHorizontal;
            grid.DataSource               = itemList;
            form.Controls.Add(grid);

            StatusStrip statusBar = new StatusStrip();

            statusBar.Dock = DockStyle.Bottom;
            form.Controls.Add(statusBar);

            ToolStripStatusLabel statusLabelItemCnt = new ToolStripStatusLabel();

            statusLabelItemCnt.TextAlign   = ContentAlignment.MiddleLeft;
            statusLabelItemCnt.Width       = 90;
            statusLabelItemCnt.BorderSides = ToolStripStatusLabelBorderSides.All;
            statusBar.Items.Add(statusLabelItemCnt);
            ToolStripStatusLabel statusLabelSearchStr = new ToolStripStatusLabel();

            statusLabelSearchStr.Spring    = true;
            statusLabelSearchStr.TextAlign = ContentAlignment.MiddleLeft;
            statusBar.Items.Add(statusLabelSearchStr);

            // 单击列头,排序
            bool ascendingSort = true;

            grid.ColumnHeaderMouseClick += (o, e) =>
            {
                var column = grid.Columns[e.ColumnIndex];

                {
                    Type t = column.ValueType;
                    if (t.IsGenericType && t.GetGenericTypeDefinition().FullName == "System.Nullable`1")
                    {
                        t = t.GetGenericArguments()[0];
                    }
                    if (t.GetInterface("IComparable") == null)
                    {
                        return;
                    }
                }

                grid.ScrollBars = ScrollBars.None;
                grid.DataSource = null;
                ascendingSort   = !ascendingSort;
                var fGet = MakeGetPropertyFunc(typeof(UinstallItem).GetProperty(column.DataPropertyName));
                itemList.Sort((x, y) =>
                {
                    int r       = 0;
                    object valX = fGet(x);
                    object valY = fGet(y);
                    if (valX == null && valY == null)
                    {
                        r = 0;
                    }
                    else if (valX == null)
                    {
                        r = -1;
                    }
                    else if (valY == null)
                    {
                        r = 1;
                    }
                    else
                    {
                        r = (valX as IComparable).CompareTo(valY);
                    }
                    return(ascendingSort ? r : -r);
                });
                grid.DataSource = itemList;
                grid.ScrollBars = ScrollBars.Both;
            };

            // 控制显示的列数
            int    visibleColumn        = 4;
            Action adjustGridColumnFunc = () =>
            {
                for (int i = 0; i < grid.Columns.Count; ++i)
                {
                    var column = grid.Columns[i];
                    column.Width =
                        (typeof(UinstallItem).GetProperty(column.DataPropertyName).
                         GetCustomAttributes(typeof(DisplayWidth), false)[0] as DisplayWidth).Width;
                    column.Visible = i < visibleColumn;
                }
            };

            grid.DataBindingComplete += (o, e) =>
            {
                adjustGridColumnFunc();
                statusLabelItemCnt.Text = string.Format("共有{0}个项目", itemList.Count);
            };

            // 右键菜单
            ContextMenuStrip contextMenu = new ContextMenuStrip();

            contextMenu.Items.Add("详细信息").Click += (o, e) =>
            {
                visibleColumn = 104 - visibleColumn;
                adjustGridColumnFunc();
            };
            contextMenu.Items.Add(string.Format(AppConfig.BrowseWow64 ? "兼容软件" : "非兼容软件")).Click += (o, e) =>
            {
                AppConfig.BrowseWow64 = !AppConfig.BrowseWow64;
                Win32Import.WinExec(Environment.CommandLine, 5);
                form.Close();
            };
            contextMenu.Items.Add("关于").Click += (o, e) =>
            {
                MessageBox.Show("Scan制作!", "关于");
            };
            MouseEventHandler mouseHandlerShowMenu = (o, e) =>
            {
                if (e.Button == MouseButtons.Right)
                {
                    contextMenu.Show(grid, e.Location);
                }
            };

            grid.MouseClick += mouseHandlerShowMenu;
            form.MouseClick += mouseHandlerShowMenu;

            // 输入定位; 包括把form和grid的输入字符都交给输入框
            TextBox searchTextBox = new TextBox();

            searchTextBox.Location     = new Point(-5, -5);
            searchTextBox.Size         = new Size(1, 1);
            searchTextBox.ImeMode      = ImeMode.On;
            searchTextBox.TextChanged += (o, e) =>
            {
                statusLabelSearchStr.Text = "";
                if (string.IsNullOrEmpty(searchTextBox.Text))
                {
                    return;
                }
                statusLabelSearchStr.Text = string.Format("搜索:{0}", searchTextBox.Text);
                int idx = 0;
                foreach (string name in itemList.Select(n => n.DisplayName))
                {
                    if (name.StartsWith(searchTextBox.Text, StringComparison.OrdinalIgnoreCase))
                    {
                        Program.Assert(idx >= 0 && idx < grid.Rows.Count);
                        grid.CurrentCell = grid.Rows[idx].Cells[0];
                        break;
                    }
                    ++idx;
                }
            };
            form.Controls.Add(searchTextBox);
            grid.MouseClick += (o, e) => { searchTextBox.Text = string.Empty; };
            KeyPressEventHandler keyPressFunc = (o, e) =>
            {
                if (char.IsControl(e.KeyChar))
                {
                    return;
                }
                searchTextBox.Text          += e.KeyChar;
                searchTextBox.SelectionStart = searchTextBox.Text.Length;
            };
            PreviewKeyDownEventHandler previewKeyDownFunc = (o, e) =>
            {
                if (e.KeyCode == Keys.Up || e.KeyCode == Keys.Down ||
                    e.KeyCode == Keys.Escape || e.KeyCode == Keys.Enter)
                {
                    return;
                }
                searchTextBox.Focus();
            };

            form.KeyPress       += keyPressFunc;
            grid.KeyPress       += keyPressFunc;
            form.PreviewKeyDown += previewKeyDownFunc;
            grid.PreviewKeyDown += previewKeyDownFunc;

            // 弹出详细信息
            grid.DoubleClick += (o, e) =>
            {
                if (grid.SelectedRows == null || grid.SelectedRows.Count == 0)
                {
                    return;
                }
                int idx = grid.SelectedRows[0].Index;
                Program.Assert(idx >= 0 && idx < itemList.Count);
                TryUninstallItem(itemList[idx]);
            };

            // esc,退出
            KeyEventHandler escHandler = (o, e) =>
            {
                if (e.KeyCode == Keys.Escape)
                {
                    form.Close();
                }
            };

            form.KeyUp          += escHandler;
            grid.KeyUp          += escHandler;
            searchTextBox.KeyUp += escHandler;

            // 检测列表中的项目是否已经从注册表中删除,是的话重启
            var registryChangeDetectTimer = new System.Windows.Forms.Timer();

            registryChangeDetectTimer.Interval = 1000;
            registryChangeDetectTimer.Tick    += (o, e) =>
            {
                using (RegistryKey uninstallKey = OpenUninstallRegistryKey(false))
                {
                    List <string> subKeyNames = uninstallKey.GetSubKeyNames().ToList();
                    subKeyNames.Sort();
                    foreach (UinstallItem item in itemList)
                    {
                        if (subKeyNames.BinarySearch(item.RegistryKey) < 0)
                        {
                            Win32Import.WinExec(Environment.CommandLine, 5);
                            form.Close();
                            break;
                        }
                    }
                }
            };
            registryChangeDetectTimer.Start();

            Application.Run(form);
        }