public static extern int EnumDisplaySettings(string deviceName, int modeNumber, ref DEVMODE devMode);
public ConnectionWindow(Favorites favorites, RDCConnection connection, MainForm.ConnectionDelegate connectionDelegate, SecureString password) { InitializeComponent(); _connection = connection; _favorites = favorites; _connectionDelegate = connectionDelegate; _password = password; keyboardDropdown.SelectedIndex = 1; rdcImage.Parent = gradientBackground; rdcLabel1.Parent = gradientBackground; rdcLabel2.Parent = gradientBackground; DEVMODE devMode = new DEVMODE(); int modeNumber = 0; while (DisplayHelper.EnumDisplaySettings(null, modeNumber, ref devMode) > 0) { if (!_resolutions.Exists((DEVMODE d) => d.dmPelsWidth == devMode.dmPelsWidth && d.dmPelsHeight == devMode.dmPelsHeight)) _resolutions.Add(devMode); modeNumber++; } resolutionTrackBar.Maximum = _resolutions.Count; resolutionTrackBar.Value = _resolutions.Count; if (connection != null) { hostBox.Text = connection.Host; usernameTextBox.Text = connection.Username; passwordTextBox.SecureText = (connection.Password == null ? new SecureString() : connection.Password.Copy()); keyboardDropdown.SelectedIndex = (int)connection.KeyboardMode; printersCheckBox.Checked = connection.ConnectPrinters; clipboardCheckBox.Checked = connection.ConnectClipboard; drivesCheckBox.Checked = connection.ConnectDrives; desktopBackgroundCheckBox.Checked = connection.DesktopBackground; fontSmoothingCheckBox.Checked = connection.FontSmoothing; desktopCompositionCheckBox.Checked = connection.DesktopComposition; windowContentsCheckBox.Checked = connection.WindowContentsWhileDragging; animationCheckBox.Checked = connection.Animations; visualStylesCheckBox.Checked = connection.VisualStyles; bitmapCachingCheckBox.Checked = connection.PersistentBitmapCaching; if (connection.AudioMode == AudioMode.Remotely) playRemotelyRadioButton.Checked = true; else if (connection.AudioMode == AudioMode.None) dontPlayRadioButton.Checked = true; int resolutionIndex = _resolutions.FindIndex((DEVMODE d) => d.dmPelsWidth == connection.DesktopWidth && d.dmPelsHeight == connection.DesktopHeight); if (resolutionIndex != -1) resolutionTrackBar.Value = resolutionIndex; switch (connection.ColorDepth) { case 15: colorDepthDropdown.SelectedIndex = 0; break; case 16: colorDepthDropdown.SelectedIndex = 1; break; case 24: colorDepthDropdown.SelectedIndex = 2; break; case 32: colorDepthDropdown.SelectedIndex = 3; break; } } }