示例#1
0
        //assumption: sender is either radio button or label with named tag pointing to corresponding button
        private void buttonClick(object sender, EventArgs e)
        {
            if (sender == null)
            {
                return;              //safeguard
            }
            RadioButtonElement rbt = sender as RadioButtonElement;

            if (rbt == null) //it is a text label, not button
            {
                rbt = (sender as TextLabelElement).Tags[BUTTON_TAG] as RadioButtonElement;
            }


            rbt.Checked = !rbt.Checked;

            if (rbt.Checked)
            {
                foreach (RadioButtonElement other in m_RadioList)
                {
                    if (other != rbt)
                    {
                        other.Checked = false;
                    }
                }

                m_CheckedElement = rbt;
            }
            else
            {
                m_CheckedElement = null;
            }

            OnCheckedChanged(EventArgs.Empty);
        }
示例#2
0
        /// <summary>
        /// Tries to find a button with specified key and checks it. Returns true if button could be found
        /// </summary>
        public bool CheckButtonWithKey(object key)
        {
            m_CheckedElement = null;

            foreach (RadioButtonElement other in m_RadioList)
            {
                other.Checked = false;
            }

            foreach (RadioButtonElement rbt in m_RadioList)
            {
                if (equal(rbt.Key, key))
                {
                    rbt.Checked      = true;
                    m_CheckedElement = rbt;

                    OnCheckedChanged(EventArgs.Empty);

                    return(true);
                }
            }

            OnCheckedChanged(EventArgs.Empty);
            return(false);
        }
示例#3
0
         private void deleteAllButtons()
         {
           m_CheckedElement = null;

           foreach (RadioButtonElement rbt in m_RadioList)
             rbt.Dispose();

           m_RadioList.Clear();
         }
示例#4
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();
               }
        }
示例#5
0
        private void deleteAllButtons()
        {
            m_CheckedElement = null;

               foreach (RadioButtonElement rbt in m_RadioList)
             rbt.Dispose();

               m_RadioList.Clear();
        }
示例#6
0
        //assumption: sender is either radio button or label with named tag pointing to corresponding button
        private void buttonClick(object sender, EventArgs e)
        {
            if (sender==null) return; //safeguard

               RadioButtonElement rbt = sender as RadioButtonElement;

               if (rbt==null) //it is a text label, not button
               {
             rbt = (sender as TextLabelElement).Tags[BUTTON_TAG] as RadioButtonElement;
               }

               rbt.Checked = !rbt.Checked;

               if (rbt.Checked)
               {
             foreach (RadioButtonElement other in m_RadioList)
                if (other!=rbt) other.Checked = false;

             m_CheckedElement = rbt;
               }
               else
             m_CheckedElement = null;

               OnCheckedChanged(EventArgs.Empty);
        }
示例#7
0
        /// <summary>
        /// Tries to find a button with specified key and checks it. Returns true if button could be found
        /// </summary>
        public bool CheckButtonWithKey(object key)
        {
            m_CheckedElement = null;

             foreach (RadioButtonElement other in m_RadioList)
               other.Checked = false;

             foreach (RadioButtonElement rbt in m_RadioList)
               if (equal(rbt.Key, key))
               {
             rbt.Checked = true;
             m_CheckedElement = rbt;

             OnCheckedChanged(EventArgs.Empty);

             return true;
               }

             OnCheckedChanged(EventArgs.Empty);
             return false;
        }
示例#8
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();
            }
        }