Add() публичный Метод

public Add ( Control item ) : void
item Control
Результат void
		/// <summary>
		/// Creates a multiline label with its height fitted to the text
		/// </summary>
		/// <param name="text">The text for the label</param>
		/// <param name="graphics">The graphics context to use for measuring the text</param>
		/// <param name="width">The available width</param>
		/// <param name="controls">The collection to add the label to</param>
		private void AddNewLabel(string text, Graphics graphics, int width, ControlCollection controls)
		{
			Label label = new Label()
			{
				Visible = false,
				AutoSize = false,
				Dock = DockStyle.Top,
				Text = text
			};
			SizeF size = graphics.MeasureString(text, label.Font, width);
			label.Height = (int) Math.Round(size.Height + 8);

			controls.Add(label);
			label.BringToFront();
		}
Пример #2
0
        public static void ParseChildren(CustomInputControl parent, List<Classes.CustomInput.CustomInputControl> controls, ControlCollection controlContainer)
        {
            Bitmap image_down = Properties.Resources.Custom_Button_Down;
            Bitmap image_up = Properties.Resources.Custom_Button_Up;

            foreach (Classes.CustomInput.CustomInputControl controlDesc in controls)
            {
                HidButton imageButton = null;
                Control control = imageButton;

                switch (controlDesc.InputType)
                {
                    case Classes.CustomInputType.Container:
                        {
                            control = new ContainerPanel(parent, controlDesc);
                        }
                        break;
                    case Classes.CustomInputType.KeyCombination:
                    case Classes.CustomInputType.VirtualKey:
                    case Classes.CustomInputType.ScanCode:
                        {
                            control = imageButton = new KeyboardHidButton(parent, controlDesc);

                            if (!string.IsNullOrEmpty(controlDesc.Image))
                            {
                                imageButton.Image = GetBitmap(controlDesc.Image);
                            }
                            else
                            {
                                imageButton.Image = BuildCustomBitmap(image_up, controlDesc.InputDisplay, parent.Font, Color.Black);
                            }
                            if (!string.IsNullOrEmpty(controlDesc.DownImage))
                            {
                                imageButton.DownImage = GetBitmap(controlDesc.DownImage);
                            }
                            else
                            {
                                imageButton.DownImage = BuildCustomBitmap(image_down, controlDesc.InputDisplay, parent.Font, Color.White);
                            }
                            imageButton.SelectedImage = imageButton.DownImage;
                            imageButton.TransparentBackground = controlDesc.TransparentBackground;
                            imageButton.BackColor = parent.BackColor;
                            imageButton.CanHold = false;
                        }
                        break;
                    case Classes.CustomInputType.ShiftKey:
                    case Classes.CustomInputType.AltKey:
                    case Classes.CustomInputType.WinKey:
                        {
                        }
                        break;
                    case Classes.CustomInputType.LeftMouseButton:
                        {
                            imageButton = new MouseButtonHidButton(parent, controlDesc);
                        }
                        break;
                    case Classes.CustomInputType.RightMouseButton:
                        {
                            imageButton = new MouseButtonHidButton(parent, controlDesc);
                        }
                        break;
                    case Classes.CustomInputType.MouseDPad:
                        {
                            // add a control here to map dpad to mouse
                        }
                        break;
                    case Classes.CustomInputType.Accelerometer:
                        {
                            // add a control here to map accelerometer to mouse
                        }
                        break;
                    case Classes.CustomInputType.TouchPad:
                    case Classes.CustomInputType.TouchPadWithScroll:
                        {
                            control = new TouchControl();
                            ((TouchControl)control).HidWriter = parent.HidWriter;
                        }
                        break;
                    default:
                        {
                            // why are we here?
                        }
                        break;
                }
                control.Width = controlDesc.Width;
                control.Height = controlDesc.Height;
                control.Left = controlDesc.Left;
                control.Top = controlDesc.Top;
                control.Tag = controlDesc;

                if (!(control is ContainerPanel))
                {
                    control.Anchor = controlDesc.Anchor;
                    control.Dock = controlDesc.Dock;
                }

                controlContainer.Add(control);
            }
        }
		/// <summary>
		/// Adds a new one-line, bold label to a controls collection
		/// </summary>
		/// <param name="text">The text for the label</param>
		/// <param name="controls">The collection to add the label to</param>
		private void AddNewLabel(string text, ControlCollection controls)
		{
			Label label = new Label()
			{
				Visible = false,
				AutoSize = false,
				Dock = DockStyle.Top,
				Height = 16,
				Font = new Font("Arial", 8, FontStyle.Bold),
				Text = text
			};

			controls.Add(label);
			label.BringToFront();
		}