private DebugForm(Logger logger) { Logger = logger; InitializeComponent(); ShareXResources.ApplyThemeToForm(this); rtbDebug.Text = Logger.ToString(); rtbDebug.SelectionStart = rtbDebug.TextLength; rtbDebug.ScrollToCaret(); rtbDebug.AddContextMenu(); string startupPath = AppDomain.CurrentDomain.BaseDirectory; llRunningFrom.Text = startupPath; llRunningFrom.LinkClicked += (sender, e) => Helpers.OpenFolder(startupPath); Logger.MessageAdded += logger_MessageAdded; Activated += (sender, e) => btnUploadLog.Visible = HasUploadRequested; FormClosing += (sender, e) => Logger.MessageAdded -= logger_MessageAdded; }
public ErrorForm(string errorTitle, string errorMessage, string logPath, string bugReportPath, bool unhandledException = true) { InitializeComponent(); ShareXResources.ApplyTheme(this); IsUnhandledException = unhandledException; LogPath = logPath; BugReportPath = bugReportPath; if (IsUnhandledException) { DebugHelper.WriteException(errorMessage, "Unhandled exception"); } lblErrorMessage.Text = errorTitle; txtException.Text = errorMessage; txtException.SelectionStart = txtException.TextLength; btnSendBugReport.Visible = !string.IsNullOrEmpty(BugReportPath); btnOpenLogFile.Visible = !string.IsNullOrEmpty(LogPath) && File.Exists(LogPath); btnContinue.Visible = IsUnhandledException; btnClose.Visible = IsUnhandledException; btnOK.Visible = !IsUnhandledException; }
public InputBox(string title = null, string inputText = null, string okText = null, string cancelText = null) { InitializeComponent(); ShareXResources.ApplyTheme(this); InputText = inputText; if (!string.IsNullOrEmpty(title)) { Text = title; } if (!string.IsNullOrEmpty(InputText)) { txtInputText.Text = InputText; } if (!string.IsNullOrEmpty(okText)) { btnOK.Text = okText; } if (!string.IsNullOrEmpty(cancelText)) { btnCancel.Text = cancelText; } }
public CodeMenu(TextBoxBase tbb, CodeMenuItem[] items) { textBoxBase = tbb; Font = new Font("Lucida Console", 8); AutoClose = textBoxBase == null; ShowImageMargin = false; foreach (CodeMenuItem item in items) { ToolStripMenuItem tsmi = new ToolStripMenuItem { Text = $"{item.Name} - {item.Description}", Tag = item.Name }; tsmi.MouseUp += (sender, e) => { if (textBoxBase != null && e.Button == MouseButtons.Left) { string text = ((ToolStripMenuItem)sender).Tag.ToString(); textBoxBase.AppendTextToSelection(text); } else { Close(); } }; if (string.IsNullOrWhiteSpace(item.Category)) { Items.Add(tsmi); } else { ToolStripMenuItem tsmiParent; int index = Items.IndexOfKey(item.Category); if (index < 0) { tsmiParent = new ToolStripMenuItem { Text = item.Category, Tag = item.Category, Name = item.Category }; tsmiParent.HideImageMargin(); Items.Add(tsmiParent); } else { tsmiParent = Items[index] as ToolStripMenuItem; } tsmiParent.DropDownItems.Add(tsmi); } } Items.Add(new ToolStripSeparator()); ToolStripMenuItem tsmiClose = new ToolStripMenuItem(Resources.CodeMenu_Create_Close); tsmiClose.Click += (sender, e) => Close(); Items.Add(tsmiClose); if (ShareXResources.UseCustomTheme) { ShareXResources.ApplyCustomThemeToContextMenuStrip(this); } if (textBoxBase != null) { textBoxBase.MouseDown += (sender, e) => { if (Items.Count > 0) { Show(textBoxBase, MenuLocation); } }; textBoxBase.GotFocus += (sender, e) => { if (Items.Count > 0) { Show(textBoxBase, MenuLocation); } }; textBoxBase.LostFocus += (sender, e) => { if (Visible) { Close(); } }; textBoxBase.KeyDown += (sender, e) => { if ((e.KeyCode == Keys.Enter || e.KeyCode == Keys.Escape) && Visible) { Close(); e.SuppressKeyPress = true; } }; textBoxBase.Disposed += (sender, e) => Dispose(); } }
public MyMessageBox(string text, string caption, MessageBoxButtons buttons = MessageBoxButtons.OK, string checkBoxText = null, bool isChecked = false) { Width = 180; Height = 100; Text = caption; BackColor = SystemColors.Window; FormBorderStyle = FormBorderStyle.FixedDialog; ShowInTaskbar = false; TopMost = true; StartPosition = FormStartPosition.CenterScreen; MinimizeBox = false; MaximizeBox = false; Shown += MyMessageBox_Shown; Label labelText = new Label(); labelText.Margin = new Padding(0); labelText.Font = SystemFonts.MessageBoxFont; labelText.TextAlign = ContentAlignment.MiddleLeft; labelText.AutoSize = true; labelText.MinimumSize = new Size(125, 0); labelText.MaximumSize = new Size(400, 400); labelText.Location = new Point(0, 0); labelText.Text = text; Button button1 = new Button(); button1.Margin = new Padding(0, ButtonPadding, ButtonPadding, ButtonPadding); button1.BackColor = Color.Transparent; button1.Size = new Size(80, 26); button1.UseVisualStyleBackColor = false; button1.Text = "button1"; button1.TabIndex = 0; button1.Click += (sender, e) => { DialogResult = button1Result; Close(); }; Button button2 = new Button(); button2.Margin = new Padding(0, ButtonPadding, ButtonPadding, ButtonPadding); button2.BackColor = Color.Transparent; button2.Size = new Size(80, 26); button2.UseVisualStyleBackColor = false; button2.Text = "button2"; button2.TabIndex = 1; button2.Click += (sender, e) => { DialogResult = button2Result; Close(); }; switch (buttons) { default: case MessageBoxButtons.OK: button1.Text = Resources.MyMessageBox_MyMessageBox_OK; button1Result = DialogResult.OK; button2.Visible = false; break; case MessageBoxButtons.OKCancel: button1.Text = Resources.MyMessageBox_MyMessageBox_OK; button1Result = DialogResult.OK; button2.Text = Resources.MyMessageBox_MyMessageBox_Cancel; button2Result = DialogResult.Cancel; break; case MessageBoxButtons.YesNo: button1.Text = Resources.MyMessageBox_MyMessageBox_Yes; button1Result = DialogResult.Yes; button2.Text = Resources.MyMessageBox_MyMessageBox_No; button2Result = DialogResult.No; break; } FlowLayoutPanel panel = new FlowLayoutPanel(); panel.BackColor = Color.FromArgb(240, 240, 240); panel.FlowDirection = FlowDirection.RightToLeft; FlowLayoutPanel labelPanel = new FlowLayoutPanel(); labelPanel.FlowDirection = FlowDirection.TopDown; labelPanel.AutoSize = true; labelPanel.AutoSizeMode = AutoSizeMode.GrowAndShrink; labelPanel.Location = new Point(LabelHorizontalPadding, LabelVerticalPadding); labelPanel.Controls.Add(labelText); if (checkBoxText != null) { IsChecked = isChecked; CheckBox checkBox = new CheckBox(); checkBox.Font = SystemFonts.MessageBoxFont; checkBox.Margin = new Padding(2, LabelVerticalPadding, 0, 0); checkBox.AutoSize = true; checkBox.Text = checkBoxText; checkBox.CheckedChanged += (sender, e) => IsChecked = checkBox.Checked; labelPanel.Controls.Add(checkBox); } panel.Controls.Add(button2); panel.Controls.Add(button1); Controls.Add(labelPanel); Controls.Add(panel); panel.Location = new Point(0, labelPanel.Bottom + LabelVerticalPadding); panel.Size = new Size(labelPanel.Width + (LabelHorizontalPadding * 2), button1.Height + (ButtonPadding * 2)); ClientSize = new Size(panel.Width, labelPanel.Height + (LabelVerticalPadding * 2) + panel.Height); ShareXResources.ApplyTheme(this); if (ShareXResources.ExperimentalCustomTheme) { panel.BackColor = ShareXResources.Theme.BorderColor; } }