public Element GetSelected(CoreOperations aw) { Element tmp = null; int s = control.SelectedIndex; if (s == -1) { return(tmp); } TMyListBoxItem t = (TMyListBoxItem)(control.ht[control.Items[s]]); double rand = t.rand; foreach (Element el in aw.list.list) { if (el.rand == rand) { tmp = el; break; } } foreach (Element el in aw.skipped) { if (el.rand == rand) { tmp = el; break; } } return(tmp); }
protected override void OnDrawItem(DrawItemEventArgs e) { // Make sure we're not trying to draw something that isn't there. if (e.Index >= this.Items.Count || e.Index <= -1) { return; } // Get the item object. object item = this.Items[e.Index]; if (item == null) { return; } string key = item.ToString(); TMyListBoxItem tm = (TMyListBoxItem)(ht[key]); if (tm != null) { // MessageBox.Show(tm.name); } else { return; } e.DrawBackground(); switch (tm.state2) { case 0: e.Graphics.FillRectangle(new SolidBrush(Color.Gainsboro), e.Bounds); break; case 1: e.Graphics.FillRectangle(new SolidBrush(Color.White), e.Bounds); if (!tm.was_ever_reviewed) { e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(255, 240, 240)), e.Bounds); } break; } // Draw the background color depending on // if the item is selected or not. //if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) if (tm.selected) { // The item is selected. // We want a blue background color. Rectangle tmp = new Rectangle(); tmp.X = e.Bounds.X; tmp.Y = e.Bounds.Y; tmp.Width = e.Bounds.Width; tmp.Height = e.Bounds.Height; tmp.Height--; e.Graphics.DrawRectangle(new Pen(Color.Blue), tmp); } // Draw the item. string text = tm.name; SizeF stringSize = e.Graphics.MeasureString(text, this.Font); e.Graphics.DrawString(text, this.Font, new SolidBrush(Color.Black), new PointF(18, e.Bounds.Y + (e.Bounds.Height - stringSize.Height) / 2)); switch (tm.state1) { case 0: e.Graphics.DrawImage(this.rw, new Point(1, e.Bounds.Y + 1)); break; case 1: e.Graphics.DrawImage(this.rb, new Point(1, e.Bounds.Y + 1)); break; case 2: e.Graphics.DrawImage(this.nw, new Point(1, e.Bounds.Y + 1)); break; } base.OnDrawItem(e); }
public void AddAssigned(String key, TMyListBoxItem value) { ht[key] = value; this.Items.Add(key); this.items2_list.Add(value); }
public void UpdateItems(CoreOperations aw, bool check_hash = true) { lock (control) { lock (aw.list.list) { String hash = ""; lock (aw.skipped) { try { //Point p_old = control.AutoScrollOffset; if (control.Visible == false) { return; } // нет смысла if (aw.skipped.Count == 0 && aw.list.Count == 0) { return; } // Сначала проверим, можно ли обойтись без полного обновления control.SuspendLayout(); int wc = aw.list.Count; int s1, s2; if (control.items2_list.Count > 0 && check_hash) { hash = GetHash(aw); if (tmp_hash.Equals(hash)) { return; } } Element tmp; double sel_rand = -1; //if (control.TopIndex > 0) { MessageBox.Show(control.TopIndex + ""); } int top_index = control.TopIndex; String top_rand_s = ""; double top_rand = -1; try { top_rand_s = control.Items[top_index].ToString(); foreach (TMyListBoxItem i in control.items2_list) { if (i.rand_s.Equals(top_rand_s)) { top_rand = i.rand; break; } } } catch { } int new_index = top_index; foreach (TMyListBoxItem e in control.items2_list) { if (e.selected) { sel_rand = e.rand; break; } } int old_sel_id = control.SelectedIndex; control.BeginUpdate(); control.Clear(); for (int a = aw.list.list.Count - 1; a >= 0; a--) { tmp = aw.list.list[a]; if (tmp.skip_me) { continue; } //s1 = -1; s2 = -1; if (tmp.loaded) { s2 = 1; } else { s2 = 0; } if (tmp.reviewed) { s1 = 0; } else if (tmp.rejected) { s1 = 1; } else if (!tmp.showed) { s1 = 2; } else { s1 = 3; } TMyListBoxItem n = new TMyListBoxItem(); n.state1 = s1; n.state2 = s2; n.name = tmp.title; n.pos = a; n.rand = tmp.rand; n.was_ever_reviewed = (tmp.stable_id != -1); n.rand_s = tmp.rand + ""; control.AddAssigned(n.rand_s, n); if (top_rand == n.rand) { new_index = control.Items.Count - 1; } if (tmp.rand == sel_rand) { n.selected = true; } } for (int a = aw.skipped.Count - 1; a >= 0; a--) { if (a < 0) { break; } tmp = aw.skipped.items[a]; if (tmp.skip_me) { continue; } //s1 = -1; s2 = -1; if (tmp.reviewed) { s1 = 0; } else if (tmp.rejected) { s1 = 1; } else if (!tmp.showed) { s1 = 2; } else { s1 = 3; } if (tmp.loaded) { s2 = 1; } else { s2 = 0; } TMyListBoxItem n = new TMyListBoxItem(); n.state1 = s1; n.state2 = s2; n.name = tmp.title; n.pos = a; n.rand = tmp.rand; n.was_ever_reviewed = (tmp.stable_id != -1); n.rand_s = tmp.rand + ""; control.AddAssigned(n.rand_s, n); if (top_rand == n.rand) { new_index = control.Items.Count - 1; } if (tmp.rand == sel_rand) { n.selected = true; } } control.TopIndex = new_index; control.EndUpdate(); // Thread.Sleep(80); control.PerformLayout(); tmp_hash = hash; //control.AutoScrollOffset = new Point(p_old.X, p_old.Y); //if (p_old.Y > 0) { MessageBox.Show(p_old.Y+""); } } catch (InvalidOperationException) { } catch (Exception e) { #if DEBUG MessageBox.Show("Исключение в движке списка: " + e.GetType().ToString() + "|" + e.Message + "|" + e.StackTrace); #endif } } } } }