private void titleTextBox_KeyDown(object sender, KeyEventArgs e) { TitleTextBox textBox = (sender as TitleTextBox); if (e.KeyCode == Keys.Down) { if (e.Control) { //move to beginning of next textbox int row = this.GetRow(sender as Control); FocusOnTitle(row + 1); e.Handled = true; } else { //if cursor is on last line, move to next textbox if (textBox.CursorOnLastLine()) { int row = this.GetRow(sender as Control); SelectTitleTextBox(row, row + 1); e.Handled = true; } } } if (e.KeyCode == Keys.Up) { if (e.Control) { //move to beginning of next textbox int row = this.GetRow(sender as Control); FocusOnTitle(row - 1); e.Handled = true; } else { //if cursor is on first line, move to previous textbox if (textBox.CursorOnFirstLine()) { int row = this.GetRow(sender as Control); SelectTitleTextBox(row, row - 1); e.Handled = true; } } } }
private void InsertTaskRowAt(int rowIndex, Task task) { RequestSuspendLayout(); InsertRowAt(rowIndex); Button addButton = NewButton("+", addTask_Click); this.Controls.Add(addButton, PLUS_COLUMN_INDEX, rowIndex); TextBox rowNumberBox = NewTextBox("RowNumberTextBox", rowIndex.ToString()); rowNumberBox.LostFocus += new EventHandler(rowNumberTextBox_LostFocus); rowNumberBox.Margin = new Padding(0); rowNumberBox.TabStop = false; rowNumberBox.KeyDown += new KeyEventHandler(rowNumberTextBox_KeyDown); rowNumberBox.KeyUp += new KeyEventHandler(rowNumberTextBox_KeyUp); this.Controls.Add(rowNumberBox, ROW_COLUMN_INDEX, rowIndex); this.Controls.Add(NewDataLabel("Id", task.Id.ToString()), ID_COLUMN_INDEX, rowIndex); TitleTextBox titleBox = new TitleTextBox("TitleTextBox", task.Description); titleBox.GotFocus += new EventHandler(titleTextBox_GotFocus); titleBox.TextChanged += new EventHandler(titleTextBox_TextChanged); titleBox.KeyDown += new KeyEventHandler(titleTextBox_KeyDown); titleBox.KeyUp += new KeyEventHandler(titleTextBox_KeyUp); titleBox.TabIndex = 1; this.Controls.Add(titleBox, TITLE_COLUMN_INDEX, rowIndex); StatusComboBox statusComboBox = new StatusComboBox(project.Statuses.ToList(), task.Status); statusComboBox.SelectedIndexChanged += new EventHandler(statusComboBox_SelectedIndexChanged); this.Controls.Add(statusComboBox, STATUS_COLUMN_INDEX, rowIndex); CategoryComboBox categoryComboBox = new CategoryComboBox(project.Categories.ToList(), task.Category); categoryComboBox.SelectedIndexChanged += new EventHandler(categoryComboBox_SelectedIndexChanged); this.Controls.Add(categoryComboBox, CATEGORY_COLUMN_INDEX, rowIndex); Label createLabel = NewDataLabel("CreateDate", task.CreateDateString); createLabel.Margin = new Padding(0); createLabel.TextAlign = ContentAlignment.TopRight; createLabel.Dock = DockStyle.Right; this.Controls.Add(createLabel, CREATED_COLUMN_INDEX, rowIndex); Label doneLabel = NewDataLabel("DoneDate", task.DoneDateString); doneLabel.Margin = new Padding(0); doneLabel.TextAlign = ContentAlignment.TopRight; doneLabel.Dock = DockStyle.Right; this.Controls.Add(doneLabel, DONE_COLUMN_INDEX, rowIndex); this.Controls.Add(NewButton("X", deleteTask_Click), DELETE_COLUMN_INDEX, rowIndex); this.RowCount++; SetTabIndexes(); RequestResumeLayout(); }