using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Collections; namespace sharprd { public partial class NewRDPConnection : Form { private const string computerNameMessage1 = "The computer name field is blank. Enter a full remote computer name"; private const string computerNameMessage2 = "You will be asked for credentials when you connect"; private RDConnection connection; public RDConnection Connection { get { return connection; } set { connection = value; cboType.SelectedIndex = (int)connection.Type; txtName.Text = connection.Name; txtDescription.Text = connection.Description; txtComputer.Text = connection.Computer; txtDomain.Text = connection.Domain; txtUsername.Text = connection.Username; txtPassword.Text = !string.IsNullOrEmpty(connection.Password) ? Encryption.Decrypt(connection.Password) : string.Empty; switch (connection.ColorDepth) { case RDConnection.ColorDepths.Color256: cboColorDepth.SelectedIndex = 0; break; case RDConnection.ColorDepths.HighColor15: cboColorDepth.SelectedIndex = 1; break; case RDConnection.ColorDepths.HighColor16: cboColorDepth.SelectedIndex = 2; break; case RDConnection.ColorDepths.TrueColor24: cboColorDepth.SelectedIndex = 3; break; case RDConnection.ColorDepths.TrueColor32: cboColorDepth.SelectedIndex = 4; break; } chkConsole.Checked = connection.Console; cboRemoteAudio.SelectedIndex = (int)connection.RemoteAudio; chkPrinters.Checked = connection.Printers; chkClipboard.Checked = connection.Clipboard; chkDrives.Checked = connection.Drives; chkProgram.Checked = !string.IsNullOrEmpty(connection.AlternateShell) || !string.IsNullOrEmpty(connection.ShellWorkingDirectory); txtAlternateShell.Text = connection.AlternateShell; txtShellWorkingDirectory.Text = connection.ShellWorkingDirectory; cboDisplayMode.SelectedIndex = connection.DisplayMode == RDConnection.DisplayModes.Fullscreen ? 0 : 1; chkDisplayConnectionBar.Checked = connection.DisplayConnectionBar; cboPerformance.SelectedIndex = (int)connection.PerformancePreset; chkDesktopBackground.Checked = connection.DesktopBackground; chkFontSmoothing.Checked = connection.FontSmoothing; chkDesktopComposition.Checked = connection.DesktopComposition; chkWindowContents.Checked = connection.WindowContents; chkMenuAnimation.Checked = connection.MenuAnimation; chkVisualStyles.Checked = connection.VisualStyles; chkPersistentBitmapCaching.Checked = connection.PersistentBitmapCaching; chkNla.Checked = connection.NLA; } } public NewRDPConnection() { InitializeComponent(); cboType.SelectedIndex = (int)RDConnection.Types.RDP; cboColorDepth.SelectedIndex = 2; // RDConnection.ColorDepths.HighColor16 cboDisplayMode.SelectedIndex = (int)RDConnection.DisplayModes.Tabbed; cboRemoteAudio.SelectedIndex = (int)RDConnection.RemoteAudioConfiguration.DoNotPlay; chkClipboard.Checked = true; cboPerformance.SelectedIndex = (int)RDConnection.PerformancePresets.LowBroadband; lblComputerName.Text = computerNameMessage1; } private void ButtonClick(object sender, EventArgs e) { if (sender == btnOk) { if (string.IsNullOrEmpty(txtName.Text)) { Error("The connection name is blank"); return; } if (string.IsNullOrEmpty(txtComputer.Text)) { Error("The computer name is blank or it contains invalid characters. Try typing it again.\n\nInvalid characters include; spaces, tabs, ; : < > * + = \\ | ! , \""); return; } DialogResult = DialogResult.OK; if (connection == null) { connection = new RDConnection(); } connection.Type = (RDConnection.Types)cboType.SelectedIndex; connection.Name = txtName.Text; connection.Description = txtDescription.Text; connection.Computer = txtComputer.Text; connection.Domain = txtDomain.Text; connection.Username = txtUsername.Text; connection.Password = !string.IsNullOrEmpty(txtPassword.Text) ? Encryption.Encrypt(txtPassword.Text) : string.Empty; RDConnection.ColorDepths colorDepth = 0; switch (cboColorDepth.SelectedIndex) { case 0: colorDepth = RDConnection.ColorDepths.Color256; break; case 1: colorDepth = RDConnection.ColorDepths.HighColor15; break; case 2: colorDepth = RDConnection.ColorDepths.HighColor16; break; case 3: colorDepth = RDConnection.ColorDepths.TrueColor24; break; case 4: colorDepth = RDConnection.ColorDepths.TrueColor32; break; } connection.ColorDepth = colorDepth; connection.Console = chkConsole.Checked; connection.RemoteAudio = (RDConnection.RemoteAudioConfiguration)cboRemoteAudio.SelectedIndex; connection.Printers = chkPrinters.Checked; connection.Clipboard = chkClipboard.Checked; connection.Drives = chkDrives.Checked; connection.AlternateShell = txtAlternateShell.Text; connection.ShellWorkingDirectory = txtShellWorkingDirectory.Text; connection.DisplayMode = cboDisplayMode.SelectedIndex == 0 ? RDConnection.DisplayModes.Fullscreen : RDConnection.DisplayModes.Tabbed; connection.DisplayConnectionBar = chkDisplayConnectionBar.Checked; connection.PerformancePreset = (RDConnection.PerformancePresets)cboPerformance.SelectedIndex; connection.DesktopBackground = chkDesktopBackground.Checked; connection.FontSmoothing = chkFontSmoothing.Checked; connection.DesktopComposition = chkDesktopComposition.Checked; connection.WindowContents = chkWindowContents.Checked; connection.MenuAnimation = chkMenuAnimation.Checked; connection.VisualStyles = chkVisualStyles.Checked; connection.PersistentBitmapCaching = chkPersistentBitmapCaching.Checked; connection.NLA = chkNla.Checked; } Close(); } private void txtComputer_TextChanged(object sender, EventArgs e) { lblComputerName.Text = computerNameMessage1; chkSaveCredentials.Visible = false; if (!string.IsNullOrEmpty(txtComputer.Text)) { lblComputerName.Text = computerNameMessage2; chkSaveCredentials.Visible = true; } } private void Error(string text) { MessageBox.Show(text, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } private void cboPerformance_SelectedIndexChanged(object sender, EventArgs e) { chkDesktopBackground.Checked = false; chkFontSmoothing.Checked = false; chkDesktopComposition.Checked = false; chkWindowContents.Checked = false; chkMenuAnimation.Checked = false; chkVisualStyles.Checked = false; chkPersistentBitmapCaching.Checked = false; switch (cboPerformance.SelectedIndex) { case 0: chkPersistentBitmapCaching.Checked = true; break; case 1: chkVisualStyles.Checked = true; chkPersistentBitmapCaching.Checked = true; break; case 2: case 3: chkDesktopComposition.Checked = true; chkVisualStyles.Checked = true; chkPersistentBitmapCaching.Checked = true; break; case 4: case 5: chkDesktopBackground.Checked = true; chkFontSmoothing.Checked = true; chkDesktopComposition.Checked = true; chkWindowContents.Checked = true; chkMenuAnimation.Checked = true; chkVisualStyles.Checked = true; chkPersistentBitmapCaching.Checked = true; break; } } private void btnShowPassword_Click(object sender, EventArgs e) { MessageBox.Show(this, txtPassword.Text, "Password", MessageBoxButtons.OK, MessageBoxIcon.Information); } private void chkProgram_CheckedChanged(object sender, EventArgs e) { lblProgramPath.Enabled = chkProgram.Checked; lblProgramFolder.Enabled = chkProgram.Checked; txtAlternateShell.Enabled = chkProgram.Checked; txtShellWorkingDirectory.Enabled = chkProgram.Checked; } } }