Esempio n. 1
0
        private void OnBtnColor(object sender, EventArgs e)
        {
            // Color? clr = UIUtil.ShowColorDialog(m_clr);
            // if(clr.HasValue)
            // {
            //	float h, s, v;
            //	UIUtil.ColorToHsv(clr.Value, out h, out s, out v);
            //	m_clr = UIUtil.ColorFromHsv(h, 1.0f, 1.0f);
            //	UIUtil.SetButtonImage(m_btnColor, PwEntryForm.CreateColorButtonImage(
            //		m_btnColor, m_clr), false);
            // }

            if (m_ctxColor == null)
            {
                m_ctxColor = new ContextMenu();

                int qSize = (int)((20.0f * m_btnColor.Height) / 23.0f + 0.01f);

                const int nMaxColors = 64;
                int       nBreakAt   = (int)Math.Sqrt(0.1 + nMaxColors);

                // m_ctxColor.LayoutStyle = ToolStripLayoutStyle.Flow;
                // FlowLayoutSettings fls = (m_ctxColor.LayoutSettings as FlowLayoutSettings);
                // if(fls == null) { Debug.Assert(false); return; }
                // fls.FlowDirection = FlowDirection.LeftToRight;

                // m_ctxColor.LayoutStyle = ToolStripLayoutStyle.Table;
                // TableLayoutSettings tls = (m_ctxColor.LayoutSettings as TableLayoutSettings);
                // if(tls == null) { Debug.Assert(false); return; }
                // tls.ColumnCount = nBreakAt;
                // tls.RowCount = nBreakAt;

                // m_ctxColor.SuspendLayout();

                for (int i = 0; i < nMaxColors; ++i)
                {
                    float fHue = ((float)i * 360.0f) / (float)nMaxColors;
                    Color clr  = UIUtil.ColorFromHsv(fHue, 1.0f, 1.0f);

                    // Image img = UIUtil.CreateColorBitmap24(16, 16, clr);
                    // ToolStripButton btn = new ToolStripButton(string.Empty, img);
                    // btn.DisplayStyle = ToolStripItemDisplayStyle.Image;
                    // btn.ImageAlign = ContentAlignment.MiddleCenter;
                    // btn.AutoSize = true;

                    ColorMenuItem mi = new ColorMenuItem(clr, qSize);

                    if ((i > 0) && ((i % nBreakAt) == 0))
                    {
                        mi.Break = true;
                    }
                    //	fls.SetFlowBreak(btn, true);

                    mi.Click += this.HandleColorButtonClicked;

                    // m_ctxColor.Items.Add(btn);
                    m_vColorItems.Add(mi);
                }

                m_ctxColor.MenuItems.AddRange(m_vColorItems.ToArray());

                // m_ctxColor.ResumeLayout(true);
                // this.Controls.Add(m_ctxColor);
                // m_ctxColor.BringToFront();
            }

            // m_ctxColor.Show(m_btnColor, new Point(0, m_btnColor.Height));
            // m_ctxColor.Location = new Point(m_btnColor.Location.X,
            //	m_btnColor.Location.Y - m_btnColor.Height - m_ctxColor.Height);
            // m_ctxColor.Visible = true;
            // m_ctxColor.Show();

            m_ctxColor.Show(m_btnColor, new Point(0, m_btnColor.Height));
        }