protected override void OnPaint(PaintEventArgs e) { // used for double-buffering Graphics offscreen = Graphics.FromImage(_imageBuffer); offscreen.FillRectangle(_nohlightBrush, 0, 0, this.Size.Width, this.Size.Height); int itemSpace = this.Size.Height / NUM_ITEMS_VISIBLE; int textHeight = (int)e.Graphics.MeasureString("Hgllyf!", this.Font).Height; int itemOffset = (itemSpace - textHeight) / 2; int top = itemOffset; for (int i = 0; i < (NUM_ITEMS_VISIBLE - 1); i++) { if ((i + _firstIndex) >= _items.Count) { break; } IPhoneListViewItem item = (IPhoneListViewItem)_items[i + _firstIndex]; item.Width = this.Size.Width; drawItemHelper(offscreen, item.Label, item.Enabled, i, top, itemSpace, itemOffset, item.Font); top += itemSpace; } if (((NUM_ITEMS_VISIBLE) + _firstIndex) < _items.Count) { _moreButtonUsed = true; drawItemHelper(offscreen, MORE_LABEL, true, NUM_ITEMS_VISIBLE - 1, top, itemSpace, itemOffset, this.Font); } else if (((NUM_ITEMS_VISIBLE) + _firstIndex) == _items.Count) { _moreButtonUsed = false; IPhoneListViewItem item = (IPhoneListViewItem)_items[NUM_ITEMS_VISIBLE - 1 + _firstIndex]; item.Width = this.Size.Width; drawItemHelper(offscreen, item.Label, item.Enabled, NUM_ITEMS_VISIBLE - 1, top, itemSpace, itemOffset, item.Font); } e.Graphics.DrawImage(_imageBuffer, 0, 0); if (_activateNow) { _activateNow = false; IPhoneListViewItem item = (IPhoneListViewItem)_items[_firstIndex + _selectedIndex]; item.Activate(); if (ItemActivated != null) { ItemActivated(this, new EventArgs()); } } }
protected void list_keyDown(object source, KeyEventArgs e) { switch (e.KeyCode) { case Keys.Return: if (_selectedIndex == (NUM_ITEMS_VISIBLE - 1) && _moreButtonUsed) { activateMoreButton(); } else { // do something else for other activations IPhoneListViewItem item = (IPhoneListViewItem)_items[_firstIndex + _selectedIndex]; item.Activate(); if (ItemActivated != null) { ItemActivated(this, new EventArgs()); } } break; case Keys.Up: if (_selectedIndex != 0) { changeSelectedIndex(_selectedIndex - 1); this.Invalidate(); e.Handled = true; } break; case Keys.Down: if (_selectedIndex < (NUM_ITEMS_VISIBLE - 1) && (_selectedIndex + _firstIndex) < (_items.Count - 1)) { changeSelectedIndex(_selectedIndex + 1); this.Invalidate(); e.Handled = true; } break; case Keys.D1: changeSelectedIndex(0); _activateNow = true; this.Invalidate(); e.Handled = true; break; case Keys.D2: if ((_firstIndex + 1) >= _items.Count) { break; } changeSelectedIndex(1); _activateNow = true; this.Invalidate(); e.Handled = true; break; case Keys.D3: if ((_firstIndex + 2) >= _items.Count) { break; } changeSelectedIndex(2); _activateNow = true; this.Invalidate(); e.Handled = true; break; case Keys.D4: if ((_firstIndex + 3) >= _items.Count) { break; } changeSelectedIndex(3); _activateNow = true; this.Invalidate(); e.Handled = true; break; case Keys.D5: if ((_firstIndex + 4) >= _items.Count) { break; } changeSelectedIndex(4); _activateNow = true; this.Invalidate(); e.Handled = true; break; case Keys.D6: if ((_firstIndex + 5) >= _items.Count) { break; } changeSelectedIndex(5); _activateNow = true; this.Invalidate(); e.Handled = true; break; case Keys.D7: if ((_firstIndex + 6) >= _items.Count) { break; } changeSelectedIndex(6); _activateNow = true; this.Invalidate(); e.Handled = true; break; case Keys.D8: if ((_firstIndex + 7) >= _items.Count) { break; } changeSelectedIndex(7); _activateNow = true; this.Invalidate(); e.Handled = true; break; case Keys.D9: if ((_firstIndex + 8) >= _items.Count) { break; } changeSelectedIndex(8); if (_moreButtonUsed) { activateMoreButton(); } else { _activateNow = true; } this.Invalidate(); e.Handled = true; break; /* * default: * MessageBox.Show( "Code: " + e.KeyCode.ToString() ); * e.Handled = true; * break; */ } }