private void InitializeControls() { if (_games != null) { if (_gameCards == null) { _gameCards = new List <FoundedGameCard>(); } this.Clear(); _countItems = 0; foreach (MyAbandonGameFound game in _games) { FoundedGameCard card = new FoundedGameCard(); SetupCard(card); card.GameData = game; card.Tag = _countItems; card.IsSelected = (_countItems == 0); card.Visible = true; this.Controls.Add(card); _gameCards.Add(card); _countItems++; } //As I default the first element to be selected I need to raise the event _currentlySelected = 0; if (GameSelected != null) { GameSelected(this, _gameCards[0].GameData); } //Now checking if it is necessary to add the scrollbar if ((_gameCards.Count * 150) > this.Height) { scroller = new ScrollBarEx(); scroller.BringToFront(); scroller.Orientation = ScrollBarOrientation.Vertical; scroller.BorderColor = Color.FromArgb(64, 64, 64); scroller.Dock = DockStyle.Right; scroller.Visible = true; scroller.Maximum = (_gameCards.Count - 1) * 85; scroller.Scroll += scroller_Scroll; this.MouseWheel += cards_MouseWheel; this.Controls.Add(scroller); } else if (scroller != null) { scroller.Scroll -= scroller_Scroll; scroller.Dispose(); scroller = null; } } }
private void SetupCard(FoundedGameCard card) { card.Width = this.Width - 22; card.Height = 85; card.Top = _countItems * 85; card.MouseEnter += card_MouseEnter; card.FoundedGameCardClick += card_FoundedGameCardClick; card.FoundedGameCardDoubleClick += card_FoundedGameCardDoubleClick; }
void card_FoundedGameCardDoubleClick(object sender) { FoundedGameCard fgc = (FoundedGameCard)sender; if (GameDoubleClick != null) { GameDoubleClick(this, fgc.GameData); } if (Convert.ToInt32(fgc.Tag) != _currentlySelected) { _gameCards[_currentlySelected].IsSelected = false; fgc.IsSelected = true; _currentlySelected = Convert.ToInt32(fgc.Tag); } }
private void InitializeControls() { if (_games != null) { if (_gameCards == null) _gameCards = new List<FoundedGameCard>(); this.Clear(); _countItems = 0; foreach (MyAbandonGameFound game in _games) { FoundedGameCard card = new FoundedGameCard(); SetupCard(card); card.GameData = game; card.Tag = _countItems; card.IsSelected = (_countItems == 0); card.Visible = true; this.Controls.Add(card); _gameCards.Add(card); _countItems++; } //As I default the first element to be selected I need to raise the event _currentlySelected = 0; if (GameSelected!=null) GameSelected(this, _gameCards[0].GameData); //Now checking if it is necessary to add the scrollbar if ((_gameCards.Count * 150) > this.Height) { scroller = new ScrollBarEx(); scroller.BringToFront(); scroller.Orientation = ScrollBarOrientation.Vertical; scroller.BorderColor = Color.FromArgb(64, 64, 64); scroller.Dock = DockStyle.Right; scroller.Visible = true; scroller.Maximum = (_gameCards.Count - 1) * 85; scroller.Scroll += scroller_Scroll; this.MouseWheel += cards_MouseWheel; this.Controls.Add(scroller); } else if (scroller != null) { scroller.Scroll -= scroller_Scroll; scroller.Dispose(); scroller = null; } } }