From 4a8b7bf3b74eb42de9f2f35158895f2daf8870f6 Mon Sep 17 00:00:00 2001 From: Jens True Date: Sat, 12 Jun 2021 19:42:33 +0200 Subject: [PATCH] Focus on mouseover so spacebar may be used for pressing complete --- Tidstagning/Form1.Designer.cs | 7 +++++++ Tidstagning/Form1.cs | 29 ++++++++++++++++++++++------- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/Tidstagning/Form1.Designer.cs b/Tidstagning/Form1.Designer.cs index f80dd55..21202e6 100644 --- a/Tidstagning/Form1.Designer.cs +++ b/Tidstagning/Form1.Designer.cs @@ -164,8 +164,11 @@ // this.grid.AllowUserToAddRows = false; this.grid.AllowUserToDeleteRows = false; + this.grid.AllowUserToResizeColumns = false; + this.grid.AllowUserToResizeRows = false; this.grid.AutoGenerateColumns = false; this.grid.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill; + this.grid.ClipboardCopyMode = System.Windows.Forms.DataGridViewClipboardCopyMode.Disable; this.grid.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.grid.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { this.Complete, @@ -174,7 +177,9 @@ this.txtLog.SetColumnSpan(this.grid, 2); this.grid.DataSource = this.entryBindingSource; this.grid.Dock = System.Windows.Forms.DockStyle.Fill; + this.grid.EditMode = System.Windows.Forms.DataGridViewEditMode.EditProgrammatically; this.grid.Location = new System.Drawing.Point(273, 3); + this.grid.MultiSelect = false; this.grid.Name = "grid"; this.grid.ReadOnly = true; this.grid.RowHeadersWidthSizeMode = System.Windows.Forms.DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders; @@ -182,6 +187,7 @@ this.grid.RowTemplate.DefaultCellStyle.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.grid.RowTemplate.Height = 30; this.grid.RowTemplate.ReadOnly = true; + this.grid.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; this.grid.Size = new System.Drawing.Size(1039, 542); this.grid.TabIndex = 0; this.grid.CellClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.grid_Click); @@ -315,6 +321,7 @@ this.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; this.ClientSize = new System.Drawing.Size(1315, 694); this.Controls.Add(this.txtLog); + this.DoubleBuffered = true; this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.Name = "Form1"; this.Text = "Tidstagning"; diff --git a/Tidstagning/Form1.cs b/Tidstagning/Form1.cs index 5ab4ec7..5cdbbd1 100644 --- a/Tidstagning/Form1.cs +++ b/Tidstagning/Form1.cs @@ -14,7 +14,6 @@ namespace Tidstagning Relay horn; Procedure startprocedure = new Procedure(); - int OldRow = 0; public Form1() { InitializeComponent(); @@ -182,20 +181,36 @@ namespace Tidstagning private void grid_CellMouseEnter(object sender, DataGridViewCellEventArgs e) { - if (e.RowIndex > -1) + if (e.RowIndex > -1 ) { - grid.Rows[e.RowIndex].Selected = true; - grid.Rows[e.RowIndex].Height = 60; + try + { + grid.Rows[e.RowIndex].Selected = true; + grid.Rows[e.RowIndex].Height = 60; + grid.CurrentCell = grid.Rows[e.RowIndex].Cells[e.ColumnIndex]; + if (btnStop.Enabled) + { + grid.Focus(); + } + } + catch { } } } private void grid_CellMouseLeave(object sender, DataGridViewCellEventArgs e) { - if (e.RowIndex > -1) + if (e.RowIndex > -1 ) { - grid.Rows[e.RowIndex].Selected = false; - grid.Rows[e.RowIndex].Height = 30; + try + { + grid.Rows[e.RowIndex].Selected = false; + grid.Rows[e.RowIndex].Height = 30; + + } + catch + { } } + } } }