Hot Key Assignment

I have a bunch of custom text boxes and code I would like to run on a F3 key press. I have assigned all of this to a button click but want to have it assigned to F3 instead. Any ideas?

//All - Clear Out
	private void btnClearOrderForm_Click(object sender, System.EventArgs args)
	{
		ClearScreen();
	}
	private void ClearScreen()
	{
		epiNumericRMANum.Value = (0);
		epiTextBoxLineArt.Text = string.Empty;
		epiTextBoxOrderNoAttach.Text = string.Empty;
		btnShipstore.Visible = true;
		btnChecklist.Visible = true;
		epiTextBoxNoChecklist.Visible = false;
		btnCreateNon_Conformance.Visible = true;
		txtCustomer_CustID.Text = string.Empty;
		epiTextCustNumRef.Text = string.Empty;
		numOrderDtl_OrderNum.Value = (0);
		numOrderDtl_OrderLine.Value = (0);
		numOrderDtl_TotalReleases.Value = (0);
		epiNumericOrderNumRef.Value = (0);
		epiNumericEditorOrderLineNo.Value = (0);
		epiNumericEditorLastLocation.Value = (0);	
		epiTextBoxPORefNum.Text = string.Empty;
		txtOrderHed_PONum.Text = string.Empty;
		epiTextBoxCustomerName.Text = string.Empty;
		epiTextCustNumRef.Text = string.Empty;
		txtQuoteSentDate.Text = string.Empty;
		epiTextBoxQuoteLetterTo.Text = string.Empty;
		QuoteRefNum.Value = (0);
		epiTextBoxQuoteLetterHTML.Text = string.Empty;	
		MessageBox.Show("Is everything 0?");
		DynamicQueryAdapter dqa = new DynamicQueryAdapter(oTrans);
		dqa.BOConnect();
		QueryExecutionDataSet qeds = dqa.GetQueryExecutionParametersByID("GS_Order_Detail_Params");
		qeds.ExecutionParameter.Clear();
		qeds.ExecutionParameter.AddExecutionParameterRow("OrderNum", epiNumericOrderNumRef.Value.ToString() , "nvarchar", false, Guid.NewGuid(), "A");
		qeds.ExecutionParameter.AddExecutionParameterRow("OrderLine", epiNumericEditorOrderLineNo.Value.ToString() , "nvarchar", false, Guid.NewGuid(), "A");
		dqa.ExecuteByID("GS_Order_Detail_Params", qeds);
		grid_OrderDetails.DataSource = dqa.QueryResults.Tables["Results"];
		changeordernumber();
		changequotenumber();
		changecustomernumber();
		//txtCustomer_CustID.Focus();
	}
1 Like

I also have something like this on a button, any Ideas to assign it to a ´Hot Key´?

The easiest way to get the desired functionality is to turn on KeyPreview for the form. Then set a key handler:

//initialize
YourFormName.KeyPreview = true;

YourFormName.KeyUp +=
 new System.Windows.Forms.KeyEventHandler(KeyEvent);

//destroy
YourFormName.KeyUp -=
new System.Windows.Forms.KeyEventHandler(KeyEvent);

//your func
private void KeyEvent(object sender, KeyEventArgs e) 
 {
         if (e.KeyCode == Keys.F3)
        {
            MessageBox.Show("Function F3"); 
         //Your Code
        }
}



6 Likes

Chris
do you think something similar to this code could be used to invoke switching action with FunctionKey combination within and entry program such as AP INVOICE ENTRY.
For example: ALT-F8 to switch to LINES/GL ANALYSIS tab
and then CTRL-F8 to switch to HEADER/DETAIL tab

Assuming that those arent already assigned as shortcuts you could do this.

1 Like