private void mouseClick(object sender, MouseEventArgs args) { if (args.Button != MouseButtons.Left) { return; } var position = _panelExamples.GetCellPosition((Control)sender); (Label query, _) = getLabels(position.Row); QueryClicked?.Invoke(query.Text); }
public SearchExamplesMenu() { InitializeComponent(); if (DesignMode) { return; } var queryRows = Enumerable.Range(0, _panelExamples.RowCount) .Select(getFindExampleRow) .Where(r => r.Query != null) .ToList(); var selectionBackColor = SystemColors.Highlight; foreach (var(query, comment, backColor) in queryRows) { void mouseEnter(object sender, EventArgs args) { query.BackColor = selectionBackColor; comment.BackColor = selectionBackColor; } void mouseLeave(object sender, EventArgs args) { query.BackColor = backColor; comment.BackColor = backColor; } void mouseClick(object sender, MouseEventArgs args) { if (args.Button != MouseButtons.Left) { return; } QueryClicked?.Invoke(query.Text); } query.MouseEnter += mouseEnter; comment.MouseEnter += mouseEnter; query.MouseLeave += mouseLeave; comment.MouseLeave += mouseLeave; query.MouseClick += mouseClick; comment.MouseClick += mouseClick; } }