Ejemplo n.º 1
0
 private void _enumerator_DeviceListChanged(object sender, EventArgs e)
 {
     BeginInvoke((MethodInvoker) delegate { _deviceListBox.Items.Clear(); });
     foreach (var deviceInfo in _enumerator.Devices)
     {
         var deviceAdapter = new DeviceAdapter(new Device(deviceInfo));
         BeginInvoke((MethodInvoker) delegate { _deviceListBox.Items.Add(deviceAdapter); });
         deviceAdapter.ConnectionStateChanged += (o, state) => Invoke((MethodInvoker) delegate
         {
             _deviceListBox.PerformLayout();
         });
     }
 }
Ejemplo n.º 2
0
        private void _deviceListBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (_selectedDevice != null)
            {
                _selectedDevice.ConnectionStateChanged -= _selectedDevice_ConnectionStateChanged;
                _selectedDevice.BatteryChargeChanged   -= _selectedDevice_BatteryChargeChanged;
                _selectedDevice.Disconnect();
            }
            _selectedDevice = _deviceListBox.SelectedItem as DeviceAdapter;
            if (_selectedDevice != null)
            {
                _selectedDevice.ConnectionStateChanged += _selectedDevice_ConnectionStateChanged;
                _selectedDevice.BatteryChargeChanged   += _selectedDevice_BatteryChargeChanged;
                _selectedDevice.Connect();
            }

            UpdateDeviceControls();
        }