protected override void OnDrawItem(DrawItemEventArgs e) { CustomListItem item = (e.Index < 0 || this.DesignMode ? null : Items[e.Index] as CustomListItem); //bool draw = imageList != null && (item != null); if (item != null) { CheckHorizontalScroll(e.Graphics, customBoldFont); e.DrawBackground(); base.OnDrawItem(e); Size imageSize = item.Pic.Size; if (this.ItemHeight != imageSize.Height + 2) { this.ItemHeight = imageSize.Height + 4; } Rectangle bounds = e.Bounds; Color color = Color.Black; SolidBrush brush; if (item.Index == this.SelectedIndex) { brush = new SolidBrush(Color.LightSteelBlue); } else { brush = new SolidBrush(Color.LightBlue); } Pen pen = new Pen(Color.White); e.Graphics.DrawRectangle(pen, bounds.Left, bounds.Top, bounds.Width, bounds.Height); e.Graphics.FillRectangle(brush, bounds.Left + 1, bounds.Top + 1, bounds.Width - 1, bounds.Height - 1); if (item.Pic.Image != null) { e.Graphics.DrawImage(item.Pic.Image, new Rectangle(bounds.Left + 2, bounds.Top + 2, item.Pic.Width, item.Pic.Height + 1)); } int textCount = 0; foreach (String s in item.textList) { Rectangle itemBound = new Rectangle(bounds.Left, this.ItemHeight * textCount, bounds.Width, this.ItemHeight * textCount + this.ItemHeight); e.Graphics.DrawString(s, (textCount == 0 ? customBoldFont : customRegularFont), new SolidBrush(color), item.Pic.Width + 5, bounds.Top + 5 + textCount * (e.Font.Size + 6)); textCount++; } } }
private void AddItemToListBox(Control lst, int index, string name, string inlayURL, string pub, string type, string year, string language, string score) { if (lst.InvokeRequired) { AddItemToListBoxCallback d = new AddItemToListBoxCallback(AddItemToListBox); lst.Invoke(d, new object[] { lst, index, name, inlayURL, pub, type, year, language, score }); } else { CustomListbox cbox = (CustomListbox)lst; CustomListItem citem = new CustomListItem(name); citem.Index = index; citem.AddText(pub + (year != "" ? ", " + year : "")); citem.AddText(type); citem.AddText("Language: " + language); citem.AddText("Score: " + score); if (inlayURL != "") { citem.SetPicture(inlayURL); } citem.SetImageChangedHandler(cbox.UpdateImageOnChange); cbox.Items.Add(citem); infoListBox.TopIndex = 20 * (infoListBox.Items.Count / 20); infoListBox.SelectedIndex = infoListBox.TopIndex; if (!infoListBox.Visible) { infoListBox.Visible = true; } if (!detailsButton.Visible) { detailsButton.Show(); } if (!moreButton.Visible && (currentResultPage < totalResultPages)) { moreButton.Show(); } } }