Example #1
0
        private void rebuild()
        {
            object wasCheckedKey = null;

               if (m_CheckedElement!=null)
             wasCheckedKey = m_CheckedElement.Key;

               m_CheckedElement = null;

               deleteAllButtons();

               if (m_Items.Count==0) return;

               int fh = Host.CurrentFontHeight;

               int clientHeight = Region.Height - Padding.Vertical;
               int rowHeight = fh + m_ButtonVSpacing;
               int rowCount = clientHeight / rowHeight;

               //see if last row fits without trailing spacing
               if ((clientHeight-(rowCount*rowHeight))>=fh) rowCount++;

               if (rowCount<1)
            rowCount =1;

               int colCount = (int)(m_Items.Count / rowCount) + (((m_Items.Count % rowCount)>0)? 1 : 0);

               int colWidth = (int)((Region.Width- Padding.Horizontal) / colCount);

               RadioButtonElement btn;
               TextLabelElement lbl;

               int x = Region.Left+m_Padding.Left;

               IDictionaryEnumerator enm = m_Items.GetEnumerator();

               try
               {
             for (int col = 1; col <= colCount; col++)
             {

               int y = Region.Top + m_Padding.Top;
               for (int row = 1; row <= rowCount; row++)
               {
                  if (!enm.MoveNext()) return;
                  m_RadioList.Add(btn = new RadioButtonElement(Host));
                  btn.Region = new Rectangle(x, y, fh, fh);
                  btn.ZOrder = ZOrder + 1;
                  btn.MouseClick += buttonClick;
                  btn.Key = enm.Key;
                  btn.OwnedElements.Add(lbl = new TextLabelElement(Host));

                  if (wasCheckedKey!=null)
                     if (enm.Key==wasCheckedKey)
                     {
                       btn.Checked = true;
                       m_CheckedElement = btn;
                     }

                  lbl.Region = new Rectangle(x + fh, y, colWidth - fh, fh);
                  lbl.ZOrder = btn.ZOrder;
                  lbl.Text = (enm.Value != null)? " "+enm.Value.ToString() : string.Empty;
                  lbl.MouseClick += buttonClick;
                  lbl.Tags[BUTTON_TAG] = btn;

                  y += fh + m_ButtonVSpacing;
               }
               x+= colWidth;
             }
               }
               finally
               {
              FieldControlContextChanged();
               }
        }
Example #2
0
        private void rebuild()
        {
            object wasCheckedKey = null;

            if (m_CheckedElement != null)
            {
                wasCheckedKey = m_CheckedElement.Key;
            }

            m_CheckedElement = null;

            deleteAllButtons();

            if (m_Items.Count == 0)
            {
                return;
            }

            int fh = Host.CurrentFontHeight;

            int clientHeight = Region.Height - Padding.Vertical;
            int rowHeight    = fh + m_ButtonVSpacing;
            int rowCount     = clientHeight / rowHeight;

            //see if last row fits without trailing spacing
            if ((clientHeight - (rowCount * rowHeight)) >= fh)
            {
                rowCount++;
            }

            if (rowCount < 1)
            {
                rowCount = 1;
            }

            int colCount = (int)(m_Items.Count / rowCount) + (((m_Items.Count % rowCount) > 0)? 1 : 0);

            int colWidth = (int)((Region.Width - Padding.Horizontal) / colCount);

            RadioButtonElement btn;
            TextLabelElement   lbl;

            int x = Region.Left + m_Padding.Left;


            IDictionaryEnumerator enm = m_Items.GetEnumerator();

            try
            {
                for (int col = 1; col <= colCount; col++)
                {
                    int y = Region.Top + m_Padding.Top;
                    for (int row = 1; row <= rowCount; row++)
                    {
                        if (!enm.MoveNext())
                        {
                            return;
                        }
                        m_RadioList.Add(btn       = new RadioButtonElement(Host));
                        btn.Region                = new Rectangle(x, y, fh, fh);
                        btn.ZOrder                = ZOrder + 1;
                        btn.MouseClick           += buttonClick;
                        btn.Key                   = enm.Key;
                        btn.OwnedElements.Add(lbl = new TextLabelElement(Host));

                        if (wasCheckedKey != null)
                        {
                            if (enm.Key == wasCheckedKey)
                            {
                                btn.Checked      = true;
                                m_CheckedElement = btn;
                            }
                        }

                        lbl.Region           = new Rectangle(x + fh, y, colWidth - fh, fh);
                        lbl.ZOrder           = btn.ZOrder;
                        lbl.Text             = (enm.Value != null)? " " + enm.Value.ToString() : string.Empty;
                        lbl.MouseClick      += buttonClick;
                        lbl.Tags[BUTTON_TAG] = btn;

                        y += fh + m_ButtonVSpacing;
                    }
                    x += colWidth;
                }
            }
            finally
            {
                FieldControlContextChanged();
            }
        }