Esempio n. 1
0
        void ContextMenuStrip_Opening(object sender, System.ComponentModel.CancelEventArgs e)
        {
            _contextMenuStrip.PerformSafely(() => _contextMenuStrip.Items.Clear());

            _contextMenuStrip.PerformSafely(() => _contextMenuStrip.Items.Add(_toolStripMenuItemVersion));
            _contextMenuStrip.PerformSafely(() => _contextMenuStrip.Items.Add(new ToolStripSeparator()));


            foreach (var controller in _gamepadHelper.GetControllers())
            {
                var item = new ToolStripMenuItem
                {
                    Text  = $@"Controller {(int)controller.UserIndex + 1} ({controller.GetBatteryInformation(BatteryDeviceType.Gamepad).BatteryLevel.ToString().ToUpperInvariant()})",
                    Image = _gamepadHelper.GetBatteryImage(controller.GetBatteryInformation(BatteryDeviceType.Gamepad).BatteryLevel)
                };
                item.Click += (o, args) => { _gamepadRemote.TurnOff(controller); };

                _contextMenuStrip.PerformSafely(() => _contextMenuStrip.Items.Add(item));
            }

            if (_gamepadHelper.GetControllers().Any())
            {
                _contextMenuStrip.PerformSafely(() => _contextMenuStrip.Items.Add(new ToolStripSeparator()));
            }

            _contextMenuStrip.PerformSafely(() => _contextMenuStrip.Items.Add(_toolStripMenuItemLowBatteryWarning));
            _contextMenuStrip.PerformSafely(() => _contextMenuStrip.Items.Add(_toolStripMenuItemUseGuideButton));
            _contextMenuStrip.PerformSafely(() => _contextMenuStrip.Items.Add(_toolStripMenuItemAutoStartup));
            _contextMenuStrip.PerformSafely(() => _contextMenuStrip.Items.Add(_toolStripMenuItemExit));
        }