Пример #1
0
        private void OnTimerTick(object sender, EventArgs e)
        {
            if (_index == HCylLayouts.Count)
            {
                timer.Stop();
                if (Controls.Count > 0)
                {
                    var            bt     = Controls[0] as Button;
                    HCylLayoutItem btItem = bt.Tag as HCylLayoutItem;
                    btItem.Selected = true;
                    OnLayoutSelected(bt, null);
                }
                RefreshFinished?.Invoke(this, null);
                return;
            }
            bool selected = (0 == Controls.Count) ? FirstLayoutSelected : false;
            var  layout   = HCylLayouts[_index];

            // create pattern and add to panel
            var btn = new Button
            {
                Image    = TryGeneratePatternImage(HCylLayouts[_index], szButtons, selected),
                Location = new Point(_x, _y) + (Size)AutoScrollPosition,
                Size     = new Size(szButtons.Width, szButtons.Height),
                Tag      = new HCylLayoutItem(layout, selected)
            };

            btn.Click += OnLayoutSelected;
            Controls.Add(btn);
            // give button a tooltip
            tooltip.SetToolTip(btn, layout.Tooltip);
            // adjust i, x and y for next image
            AdjustXY(ref _x, ref _y);
            ++_index;
        }
Пример #2
0
        private void OnLayoutSelected(object sender, EventArgs e)
        {
            Button bnSender = sender as Button;

            foreach (var ctrl in Controls)
            {
                if (ctrl is Button bt && bt != bnSender)
                {
                    if (bt.Tag is HCylLayoutItem btItem && btItem.Selected)
                    {
                        btItem.Selected = false;
                        bt.Image        = TryGeneratePatternImage(btItem.Layout, szButtons, btItem.Selected);
                    }
                }
            }
            // ***
            HCylLayoutItem lItem    = bnSender.Tag as HCylLayoutItem;
            bool           selected = true;

            bnSender.Image = TryGeneratePatternImage(lItem.Layout, szButtons, selected);
            bnSender.Tag   = new HCylLayoutItem(lItem.Layout, selected);
            LayoutSelected?.Invoke(this, e);
        }