private NonSelectableButton CreateCaptionButton() { var button = new NonSelectableButton { ImageAlign = ContentAlignment.MiddleCenter, FlatStyle = FlatStyle.Flat, Margin = new Padding(0), Padding = new Padding(0), TabStop = false, }; button.FlatAppearance.BorderSize = 1; button.MouseEnter += TitleBarButton_MouseEnter; button.MouseLeave += TitleBarButton_MouseLeave; button.MouseMove += TitleBarButton_MouseMove; return(button); }
public MainForm () { // // _comboBox // _comboBox = new ComboBox (); _comboBox.Location = new Point (8, 12); _comboBox.Size = new Size (285, 20); _comboBox.GotFocus += new EventHandler (ComboBox_GotFocus); _comboBox.LostFocus += new EventHandler (ComboBox_LostFocus); Controls.Add (_comboBox); // // _selectButton // _selectButton = new NonSelectableButton (); _selectButton.FlatStyle = FlatStyle.Flat; _selectButton.Location = new Point (10, 100); _selectButton.Text = "Select"; _selectButton.Click += new EventHandler (SelectButton_Click); Controls.Add (_selectButton); // // _refreshButton // _refreshButton = new NonSelectableButton (); _refreshButton.FlatStyle = FlatStyle.Flat; _refreshButton.Location = new Point (115, 100); _refreshButton.Text = "Refresh"; _refreshButton.Click += new EventHandler (RefreshButton_Click); Controls.Add (_refreshButton); // // _quitButton // _quitButton = new Button (); _quitButton.FlatStyle = FlatStyle.Flat; _quitButton.Location = new Point (215, 100); _quitButton.Text = "Quit"; _quitButton.Click += new EventHandler (QuitButton_Click); Controls.Add (_quitButton); // // _selectionStartLabel // _selectionStartLabel = new Label (); _selectionStartLabel.Location = new Point (8, 50); _selectionStartLabel.Size = new Size (100, 20); _selectionStartLabel.Text = "SelectionStart:"; Controls.Add (_selectionStartLabel); // // _selectionStartValue // _selectionStartValue = new Label (); _selectionStartValue.Location = new Point (110, 50); _selectionStartValue.Size = new Size (100, 20); Controls.Add (_selectionStartValue); // // _selectionLengthLabel // _selectionLengthLabel = new Label (); _selectionLengthLabel.Location = new Point (8, 75); _selectionLengthLabel.Size = new Size (100, 20); _selectionLengthLabel.Text = "SelectionLength:"; Controls.Add (_selectionLengthLabel); // // _selectionLengthValue // _selectionLengthValue = new Label (); _selectionLengthValue.Location = new Point (110, 75); _selectionLengthValue.Size = new Size (100, 20); Controls.Add (_selectionLengthValue); // // MainForm // ClientSize = new Size (300, 135); Location = new Point (250, 100); StartPosition = FormStartPosition.Manual; Text = "bug #333663"; Load += new EventHandler (MainForm_Load); }
private protected MenuCaptionBarForm() { SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.UserMouse | ControlStyles.OptimizedDoubleBuffer | ControlStyles.FixedHeight | ControlStyles.FixedWidth | ControlStyles.ResizeRedraw | ControlStyles.Opaque, true); minimizeButton = CreateCaptionButton(); minimizeButton.Click += (_, __) => WindowState = FormWindowState.Minimized; maximizeButton = CreateCaptionButton(); maximizeButton.Click += (_, __) => { inRestoreCommand = WindowState == FormWindowState.Maximized; try { WindowState = WindowState == FormWindowState.Maximized ? FormWindowState.Normal : FormWindowState.Maximized; } finally { inRestoreCommand = false; } UpdateMaximizeButtonIcon(); }; // Specialized save button which binds on the SaveToFile UIAction. saveButton = CreateCaptionButton(); saveButton.Visible = false; saveButton.Click += (_, __) => { try { ActionHandler.TryPerformAction(SharedUIAction.SaveToFile.Action, true); } catch (Exception exc) { MessageBox.Show(exc.Message); } }; ActionHandler.UIActionsInvalidated += _ => { // Update the save button each time the handler is invalidated. // Some kind of checked state doesn't seem to be supported, so ignore UIActionState.Checked. UIActionState currentActionState = ActionHandler.TryPerformAction(SharedUIAction.SaveToFile.Action, false); saveButton.Visible = currentActionState.Visible; saveButton.Enabled = currentActionState.Enabled; if (!saveButton.Enabled) { saveButton.FlatAppearance.BorderColor = ObservableStyle.BackColor; } }; closeButton = CreateCaptionButton(); closeButton.Click += (_, __) => Close(); MainMenuStrip = new MenuStrip(); SuspendLayout(); Controls.Add(minimizeButton); Controls.Add(maximizeButton); Controls.Add(saveButton); Controls.Add(closeButton); Controls.Add(MainMenuStrip); ResumeLayout(); ToolTip = new ToolTip(); UpdateToolTips(); ObservableStyle.NotifyChange += ObservableStyle_NotifyChange; AllowTransparency = true; TransparencyKey = ObservableStyle.SuggestedTransparencyKey; mainMenuActionHandler = new UIActionHandler(); this.BindActions(StandardUIActionBindings); Session.Current.CurrentLocalizerChanged += CurrentLocalizerChanged; }