private T CreateButton <T>(ref ButtonRect btnRect, int tabIndex, string text, MouseEventHandler clickFunc, int shapeIndex = -1) where T : Control, new() { Control button = new T() { Location = new Point(btnRect.x, btnRect.y), Size = new Size(btnRect.width, btnRect.height), TabIndex = tabIndex, Text = text, }; // Only set type info when button is a shaoe button if (typeof(T) == typeof(ShapeButton)) { ((ShapeButton)button).Text = ShapeTypeHelper.GetShapeName((ShapeType)shapeIndex); ((ShapeButton)button).Checked = (Value == (ShapeType)shapeIndex); ((ShapeButton)button).Type = (ShapeType)shapeIndex; } button.MouseClick += clickFunc; Controls.Add(button); btnRect.x += btnRect.width + btnRect.xSpacing; return((T)button); }
public void InitializeComponent() { ButtonRect btnRect = new ButtonRect(BUTTON_WIDTH, BUTTON_HEIGHT, BUTTON_XSPACING, 0); btnRect.left = btnRect.x; int tab = 2; // Create an array to store the amount of colors per palette colorToggles = new ColorButton[ColorsArray.COLORS_PER_PALETTE]; // Left button to create Scrolling CreateButton <Button>(ref btnRect, tab++, "<", PreviousPaletteButton_Click); // Create enough color buttons to match the colors per palette for (int i = 0; i < ColorsArray.COLORS_PER_PALETTE; i++) { var button = CreateButton <ColorButton>(ref btnRect, tab++, null, ColorButton_Click, i); colorToggles[i] = button; } // Right button to create Scrolling CreateButton <Button>(ref btnRect, tab++, ">", NextPaletteButton_Click); // Clamp the panel's maximum size to fit the color buttons + left/right buttons const int buttonCount = ColorsArray.COLORS_PER_PALETTE + 2; int rightOffset = btnRect.xSpacing * 2; this.MaximumSize = new Size( btnRect.left + (buttonCount * (btnRect.width + btnRect.xSpacing)) + rightOffset, this.Size.Height ); }
private T CreateButton <T>(ref ButtonRect btnRect, int tabIndex, string text, MouseEventHandler clickFunc, int colorIndex = -1) where T : Control, new() { Control button = new T() { Location = new Point(btnRect.x, btnRect.y), Size = new Size(btnRect.width, btnRect.height), TabIndex = tabIndex, Text = text, }; // Only set color info when button is a color button (ignoring palette scroll buttons) if (typeof(T) == typeof(ColorButton)) { ((ColorButton)button).Text = null; ((ColorButton)button).Color = ColorsArray.GetColorFromPalette(PaletteIndex, colorIndex); } button.MouseClick += clickFunc; Controls.Add(button); btnRect.x += btnRect.width + btnRect.xSpacing; return((T)button); }
/** * @return true: If a player enters the button with mouse */ public bool enterButton() { if (ButtonRect.Contains(Mouse.GetState().Position)) { return(true); } return(false); }
public static void AddButton(Rect rect, string text, int tag) { ButtonRect brect = new ButtonRect(); brect.pos = rect; brect.text = text; brect.tag = tag; btns.Add(brect); }
protected override void OnMouseEnter(EventArgs e) { base.OnMouseEnter(e); Point point = PointToClient(Cursor.Position); if (ButtonRect.Contains(point)) { ButtonState = ControlState.Hover; } }
protected override void OnMouseUp(MouseEventArgs e) { base.OnMouseUp(e); if (e.Button == MouseButtons.Left && e.Clicks == 1) { if (ClientRectangle.Contains(e.Location)) { ControlStates = ControlState.Hover; if (ShowSpliteButton) { CurrentMousePosition = ButtonRect.Contains(e.Location) ? ButtonMousePosition.Button : ButtonMousePosition.Splitebutton; if (CurrentMousePosition == ButtonMousePosition.Splitebutton) { if (OnSpliteButtonClick != null) { OnSpliteButtonClick(this, EventArgs.Empty); } if (ContextMenuStrip != null) { if (!_contextHandle) { _contextHandle = true; ContextMenuStrip.Opening += ContextMenuStrip_Opening; ContextMenuStrip.Closed += ContextMenuStrip_Closed; } ContextMenuStrip.Opacity = 1.0; ContextMenuStrip.Show(this, 0, Height + ContextOffset); } } else { if (OnButtonClick != null) { OnButtonClick(this, EventArgs.Empty); } } } else { CurrentMousePosition = ButtonMousePosition.Button; } } else { ControlStates = ControlState.Normal; CurrentMousePosition = ButtonMousePosition.None; } } }
protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); Point point = e.Location; if (ButtonRect.Contains(point)) { ButtonState = ControlState.Hover; } else { ButtonState = ControlState.Normal; } }
private void ClickStartButton() { MineCount = 99; num_cell_count = 0; scaned_list.Clear(); Operator.Instance.LeftClick(ButtonRect.Center().X, ButtonRect.Center().Y); for (int i = 0; i < CellCount.Width; i++) { for (int j = 0; j < CellCount.Height; j++) { Cells[i, j].Status = CellStatus.Idle; } } }
public void InitializeComponent() { ButtonRect btnRect = new ButtonRect(BUTTON_WIDTH, BUTTON_HEIGHT, BUTTON_XSPACING, BUTTON_YSPACING); btnRect.left = BUTTON_XSPACING; btnRect.top = BUTTON_YSPACING; int tab = 2; ShapeButtons = new ShapeButton[(int)ShapeType.Length]; for (int i = 0; i < ShapeButtons.Length; i++) { var button = CreateButton <ShapeButton>(ref btnRect, tab++, null, CheckBox_MouseClick, i); ShapeButtons[i] = button; } this.Size = new Size(btnRect.x - btnRect.left + btnRect.xSpacing, this.Size.Height); }
/// <summary> /// /// </summary> /// <param name="e"></param> protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); if (e.Button == MouseButtons.Left && e.Clicks == 1) { ControlState = MouseState.Pressed; if (ShowSpliteButton) { CurrentMousePosition = ButtonRect.Contains(e.Location) ? ButtonMousePosition.Button : ButtonMousePosition.Splitebutton; } else { CurrentMousePosition = ButtonMousePosition.Button; } } }
/// <summary> /// /// </summary> /// <param name="mevent"></param> protected override void OnMouseMove(MouseEventArgs mevent) { base.OnMouseMove(mevent); if (ClientRectangle.Contains(mevent.Location)) { ControlState = MouseState.Hover; if (ShowSpliteButton) { CurrentMousePosition = ButtonRect.Contains(mevent.Location) ? ButtonMousePosition.Button : ButtonMousePosition.Splitebutton; } else { CurrentMousePosition = ButtonMousePosition.Button; } } else { ControlState = MouseState.Normal; CurrentMousePosition = ButtonMousePosition.None; } }
void UIRenderer.ButtonRect(ButtonRect ui) { g2d.Graphics.FillRectangle(ui.Background, ui.X, ui.Y, ui.Width, ui.Hieght); }