private void profileCombobox_DrawItem(object sender, DrawItemEventArgs e) { ComboBox combobox = sender as ComboBox; if (combobox.DroppedDown) { e.DrawBackground(); } e.DrawFocusRectangle(); var items = combobox.Items; if (e.Index < 0) { e.Graphics.DrawString(combobox.Text, e.Font, new SolidBrush(e.ForeColor), e.Bounds.Left, e.Bounds.Y); } else { if (items.Count > 0 && e.Index < items.Count) { ConnectionInfoProfile model = items[e.Index] as ConnectionInfoProfile; e.Graphics.DrawString(model.Description, e.Font, new SolidBrush(combobox.DroppedDown ? e.ForeColor : Color.Black), e.Bounds.Left, e.Bounds.Y); } } }
private void btnConfirm_Click(object sender, EventArgs e) { string profileName = this.txtProfileName.Text.Trim(); this.ConnectionInfo = this.GetConnectionInfo(); if (this.isAdd) { List <ConnectionInfoProfile> profiles = ConnectionInfoProfileManager.GetProfiles(this.DatabaseType); if (!string.IsNullOrEmpty(profileName) && profiles.Any(item => item.Name == profileName)) { DialogResult dialogResult = MessageBox.Show("The profile name is existed, are you sure to override it.", "Confirm", MessageBoxButtons.YesNo); if (dialogResult != DialogResult.Yes) { this.DialogResult = DialogResult.None; return; } } } ConnectionInfoProfile profile = new ConnectionInfoProfile() { Name = profileName, DbType = this.DatabaseType, ConnectionInfo = this.ConnectionInfo, RememberPassword = this.chkRememberPassword.Checked }; this.ProflieName = ConnectionInfoProfileManager.Save(profile); this.DialogResult = DialogResult.OK; }