private void button_OK_Click(object sender, EventArgs e) { if (this.ActionTable.SelectedRows.Count == 0) { MessageBox.Show(this, "尚未选择事项..."); return; } this.SelectedIndex = this.ActionTable.SelectedRowIndices[0]; if (Actions != null) { this.SelectedAction = (ScriptAction)this.Actions[this.SelectedIndex]; } else { this.SelectedAction = null; } this.DialogResult = DialogResult.OK; this.Close(); }
void FillList() { listView1.Items.Clear(); if (Actions == null) { return; } ListViewItem first_item = null; for (int i = 0; i < Actions.Count; i++) { ScriptAction action = (ScriptAction)Actions[i]; ListViewItem item = new ListViewItem(action.Name, 0); item.SubItems.Add(action.Comment); item.SubItems.Add(action.ScriptEntry); if (action.Active == true) { item.Selected = true; // 2009/2/24 if (first_item == null) { first_item = item; } } listView1.Items.Add(item); } // 2009/2/24 if (first_item != null) { listView1.FocusedItem = first_item; first_item.EnsureVisible(); } }
void FillList() { this.ActionTable.Rows.Clear(); if (Actions == null) { return; } DpRow first_item = null; for (int i = 0; i < Actions.Count; i++) { ScriptAction action = (ScriptAction)Actions[i]; DpRow item = new DpRow(); if (action.Name == "-") { item.Style = DpRowStyle.Seperator; } else { DpCell cell = new DpCell(action.Name); cell.Font = new Font(this.ActionTable.Font.FontFamily, 10, FontStyle.Bold, GraphicsUnit.Point); item.Add(cell); // 快捷键 cell = new DpCell(); if (action.ShortcutKey != (char)0) { cell.Text = new string(action.ShortcutKey, 1); cell.Text = cell.Text.ToUpper(); } item.Add(cell); // 说明 item.Add(new DpCell(action.Comment)); // 入口函数 cell = new DpCell(action.ScriptEntry); cell.ForeColor = SystemColors.GrayText; cell.Font = new Font(this.ActionTable.Font.FontFamily, 8, GraphicsUnit.Point); item.Add(cell); } if (action.Active == true) { item.Selected = true; // 2009/2/24 if (first_item == null) { first_item = item; } } this.ActionTable.Rows.Add(item); } if (first_item != null) { this.ActionTable.FocusedItem = first_item; first_item.EnsureVisible(); } }
private void ActionTable_KeyDown(object sender, KeyEventArgs e) { Debug.Assert(this.Actions != null, ""); char key = (char)e.KeyValue; if (key == (char)Keys.Enter) { this.ActionTable_DoubleClick(this, null); return; } else if (key == (char)Keys.Escape) { this.Close(); return; } else if (char.IsLetter(key) == true) { foreach (ScriptAction action in this.Actions) { if (Char.ToUpper(key) == Char.ToUpper(action.ShortcutKey)) { this.SelectedIndex = this.Actions.IndexOf(action); this.SelectedAction = action; if (this.CloseWhenComplete == true) { this.Hide(); } if (this.SelectedAction != null && this.TriggerAction != null) { if (this._processing > 0) { MessageBox.Show(this, "正在处理中,请稍后再重新启动执行"); return; } BeginProcess(); try { TriggerActionArgs e1 = new TriggerActionArgs(); e1.EntryName = this.SelectedAction.ScriptEntry; e1.sender = this.sender; e1.e = this.e; this.TriggerAction(this, e1); } finally { EndProcess(); } } if (this.CloseWhenComplete == true) { this.Close(); } return; } } // Console.Beep(); } }
public void RefreshState() { if (this.SetMenu == null) { return; } RefreshMenuEventArgs e = new RefreshMenuEventArgs(); e.Actions = this.Actions; e.sender = this.sender; e.e = this.e; this.SetMenu(this, e); DpRow first_selected_row = null; DpRow last_selected_row = null; for (int i = 0; i < this.ActionTable.Rows.Count; i++) { DpRow row = this.ActionTable.Rows[i]; if (row.Style == DpRowStyle.Seperator) { continue; } ScriptAction action = (ScriptAction)row.Tag; if (action == null) { Debug.Assert(false, ""); continue; } if (this.Actions == null || this.Actions.IndexOf(action) == -1) { row.Selected = false; continue; } if (row.Count == 0) { continue; } Debug.Assert(row.Count >= 4, ""); // 刷新一行 row[0].Text = action.Name; string strText = ""; if (action.ShortcutKey != (char)0) { strText = new string(action.ShortcutKey, 1); strText = strText.ToUpper(); } row[1].Text = strText; row[2].Text = action.Comment; row[3].Text = action.ScriptEntry; row.Selected = action.Active; if (first_selected_row == null && row.Selected == true) { first_selected_row = row; } if (row.Selected == true) { last_selected_row = row; } } if (first_selected_row != null) { first_selected_row.EnsureVisible(); } if (last_selected_row != null && last_selected_row != first_selected_row) { last_selected_row.EnsureVisible(); } }