Exemplo n.º 1
0
        /// <summary>
        /// 替换控件集合中的特定控件
        /// </summary>
        /// <param name="controls"></param>
        /// <param name="target">要替换掉的目标控件</param>
        /// <param name="replace">要替换目标控件的源控件</param>
        public static void ReplaceControl(this Control.ControlCollection controls, Control target, Control replace)
        {
            if (null == controls || controls.Count <= 0 || null == target || null == replace)
            {
                return;
            }

            List <Control> allCtrls = new List <Control>();

            //从后往前删除控件
            for (int i = controls.Count - 1; i >= 0; --i)
            {
                var ctrl = controls[i];
                if (ctrl == target)
                {
                    allCtrls.Add(replace);
                }
                else
                {
                    allCtrls.Add(ctrl);
                }

                controls.RemoveAt(i);
            }

            //从后往前添加控件
            for (int i = allCtrls.Count - 1; i >= 0; --i)
            {
                controls.Add(allCtrls[i]);
            }
        }
Exemplo n.º 2
0
 private void button2_Click(object sender, EventArgs e)
 {
     if (listBox1.SelectedIndex >= 0)
     {
         Control.ControlCollection cC = panel1.Controls;
         while (cC.Count != 0)
         {
             cC.RemoveAt(0);
         }
         MessageBoxButtons buttons = MessageBoxButtons.YesNo;
         if (MessageBox.Show(this, "Вы уверены?", "Удаление контакта", buttons) == DialogResult.Yes)
         {
             string name = listBox1.SelectedItem.ToString();
             listBox1.Items.RemoveAt(listBox1.SelectedIndex); //удаление из ListBox
             for (int i = 0; i < Dialogs.Count; i++)          //удаление диалога
             {
                 if (Dialogs[i].companionName == name)
                 {
                     Dialogs.RemoveAt(i);
                     break;
                 }
             }
             for (int i = 0; i < Contacts.Count; i++)//удаление контакта
             {
                 if (Contacts[i].name == name)
                 {
                     Contacts.RemoveAt(i);
                     break;
                 }
             }
             Labels.Clear();
         }
         countOfLabels = 0;
     }
 }
Exemplo n.º 3
0
        private void listBox1_Click(object sender, EventArgs e)
        {
            if (listBox1.SelectedIndex >= 0)
            {
                Labels.Clear();
                Control.ControlCollection cC = panel1.Controls;
                while (cC.Count != 0)
                {
                    cC.RemoveAt(0);
                }

                string name = ((ListBox)sender).SelectedItem.ToString();
                label1.Text = name;
                int index;

                for (index = 0; index < Dialogs.Count; index++)
                {
                    if (name == Dialogs[index].companionName)
                    {
                        break;
                    }
                }

                for (countOfLabels = 0; countOfLabels < Dialogs[index].msgs.Count; countOfLabels++)
                {
                    Labels.Add(new Label());

                    Labels[countOfLabels].Text        = string.Format("{0} - {1:H:mm:ss}", Dialogs[index].msgs[countOfLabels].msg, Dialogs[index].msgs[countOfLabels].dt);
                    Labels[countOfLabels].AutoSize    = true;
                    Labels[countOfLabels].BorderStyle = BorderStyle.FixedSingle;
                    Labels[countOfLabels].MaximumSize = new System.Drawing.Size(150, 0);
                    if (countOfLabels != 0)
                    {
                        if (Dialogs[index].msgs[countOfLabels].isAdmMsg)
                        {
                            Labels[countOfLabels].Location = new System.Drawing.Point(173, Labels[countOfLabels - 1].Bottom + 5);
                        }
                        else
                        {
                            Labels[countOfLabels].Location = new System.Drawing.Point(3, Labels[countOfLabels - 1].Bottom + 5);
                        }
                    }
                    else
                    {
                        if (Dialogs[index].msgs[countOfLabels].isAdmMsg)
                        {
                            Labels[countOfLabels].Location = new System.Drawing.Point(173, 3);
                        }
                        else
                        {
                            Labels[countOfLabels].Location = new System.Drawing.Point(3, 3);
                        }
                    }

                    panel1.Controls.Add(Labels[countOfLabels]);
                }
            }
        }
        public static Control RemoveLast(this Control.ControlCollection collection)
        {
            Control result        = null;
            var     lastItemIndex = collection.Count - 1;

            if (lastItemIndex >= 0)
            {
                result = collection[lastItemIndex];
                collection.RemoveAt(lastItemIndex);
            }
            return(result);
        }
Exemplo n.º 5
0
 //---------------------------------------------------------------------
 private static void _RemoveControlsButShowedControl(Control.ControlCollection controls, Control showedControl)
 {
     for (var i = 0; i < controls.Count; i++)
     {
         var tmpControl = controls[i];
         if (!ReferenceEquals(tmpControl, showedControl))
         {
             controls.RemoveAt(i);
             i--;
         }
     }
 }
Exemplo n.º 6
0
 /// <summary>
 /// Clear a Control Collection with optional Dispose
 /// </summary>
 /// <param name="controls">The ControlCollection</param>
 /// <param name="dispose">Set true to call dispose for each item</param>
 public static void Clear(this Control.ControlCollection controls, bool dispose)
 {
     for (int ix = controls.Count - 1; ix >= 0; --ix)
     {
         var tmpObj = controls[ix];
         controls.RemoveAt(ix);
         if (dispose && !tmpObj.IsDisposed)
         {
             tmpObj.Dispose( );
         }
     }
 }
Exemplo n.º 7
0
 private void HighlightAndRemove(Control.ControlCollection controls, int index)
 {
     this.InvokeEx(new Action(() =>
     {
         controls[index].BackColor = Color.Red;
         Refresh();
     }));
     Thread.Sleep(200);
     this.InvokeEx(new Action(() =>
     {
         controls.RemoveAt(index);
     }));
 }
Exemplo n.º 8
0
 public static void Clear(this Control.ControlCollection controls, bool dispose)
 {
     for (int ix = controls.Count - 1; ix >= 0; --ix)
     {
         if (dispose)
         {
             controls[ix].Dispose();
         }
         else
         {
             controls.RemoveAt(ix);
         }
     }
 }
Exemplo n.º 9
0
        private static void ClearControlCollection(Control.ControlCollection controls)
        {
            if (controls == null)
            {
                return;
            }

            for (int i = controls.Count - 1; i >= 0; i--)
            {
                var control = controls[i];
                controls.RemoveAt(i);
                control.Dispose();
            }
        }
Exemplo n.º 10
0
 private void Move2(Control.ControlCollection source, Control.ControlCollection target, bool enabled)
 {
     while (source.Count != 0)
     {
         Control ctr = source[0];
         if (ctr is Panel)
         {
             if (!ctr.Enabled)
             {
                 source.RemoveAt(0);
                 continue;
             }
         }
         target.Add(ctr);
         ctr.Visible = true;
         ctr.Enabled = enabled;
     }
 }
Exemplo n.º 11
0
        public void setupControls(int intNum)
        {
            Control.ControlCollection objCntrls = this.Frame05.Controls;
            Control cntrl;

            RadioButton objOpt = null;

            for (int i = objCntrls.Count - 1; i > -1; i--)
            {
                cntrl = objCntrls[i];
                if (cntrl.Name.Contains("optBTN"))
                {
                    objCntrls.RemoveAt(i);
                }
            }

            for (int i = 1; i < intNum + 1; i++)
            {
                try
                {
                    objOpt      = new RadioButton();
                    objOpt.Name = "optBTN" + i;

                    cntrl        = objOpt;
                    cntrl.Left   = 3 + (i - 1) * 51;
                    cntrl.Top    = 6;
                    cntrl.Width  = 54;
                    cntrl.Height = 24;
                    cntrl.Text   = "BLDG " + intNum;

                    objCntrls.Add(cntrl);
                }
                catch (System.Exception)
                {
                }
            }

            objCntrls = this.Frame08.Controls;

            for (int i = objCntrls.Count - 1; i >= 0; i--)
            {
                objCntrls.RemoveAt(i);
            }

            Button objCMD = null;

            for (int i = 1; i <= intNum; i++)
            {
                objCMD       = new Button();
                objCMD.Name  = "GRID" + i;
                objCMD.Image = System.Drawing.Image.FromFile("R:\\TSET\\VBA\\Q.bmp");
                objCMD.Text  = "BLDG " + intNum;

                cntrl        = objCMD;
                cntrl.Left   = 6 + (i - 1) * 48;
                cntrl.Top    = 9;
                cntrl.Height = 42;
                cntrl.Width  = 42;
                objCntrls.Add(cntrl);
            }

            objCntrls = this.Frame10.Controls;

            for (int i = objCntrls.Count - 1; i >= 0; i += -1)
            {
                objCntrls.RemoveAt(i);
            }

            for (int i = 1; i <= intNum; i++)
            {
                objCMD      = new Button();
                objCMD.Name = "cmd" + i;

                cntrl         = objCMD;
                cntrl.Text    = "BLDG " + intNum;
                cntrl.Enabled = false;

                cntrl.Left   = 12 + (i - 1) * 48;
                cntrl.Top    = 6;
                cntrl.Height = 24;
                cntrl.Width  = 42;
                objCntrls.Add(cntrl);
            }
        }
Exemplo n.º 12
0
 /// <summary>
 /// Removes the XPanderPanel at the specified index from the collection.
 /// </summary>
 /// <param name="index">The zero-based index of the xpanderPanel to remove from the ControlCollection instance.</param>
 public void RemoveAt(int index)
 {
     m_controlCollection.RemoveAt(index);
 }