[英]How can i do a short key for printing
如何为打印操作做快捷键?
我已经有这个了
我不知道if{}
里面有什么
if (keyData == (Keys.Control | Keys.P))
{
drucken_Click();
}
private void drucken_Click(object sender, EventArgs e)
{
PrintDialog printDialog = new PrintDialog();
PrintDocument printDocument = new PrintDocument();
printDialog.Document = printDocument;
printDocument.PrintPage += new PrintPageEventHandler (PrintReceiptPage);
DialogResult result = printDialog.ShowDialog();
if (result == DialogResult.OK)
{
printDocument.Print();
}
}
您无需在过程中使用参数,因此可以通过以下方式使用它:
if (keyData == (Keys.Control | Keys.P))
{
drucken_Click(null, EventArgs.Empty);
}
但是更好的方法是创建新的无参数函数并使用它。 像这样:
private void Print()
{
PrintDialog printDialog = new PrintDialog();
PrintDocument printDocument = new PrintDocument();
printDialog.Document = printDocument;
printDocument.PrintPage += new PrintPageEventHandler (PrintReceiptPage);
DialogResult result = printDialog.ShowDialog();
if (result == DialogResult.OK)
{
printDocument.Print();
}
}
您可以传入不使用的空值,但将来可能会中断。 最好将打印代码移到自己的方法中:
if (keyData == (Keys.Control | Keys.P))
{
PrintDocument();
}
private void drucken_Click(object sender, EventArgs e)
{
PrintDocument();
}
private void PrintDocument()
{
PrintDialog printDialog = new PrintDialog();
PrintDocument printDocument = new PrintDocument();
printDialog.Document = printDocument;
printDocument.PrintPage += new PrintPageEventHandler (PrintReceiptPage);
DialogResult result = printDialog.ShowDialog();
if (result == DialogResult.OK)
{
printDocument.Print();
}
}
使用KeyDown事件
private void Form1_Load(object sender, EventArgs e)
{
this.KeyDown += Form1_KeyDown;
}
void Form1_KeyDown(object sender, KeyEventArgs e)
{
if(e.KeyCode =xxx)//check the key pressed
//DO....
drucken_Click(null, null);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.