Exemple #1
0
        protected override void OnClick(EventArgs e)
        {
            base.OnClick(e);
            Focus();
            var me       = e as MouseEventArgs;
            var localPos = me.Location;

            for (var i = 0; i < _planetSprites.Count; i++)
            {
                var sprite = _planetSprites[i];
                var rect   = new Rectangle(sprite.DrawLocation, sprite.SourceRect.Size);
                if (rect.Contains(localPos))
                {
                    SelectedPlanetIndex = i;
                    PlanetClicked?.Invoke(this, EventArgs.Empty);
                    return;
                }
            }
        }
Exemple #2
0
        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            switch (keyData)
            {
            case Keys.Left:
                SelectedPlanetIndex -= 1;
                if (SelectedPlanetIndex < 0)
                {
                    SelectedPlanetIndex = _planetSprites.Count - 1;
                }
                PlanetClicked?.Invoke(this, EventArgs.Empty);
                return(true);

            case Keys.Right:
                SelectedPlanetIndex += 1;
                if (SelectedPlanetIndex >= _planetSprites.Count)
                {
                    SelectedPlanetIndex = 0;
                }
                PlanetClicked?.Invoke(this, EventArgs.Empty);
                return(true);
            }
            return(base.ProcessCmdKey(ref msg, keyData));
        }