private void TesterOptions_SelectionChanged(object sender, SelectionChangedEventArgs e) { ComboBoxItem TempBoxItem = new ComboBoxItem(); foreach (var t in Utilities.ReturnTesters()) { TempBoxItem.Content = t.ToString(); if (TesterOptions.SelectedItem.ToString() == TempBoxItem.ToString()) { thisTester = t; break; } } copyTester = thisTester; AutomaticPrivateVehicle.IsChecked = thisTester.hasVehicle(new VehicleParams(Vehicle.PrivateVehicle, GearBox.Automatic)); AutomaticTwoWheelVehicle.IsChecked = thisTester.hasVehicle(new VehicleParams(Vehicle.TwoWheelVehicle, GearBox.Automatic)); AutomaticMediumTruck.IsChecked = thisTester.hasVehicle(new VehicleParams(Vehicle.MediumTruck, GearBox.Automatic)); AutomaticHeavyTruck.IsChecked = thisTester.hasVehicle(new VehicleParams(Vehicle.HeavyTruck, GearBox.Automatic)); ManualPrivateVehicle.IsChecked = thisTester.hasVehicle(new VehicleParams(Vehicle.PrivateVehicle, GearBox.Manual)); ManualTwoWheelVehicle.IsChecked = thisTester.hasVehicle(new VehicleParams(Vehicle.TwoWheelVehicle, GearBox.Manual)); ManualMediumTruck.IsChecked = thisTester.hasVehicle(new VehicleParams(Vehicle.MediumTruck, GearBox.Manual)); ManualHeavyTruck.IsChecked = thisTester.hasVehicle(new VehicleParams(Vehicle.HeavyTruck, GearBox.Manual)); MaxTests.Value = thisTester.MaximumWeeklyTests; YearsOfExperience.Value = thisTester.YearsOfExperience; MaxDistance.Value = thisTester.MaxDistanceFromTest; }
private void traineeOptions_SelectionChanged(object sender, SelectionChangedEventArgs e) { ComboBoxItem TempBoxItem = new ComboBoxItem(); foreach (var t in Utilities.ReturnTrainees()) { TempBoxItem.Content = t.ToString(); if (traineeOptions.SelectedItem.ToString() == TempBoxItem.ToString()) { thisTrainee = t; break; } } if (vehicleOptions.SelectedIndex != -1) { if (thisTrainee.PassedByVehicleParams[vehicleIndex]) { textOutput.Text = "Can Drive!"; textOutput.Background = Brushes.Green; textOutput.Foreground = Brushes.White; } else { textOutput.Text = "Can't Drive!"; textOutput.Background = Brushes.Red; textOutput.Foreground = Brushes.White; } } }
private void Init() { using (DataTable dt = Environment.OPFormsData.OPForms()) using (DataTableReader dr = dt.CreateDataReader()) { int maxWidth = cbOrganizationalForm.DropDownWidth; using (Graphics g = Graphics.FromHwnd(Handle)) { while (dr.Read()) { var id = (int)dr[Environment.OPFormsData.IDField]; string name = dr[Environment.OPFormsData.NameField].ToString(); var item = new ComboBoxItem(id, name); SizeF size = g.MeasureString(item.ToString(), Font); int width = (int)size.Width + 5; if (width <= 500) { maxWidth = Math.Max(maxWidth, width); } cbOrganizationalForm.Items.Add(item); } } cbOrganizationalForm.DropDownWidth = maxWidth; dr.Close(); dr.Dispose(); dt.Dispose(); } gbProject.Enabled = false; }
private void eraseButton_Click(object sender, RoutedEventArgs e) { if (!Utilities.AreYouSureBox("erase this trainee")) { return; } ComboBoxItem TempBoxItem = new ComboBoxItem(); Trainee k = new Trainee(); foreach (var t in Utilities.ReturnTrainees()) { TempBoxItem.Content = t.ToString(); if (traineeOptions.SelectedItem.ToString() == TempBoxItem.ToString()) { k = t; break; } } try { FactoryBL.Instance.EraseTrainee(k); } catch (Exception ex) { Utilities.ErrorBox(ex.Message); } Utilities.InformationBox("You have successfully erased a trainee."); (this.Parent as StackPanel).Children.Add(new TraineeOptions()); (this.Parent as StackPanel).Children.Remove(this); }
private void MeasureComboBoxItems(object sender, System.Windows.Forms.MeasureItemEventArgs e) { try { ComboBox comboBox = (ComboBox)sender; if (e.Index >= 0) { if (e.Index >= comboBox.Items.Count) { return; } ComboBoxItem item = (ComboBoxItem)comboBox.Items[e.Index]; SizeF size = e.Graphics.MeasureString(item.ToString(), s_font); e.ItemWidth = (int)size.Width; if (this.textAreaControl == null) { e.ItemHeight = (int)Math.Max(size.Height, 16); } else { e.ItemHeight = (int)Math.Max(size.Height, CodeEditorControl.AutoListImages.ImageSize.Height); } } } catch (Exception ee) { } }
public void Fill(string _feld, int Id = 0, string WhereClauseFeld = "", ComboBoxItem comboBoxItem = null) { cboAuswahl.Items.Clear(); if (Id > 0) { tuple = ((DbConnector)App.Current.Properties["Connector"]).ReadComboboxItems(_feld.Split('_')[3], _feld.Split('_')[4], Id, WhereClauseFeld); } else { tuple = ((DbConnector)App.Current.Properties["Connector"]).ReadComboboxItems(_feld.Split('_')[3], _feld.Split('_')[4]); } for (int i = 0; i < tuple.Item1.Count(); i++) { ComboBoxItem cbi = new ComboBoxItem(); cbi.Tag = tuple.Item1.ElementAt(i); cbi.Content = tuple.Item2.ElementAt(i); cboAuswahl.Items.Add(cbi); } if (comboBoxItem != null) { int index = 0; foreach (ComboBoxItem item in cboAuswahl.Items) { if (item.ToString().Equals(comboBoxItem.ToString())) { cboAuswahl.SelectedIndex = index; } index++; } } }
/// <summary> /// Handle changes to combo box item selection. /// </summary> /// <param name="e">unused</param> protected override void OnSelectedIndexChanged(EventArgs e) { // Respond to selection changes, as long as they aren't updates. if (_updating == 0) { if (base.DropDownStyle != ComboBoxStyle.DropDownList && _modified) { _dynModified.OnSet(); _modified = false; } ComboBoxItem item = (ComboBoxItem)base.SelectedItem; if (SetSelectedItem != null) { SetSelectedItem(item == null ? null : item.Tag); } else { _dynSelectedItem.OnSet(); _selectedIndex = base.SelectedIndex; } if (base.DropDownStyle != ComboBoxStyle.DropDownList && SetText != null) { CallSetText(item == null ? "" : item.ToString()); } } base.OnSelectedIndexChanged(e); }
private void EraseButton_Click(object sender, RoutedEventArgs e) { if (!Utilities.AreYouSureBox("erase this tester, even though any tests they are signed up to will be erased")) { return; } ComboBoxItem TempBoxItem = new ComboBoxItem(); Tester k = new Tester(); foreach (var t in Utilities.ReturnTesters()) { TempBoxItem.Content = t.ToString(); if (TesterOptions.SelectedItem.ToString() == TempBoxItem.ToString()) { k = t; break; } } try { FactoryBL.Instance.EraseTester(k); } catch (Exception ex) { Utilities.ErrorBox(ex.Message); } Utilities.InformationBox("You have successfully erased a tester"); (this.Parent as StackPanel).Children.Add(new TesterOptions()); (this.Parent as StackPanel).Children.Remove(this); }
private void ComboBox_Selected(object sender, SelectionChangedEventArgs e) { Page2 p2 = new Page2(); String cinema = Cinemas.SelectedItem.ToString(); // p2.ForCinemaName.Content = cinema; ComboBox comboBox = (ComboBox)sender; try { ComboBoxItem selectedItem = (ComboBoxItem)comboBox.SelectedItem; p2.ForCinemaName.Content = selectedItem.ToString(); MessageBox.Show(selectedItem.ToString()); } catch { MessageBox.Show("Something wrong"); } }
private void ComboBoxDrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e) { try { ComboBox comboBox = (ComboBox)sender; e.DrawBackground(); if (this.textAreaControl == null) { return; } if (e.Index >= 0) { if (comboBox.Items.Count <= e.Index) { return; } ComboBoxItem item = (ComboBoxItem)comboBox.Items[e.Index]; if ((this.textAreaControl.AutoListIcons.Images.Count <= item.IconIndex)) { return; } e.Graphics.DrawImageUnscaled(this.textAreaControl.AutoListIcons.Images[item.imagekey /*item.IconIndex*/], new Point(e.Bounds.X, e.Bounds.Y + (e.Bounds.Height - this.textAreaControl.AutoListIcons.ImageSize.Height) / 2)); Rectangle drawingRect = new Rectangle(e.Bounds.X + this.textAreaControl.AutoListIcons.ImageSize.Width, e.Bounds.Y, e.Bounds.Width - this.textAreaControl.AutoListIcons.ImageSize.Width, e.Bounds.Height); Brush drawItemBrush = SystemBrushes.WindowText; if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) { // drawItemBrush = SystemBrushes.HighlightText; } if (!item.IsInCurrentPart) { drawItemBrush = SystemBrushes.ControlDark; } else if (e.State == DrawItemState.ComboBoxEdit && !item.IsInside(textAreaControl.ActiveViewControl.Caret.Position.Y)) { drawItemBrush = SystemBrushes.ControlDark; } e.Graphics.DrawString(item.ToString(), s_font, drawItemBrush, drawingRect, s_drawStringFormat); } //e.DrawFocusRectangle(); } catch (Exception ee) { } }
void MeasureComboBoxItem(object sender, System.Windows.Forms.MeasureItemEventArgs e) { ComboBox comboBox = (ComboBox)sender; if (e.Index >= 0) { ComboBoxItem item = (ComboBoxItem)comboBox.Items[e.Index]; SizeF size = e.Graphics.MeasureString(item.ToString(), font); e.ItemWidth = (int)size.Width; e.ItemHeight = (int)Math.Max(size.Height, CodeCompletionProvider.ImagesProvider.ImageList.ImageSize.Height); } }
private void Button_Click(object sender, RoutedEventArgs e) { int cnt = 0; foreach (ComboBox c in Interfaces.Children) { ComboBoxItem ci = c.SelectedItem as ComboBoxItem; if (ci != null && ci.ToString() != "") { cnt++; } } if (cnt >= 2) { GameState.GSInstance.Initialise(cnt); int P = 0; Game g = new Game(); // Controller foreach (ComboBox c in Interfaces.Children) { ComboBoxItem ci = c.SelectedItem as ComboBoxItem; if (ci == null) { continue; } if (ci.Content.ToString() == "Desktop") { DesktopWindow dw = new DesktopWindow(P, g); dw.Show(); P++; } else if (ci.Content.ToString() == "Text") { TextWindow tw = new TextWindow(P, g); tw.Show(); P++; } else if (ci.Content.ToString() == "Mobile") { MobileWindow mw = new MobileWindow(P, g); mw.Show(); P++; } } this.Close(); } else { MessageBox.Show("You need more friends to start Scrabble!!!", "Find friends!"); } }
private void testOptions_SelectionChanged(object sender, SelectionChangedEventArgs e) { ComboBoxItem TempBoxItem = new ComboBoxItem(); foreach (var t in Utilities.ReturnTests()) { TempBoxItem.Content = t.ToString(); if (testOptions.SelectedItem.ToString() == TempBoxItem.ToString()) { thisTest = t; break; } } }
private void traineeOptions_SelectionChanged(object sender, SelectionChangedEventArgs e) { ComboBoxItem TempBoxItem = new ComboBoxItem(); foreach (var t in Utilities.ReturnTrainees()) { TempBoxItem.Content = t.ToString(); if (traineeOptions.SelectedItem.ToString() == TempBoxItem.ToString()) { thisTrainee = t; break; } } thisTest = Utilities.ReturnTests().Find(t => t.TraineeId == thisTrainee.IDNumber); }
private void Search_CB_SelectionChanged(object sender, SelectionChangedEventArgs e) { ComboBoxItem currentItem = ((System.Windows.Controls.ComboBoxItem)search_CB.SelectedItem); string text = currentItem.ToString(); String t = search_CB.SelectedItem.ToString(); if (currentItem.Content.Equals("Date")) { searchByDateControls_GR.Visibility = Visibility.Visible; searchByNameControls_GR.Visibility = Visibility.Hidden; } else if (currentItem.Content.Equals("Name")) { searchByDateControls_GR.Visibility = Visibility.Hidden; searchByNameControls_GR.Visibility = Visibility.Visible; } }
void MeasureComboBoxItem(object sender, System.Windows.Forms.MeasureItemEventArgs e) { ComboBox comboBox = (ComboBox)sender; if (e.Index >= 0) { ComboBoxItem item = (ComboBoxItem)comboBox.Items[e.Index]; SizeF size = e.Graphics.MeasureString(item.ToString(), font); e.ItemWidth = (int)size.Width; if (this.textAreaControl == null) { e.ItemHeight = (int)Math.Max(size.Height, 16); } else { e.ItemHeight = (int)Math.Max(size.Height, this.textAreaControl.AutoListIcons.ImageSize.Height); } } }
void ComboBoxDrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e) { ComboBox comboBox = (ComboBox)sender; lock (comboBox) { e.DrawBackground(); if (e.Index >= 0) { ComboBoxItem item = (ComboBoxItem)comboBox.Items[e.Index]; var dx = Convert.ToInt32(Math.Round(2 * ScreenScale.Calc())); e.Graphics.DrawImage(CodeCompletionProvider.ImagesProvider.ImageList.Images[item.IconIndex], e.Bounds.X + dx, e.Bounds.Y, // + (e.Bounds.Height - CodeCompletionProvider.ImagesProvider.ImageList.ImageSize.Height) / 2 e.Bounds.Height, e.Bounds.Height ); Rectangle drawingRect = new Rectangle(e.Bounds.X + dx + e.Bounds.Height /*CodeCompletionProvider.ImagesProvider.ImageList.ImageSize.Width*/, e.Bounds.Y, e.Bounds.Width - dx - e.Bounds.Height /*CodeCompletionProvider.ImagesProvider.ImageList.ImageSize.Width*/, e.Bounds.Height); Brush drawItemBrush = SystemBrushes.WindowText; if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) { drawItemBrush = SystemBrushes.HighlightText; } if (!item.IsInCurrentPart) { drawItemBrush = SystemBrushes.ControlDark; } else if (e.State == DrawItemState.ComboBoxEdit && !item.IsInside(textAreaControl.ActiveTextAreaControl.Caret.Line, textAreaControl.ActiveTextAreaControl.Caret.Column)) { drawItemBrush = SystemBrushes.ControlDark; } e.Graphics.DrawString(item.ToString(), font, drawItemBrush, drawingRect, drawStringFormat); } //e.DrawFocusRectangle(); } }
private void UpdateText() { ++_updating; try { if (base.DropDownStyle == ComboBoxStyle.DropDownList) { // If the control does not allow typing, then the // text of the selected item is it. _dynSelectedItem.OnGet(); if (_selectedIndex >= 0) { // If an item is selected, then it controls the text. ComboBoxItem item = (ComboBoxItem)base.Items[_selectedIndex]; item.ToString(); } } else { // If the control allows typing, then the user and // GetText determine the text. // See if the user is typing. _dynModified.OnGet(); _dynError.OnGet(); if (!_modified && GetText != null && string.IsNullOrEmpty(_errorText)) { // Get the text from the event. base.Text = GetText(); if (base.Focused) { base.SelectAll(); } } } } finally { --_updating; } }
void ComboBoxDrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e) { ComboBox comboBox = (ComboBox)sender; e.DrawBackground(); if (e.Index >= 0) { ComboBoxItem item = (ComboBoxItem)comboBox.Items[e.Index]; e.Graphics.DrawImageUnscaled(ClassBrowserIconService.ImageList.Images[item.IconIndex], new Point(e.Bounds.X, e.Bounds.Y + (e.Bounds.Height - ClassBrowserIconService.ImageList.ImageSize.Height) / 2)); Rectangle drawingRect = new Rectangle(e.Bounds.X + ClassBrowserIconService.ImageList.ImageSize.Width, e.Bounds.Y, e.Bounds.Width - ClassBrowserIconService.ImageList.ImageSize.Width, e.Bounds.Height); Brush drawItemBrush = SystemBrushes.WindowText; if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) { drawItemBrush = SystemBrushes.HighlightText; } if (!item.IsInCurrentPart) { drawItemBrush = SystemBrushes.ControlDark; } else if (e.State == DrawItemState.ComboBoxEdit && !item.IsInside(textAreaControl.ActiveTextAreaControl.Caret.Line)) { drawItemBrush = SystemBrushes.ControlDark; } e.Graphics.DrawString(item.ToString(), font, drawItemBrush, drawingRect, drawStringFormat); } e.DrawFocusRectangle(); }
public void StringTransform() { Assert.AreEqual(text, item.ToString()); }
public string RetriveReview(ComboBoxItem title) { return(title.ToString()); }
/// <summary> /// populate a combo box on the toolbar /// </summary> /// <param name="group">The group that is the basis for this combo box.</param> private void FillCombo(ChoiceGroup group) { UIItemDisplayProperties groupDisplay = group.GetDisplayProperties(); ComboBoxItem combo = group.ReferenceWidget as ComboBoxItem; if (combo.Focused) { return; //don't mess while we're in the combo } // Disable if needed, but still show what's current, as for unicode fields where you can't change it, but you want to see what it is set to. combo.Enabled = groupDisplay.Enabled; ArrayList newItems = new ArrayList(); bool fDifferent = false; ComboItem selectedItem = null; foreach (ChoiceRelatedClass item in group) { if (item is SeparatorChoice) { //TODO } else if (item is ChoiceBase) { UIItemDisplayProperties display = ((ChoiceBase)item).GetDisplayProperties(); ComboItem ci = CreateComboItem((ChoiceBase)item, display); if (ci != null) //will be null if item is supposed to be invisible now { newItems.Add(ci); if (display.Checked) { selectedItem = ci; //nb: if there should be more than one, only the last one will be selected } if (combo.Items.Count < newItems.Count || ((combo.Items[newItems.Count - 1]) as ComboItem).Tag != item) { fDifferent = true; } } } } combo.AccessibleName = group.Label; if (fDifferent || selectedItem.Tag != (combo.SelectedItem as ComboItem).Tag) { combo.SuspendLayout = true; combo.Click -= new EventHandler(OnComboClick); //don't generate clicks (which end up being onpropertychanged() calls) combo.Items.Clear(); combo.Items.AddRange(newItems.ToArray()); combo.SelectedItem = selectedItem; combo.Click += new EventHandler(OnComboClick); combo.SuspendLayout = false; } //Set the ComboWidth of the combo box so that is is wide enough to show //the text of all items in the list. int maxStringLength = 0; for (int i = 0; i < combo.Items.Count; i++) { if (combo.Items[i].ToString().Length > maxStringLength) { maxStringLength = combo.Items[i].ToString().Length; } } int factor = 6; if (maxStringLength > 0 && combo.ComboWidth < maxStringLength * factor) { combo.ComboWidth = maxStringLength * factor; } combo.Tooltip = combo.ToString(); }
private void ShowWeather(object sender, RoutedEventArgs e) { InitializeComponent(); ComboBoxItem item = Days.SelectedItem as ComboBoxItem; string dayStr = item.ToString(); string withoutLetters = Regex.Replace(dayStr, "[A-Za-zА-Яа-я]", "").Replace(".", "").Replace(":", "").Trim(); WebClient client = new WebClient(); var strLocation = (client.DownloadString(@"http://dataservice.accuweather.com/locations/v1/cities/search?apikey=UN1AkqVicgi5pDmT7pfLiAegW2sce9hq&q=" + City.Text + "&language=ru")); var location = JsonConvert.DeserializeObject <List <Location> >(strLocation); var result = client.DownloadString(@"http://dataservice.accuweather.com/forecasts/v1/daily/" + withoutLetters + "day/" + location[0].Key + "?apikey=UN1AkqVicgi5pDmT7pfLiAegW2sce9hq&language=en-us"); var wheather = JsonConvert.DeserializeObject <ForeCast>(result); listBox1.Items.Clear(); for (int i = 0; i < wheather.DailyForecasts.Count; i++) { string workingDirectory = Environment.CurrentDirectory; ListBox mainTextBox = new ListBox() { Width = listBox1.Width / 3, Height = listBox1.Height, Margin = new Thickness(50, 100, 0, 0), Name = "wheather" + i, }; StackPanel stackPanel1 = new StackPanel() { Orientation = Orientation.Horizontal, Width = mainTextBox.Width, Height = mainTextBox.Height / 3 }; StackPanel stackPanel2 = new StackPanel() { Orientation = Orientation.Horizontal, Width = mainTextBox.Width, Height = mainTextBox.Height / 3 }; TextBox textBox1 = new TextBox() { Height = mainTextBox.Height / 3, Width = mainTextBox.Width, TextAlignment = TextAlignment.Center, Text = City.Text + " (" + wheather.DailyForecasts[i].Date + ")\nМинимальная температура: " + wheather.DailyForecasts[i].Temperature.Minimum.Value + "\nМаксимальная температура: " + wheather.DailyForecasts[i].Temperature.Maximum.Value, HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Top }; //")\n\nУтром: " + wheather.DailyForecasts[i].Day.IconPhrase + " число:\n\nНочью: " + wheather.DailyForecasts[i].Night.IconPhrase + "\n\nМинимальная температура воздуха : " + wheather.DailyForecasts[i].Temperature.Minimum.Value + " градусов\n\nМаксимальная температура воздуха: " + wheather.DailyForecasts[i].Temperature.Maximum.Value + " градусов", TextBox textBox2 = new TextBox() { Height = stackPanel1.Height, Width = stackPanel1.Width / 2, TextAlignment = TextAlignment.Center, Text = "Утром: " + wheather.DailyForecasts[i].Day.IconPhrase, HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Top, }; TextBox textBox3 = new TextBox() { Height = stackPanel2.Height, Width = stackPanel2.Width / 2, TextAlignment = TextAlignment.Center, Text = "Ночью: " + wheather.DailyForecasts[i].Night.IconPhrase, HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Top }; Image img = new Image() { Source = new BitmapImage(new Uri(workingDirectory + "/Icons/" + wheather.DailyForecasts[i].Day.Icon + ".png")), Height = stackPanel1.Height, Width = stackPanel1.Width / 2, VerticalAlignment = VerticalAlignment.Top, HorizontalAlignment = HorizontalAlignment.Left, }; Image img2 = new Image() { Source = new BitmapImage(new Uri(workingDirectory + "/Icons/" + wheather.DailyForecasts[i].Night.Icon + ".png")), Height = stackPanel2.Height, Width = stackPanel2.Width / 2, VerticalAlignment = VerticalAlignment.Top, HorizontalAlignment = HorizontalAlignment.Left, }; stackPanel1.Children.Add(textBox2); stackPanel1.Children.Add(img); stackPanel2.Children.Add(textBox3); stackPanel2.Children.Add(img2); mainTextBox.Items.Add(textBox1); mainTextBox.Items.Add(stackPanel1); mainTextBox.Items.Add(stackPanel2); listBox1.Items.Add(mainTextBox); } }
private void EventComboBoxNoPaint_DrawItem(object sender, DrawItemEventArgs e) { ComboBox combo = sender as ComboBox; //e.Graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality; //e.Graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; e.Graphics.FillRectangle(iBrushBackColor, e.Bounds); if (((e.State & DrawItemState.Selected) == DrawItemState.Selected) && (iCurrent != null)) { if (combo.Name == "RoomSelection") { e.Graphics.FillRectangle(iBrushHighlightBackColor, e.Bounds.Left, e.Bounds.Top, e.Bounds.Width, e.Bounds.Height); } else { e.Graphics.FillRectangle(iBrushHighlightBackColor, e.Bounds.Left + kIconWidth, e.Bounds.Top, e.Bounds.Width - kIconWidth, e.Bounds.Height); } } if (e.Index > -1) { string s = string.Empty; Image image = null; try { if (e.Index < Items.Count) { object obj = Items[e.Index]; if (obj is DoubleBufferedComboBox.ComboBoxItem) { DoubleBufferedComboBox.ComboBoxItem item = obj as DoubleBufferedComboBox.ComboBoxItem; s = item.ToString(); if (item.Image != null) { image = item.Image; float width = (float)kIconWidth; float height = (width / item.Image.Width) * item.Image.Height; if (height > e.Bounds.Height) { width = (int)((e.Bounds.Height / (float)height) * width); } e.Graphics.DrawImage(item.Image, e.Bounds.Left + ((kIconWidth - width) * 0.5f), e.Bounds.Top, width, e.Bounds.Height); } } TextFormatFlags flags = TextFormatFlags.VerticalCenter | TextFormatFlags.EndEllipsis; Rectangle rect = new Rectangle((int)(e.Bounds.Left + kIconWidth + 5), e.Bounds.Top, (int)(e.Bounds.Width - kIconWidth - 5), e.Bounds.Height); if (image == null) { rect.X = rect.X - kIconWidth + e.Bounds.Height; rect.Width += kIconWidth; } //e.Graphics.DrawRectangle(new Pen(new SolidBrush(Color.White)), rect); if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) { TextRenderer.DrawText(e.Graphics, s, Font, rect, iHighlightForeColor, flags); } else { TextRenderer.DrawText(e.Graphics, s, Font, rect, ForeColor, flags); } } } catch (ArgumentOutOfRangeException) { Console.WriteLine("ERROR: e.Index= " + e.Index + ", Items.Count=" + Items.Count); } } else { if (iCurrent == null) { string s = ""; if (combo.Name == "RoomSelection") { if (Items.Count == 0) { s = "No rooms found"; } else { s = "Select room"; } } if (combo.Name == "SourceSelection") { if (Items.Count == 0) { s = "No sources found"; } else { s = "Select source"; } } using (Font font = new Font(Font.FontFamily, Font.Size, FontStyle.Bold | FontStyle.Italic)) { TextFormatFlags flags = TextFormatFlags.EndEllipsis | TextFormatFlags.VerticalCenter; Rectangle rect = e.Bounds; rect.Inflate(new Size(-(e.Bounds.Height + 5), 0)); TextRenderer.DrawText(e.Graphics, s, font, rect, iForeColorMuted, flags); } } else { string s = iCurrent.ToString(); if (iCurrent.Image != null) { float width = (float)kIconWidth; float height = (width / iCurrent.Image.Width) * iCurrent.Image.Height; if (height > e.Bounds.Height) { width = (int)((e.Bounds.Height / (float)height) * width); } e.Graphics.DrawImage(iCurrent.Image, e.Bounds.Left + ((kIconWidth - width) * 0.5f), e.Bounds.Top, width, e.Bounds.Height); } TextFormatFlags flags = TextFormatFlags.VerticalCenter | TextFormatFlags.EndEllipsis; Rectangle rect = new Rectangle((int)(e.Bounds.Left + kIconWidth + 5), e.Bounds.Top, (int)(e.Bounds.Width - kIconWidth - 5), e.Bounds.Height); if (iCurrent.Image == null) { rect.X = rect.X - kIconWidth + e.Bounds.Height; rect.Width += kIconWidth; } if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) { TextRenderer.DrawText(e.Graphics, s, Font, rect, iHighlightForeColor, flags); } else { TextRenderer.DrawText(e.Graphics, s, Font, rect, ForeColor, flags); } } } }