public ColorPanel(Point pt, ColorButton button) { colorButton = button; FormBorderStyle = FormBorderStyle.FixedDialog; MinimizeBox = false; MaximizeBox = false; ControlBox = false; ShowInTaskbar = false; TopMost = true; SetStyle(ControlStyles.DoubleBuffer, true); SetStyle(ControlStyles.UserPaint, true); SetStyle(ControlStyles.AllPaintingInWmPaint, true); Width = 156; Height = 100; if (colorButton.autoButton != "") { Height += 23; } if (colorButton.moreButton != "") { Height += 23; } CenterToScreen(); Location = pt; Capture = true; }
public static void RestoreForm(Form form, string tablename, bool restore_size) { ArrayList temp = new ArrayList(); // list of all first level controls ControlList(form, ref temp); ArrayList checkbox_list = new ArrayList(); ArrayList combobox_list = new ArrayList(); ArrayList numericupdown_list = new ArrayList(); ArrayList radiobutton_list = new ArrayList(); ArrayList textbox_list = new ArrayList(); ArrayList trackbar_list = new ArrayList(); ArrayList colorbutton_list = new ArrayList(); //ArrayList controls = new ArrayList(); // list of controls to restore foreach (Control c in temp) { if (c.GetType() == typeof(CheckBoxTS)) // the control is a CheckBoxTS { checkbox_list.Add(c); } else if (c.GetType() == typeof(ComboBoxTS)) // the control is a ComboBox { combobox_list.Add(c); } else if (c.GetType() == typeof(NumericUpDownTS)) // the control is a NumericUpDown { numericupdown_list.Add(c); } else if (c.GetType() == typeof(RadioButtonTS)) // the control is a RadioButton { radiobutton_list.Add(c); } else if (c.GetType() == typeof(TextBoxTS)) // the control is a TextBox { textbox_list.Add(c); } else if (c.GetType() == typeof(TrackBarTS)) // the control is a TrackBar (slider) { trackbar_list.Add(c); } else if (c.GetType() == typeof(ColorButton)) { colorbutton_list.Add(c); } } temp.Clear(); // now that we have the controls we want, delete first list ArrayList a = DB.GetVars(tablename); // Get the saved list of controls a.Sort(); // restore saved values to the controls foreach (string s in a) // string is in the format "name,value" { string[] vals = s.Split('/'); if (vals.Length > 2) { for (int i = 2; i < vals.Length; i++) { vals[1] += "/" + vals[i]; } } string name = vals[0]; string val = vals[1]; switch (name) { case "Top": form.StartPosition = FormStartPosition.Manual; int top = int.Parse(val); /*if(top < 0) top = 0; * if(top > Screen.PrimaryScreen.Bounds.Height-form.Height && Screen.AllScreens.Length == 1) * top = Screen.PrimaryScreen.Bounds.Height-form.Height;*/ form.Top = top; break; case "Left": form.StartPosition = FormStartPosition.Manual; int left = int.Parse(val); /*if(left < 0) left = 0; * if(left > Screen.PrimaryScreen.Bounds.Width-form.Width && Screen.AllScreens.Length == 1) * left = Screen.PrimaryScreen.Bounds.Width-form.Width;*/ form.Left = left; break; case "Width": if (restore_size) { int width = int.Parse(val); /*if(width + form.Left > Screen.PrimaryScreen.Bounds.Width && Screen.AllScreens.Length == 1) * form.Left -= (width+form.Left-Screen.PrimaryScreen.Bounds.Width);*/ form.Width = width; } break; case "Height": if (restore_size) { int height = int.Parse(val); /*if(height + form.Top > Screen.PrimaryScreen.Bounds.Height && Screen.AllScreens.Length == 1) * form.Top -= (height+form.Top-Screen.PrimaryScreen.Bounds.Height);*/ form.Height = height; } break; } if (s.StartsWith("chk")) // control is a CheckBoxTS { for (int i = 0; i < checkbox_list.Count; i++) { // look through each control to find the matching name CheckBoxTS c = (CheckBoxTS)checkbox_list[i]; if (c.Name.Equals(name)) // name found { c.Checked = bool.Parse(val); // restore value i = checkbox_list.Count + 1; } if (i == checkbox_list.Count) { MessageBox.Show("Control not found: " + name); } } } else if (s.StartsWith("combo")) // control is a ComboBox { for (int i = 0; i < combobox_list.Count; i++) { // look through each control to find the matching name ComboBoxTS c = (ComboBoxTS)combobox_list[i]; if (c.Name.Equals(name)) // name found { c.Text = val; // restore value i = combobox_list.Count + 1; if (c.Text != val) { Debug.WriteLine("Warning: " + form.Name + "." + name + " did not set to " + val); } } if (i == combobox_list.Count) { MessageBox.Show("Control not found: " + name); } } } else if (s.StartsWith("ud")) { for (int i = 0; i < numericupdown_list.Count; i++) { // look through each control to find the matching name NumericUpDownTS c = (NumericUpDownTS)numericupdown_list[i]; if (c.Name.Equals(name)) // name found { decimal num = decimal.Parse(val); if (num > c.Maximum) { num = c.Maximum; // check endpoints } else if (num < c.Minimum) { num = c.Minimum; } c.Value = num; // restore value i = numericupdown_list.Count + 1; } if (i == numericupdown_list.Count) { MessageBox.Show("Control not found: " + name); } } } else if (s.StartsWith("rad")) { // look through each control to find the matching name for (int i = 0; i < radiobutton_list.Count; i++) { RadioButtonTS c = (RadioButtonTS)radiobutton_list[i]; if (c.Name.Equals(name)) // name found { if (!val.ToLower().Equals("true") && !val.ToLower().Equals("false")) { val = "True"; } c.Checked = bool.Parse(val); // restore value i = radiobutton_list.Count + 1; } if (i == radiobutton_list.Count) { MessageBox.Show("Control not found: " + name); } } } else if (s.StartsWith("txt")) { // look through each control to find the matching name for (int i = 0; i < textbox_list.Count; i++) { TextBoxTS c = (TextBoxTS)textbox_list[i]; if (c.Name.Equals(name)) // name found { c.Text = val; // restore value i = textbox_list.Count + 1; } if (i == textbox_list.Count) { MessageBox.Show("Control not found: " + name); } } } else if (s.StartsWith("tb")) { // look through each control to find the matching name for (int i = 0; i < trackbar_list.Count; i++) { TrackBarTS c = (TrackBarTS)trackbar_list[i]; if (c.Name.Equals(name)) // name found { int num = int.Parse(val); if (num > c.Maximum) { num = c.Maximum; } if (num < c.Minimum) { num = c.Minimum; } c.Value = num; i = trackbar_list.Count + 1; } if (i == trackbar_list.Count) { MessageBox.Show("Control not found: " + name); } } } else if (s.StartsWith("clrbtn")) { string[] colors = val.Split('.'); if (colors.Length == 4) { int R, G, B, A; R = Int32.Parse(colors[0]); G = Int32.Parse(colors[1]); B = Int32.Parse(colors[2]); A = Int32.Parse(colors[3]); for (int i = 0; i < colorbutton_list.Count; i++) { ColorButton c = (ColorButton)colorbutton_list[i]; if (c.Name.Equals(name)) // name found { c.Color = Color.FromArgb(A, R, G, B); i = colorbutton_list.Count + 1; } if (i == colorbutton_list.Count) { MessageBox.Show("Control not found: " + name); } } } } } ForceFormOnScreen(form); }