private void BTextBox_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { CTextBox.Focus(); } }
private void toolAddCTextBox_Click(object sender, EventArgs e) { ctxt = new CTextBox(); //实例化CTextBox对象 ctxt.IsFlag = "0"; //系统默认不为单据编号对应的输入框 ctxt.ControlId = 0; //系统默认的控件编号为零 ctxt.FormParent = this; //设置父窗体 //设置文本输入框的位置 ctxt.Location = new Point(MousePosition.X - offset.X, MousePosition.Y - offset.Y); ctxt.ReadOnly = true; //设置文本输入框为只读 ctxt.BackColor = Color.Red; //设置文本输入框的背景颜色为红色 this.Controls.Add(ctxt); //向窗体中添加新的文本输入框 ctxt.Focus(); //设置新的文本输入框获取光标 ctxt.SelectAll(); //设置新的文本输入框选择全部文本 }
private void toolAddCTextBox_Click(object sender, EventArgs e) { ctxt = new CTextBox(); ctxt.IsFlag = "0"; //系统默认不为单据编号对应的输入框 ctxt.ControlId = 0; //系统默认的控件编号为零 //ctxt.Text = "请输入名称"; ctxt.FormParent = this; ctxt.Location = new Point(MousePosition.X - offset.X, MousePosition.Y - offset.Y); ctxt.ReadOnly = true; ctxt.BackColor = Color.Red; this.Controls.Add(ctxt); //---选择默认的文本 ctxt.Focus(); ctxt.SelectAll(); }
private void ctxt_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { CTextBox ctxtTurnCtrl = null; CTextBox ctxtCurCtrl = null; List <CTextBox> ctxts = GetCTextBoxes(this.splitContainer1.Panel1); foreach (CTextBox ctxt in ctxts) { if (ctxt.Focused) { ctxtCurCtrl = ctxt; break; } } ctxtTurnCtrl = ctxts.Find(number => number.ControlName == ctxtCurCtrl.TurnControlName); if (ctxtTurnCtrl != null) { ctxtTurnCtrl.Focus(); } } }
private void ctxt_KeyDown(object sender, KeyEventArgs e) //CTextBox的KeyDown事件 { if (e.KeyCode == Keys.Enter) //判断是否按下回车键 { CTextBox ctxtTurnCtrl = null; //创建转换后的CTextBox对象 CTextBox ctxtCurCtrl = null; //创建当前编辑的CTextBox对象 //获取splitContainer1.Panel1中的所有CTextBox对象 List <CTextBox> ctxts = GetCTextBoxes(this.splitContainer1.Panel1); foreach (CTextBox ctxt in ctxts) //遍历CTextBox集合 { if (ctxt.Focused) //如果CTextBox有鼠标焦点 { ctxtCurCtrl = ctxt; //为当前编辑的CTextBox对象赋值 break; } } //为确定的CTextBox对象赋值 ctxtTurnCtrl = ctxts.Find(number => number.ControlName == ctxtCurCtrl.TurnControlName); if (ctxtTurnCtrl != null) //判断转换后确定的CTextBox对象是否为空 { ctxtTurnCtrl.Focus(); //为其设置焦点 } } }
private void toolPrint_Click(object sender, EventArgs e) { //---保存 string strSql = null; List <string> strSqls = new List <string>(); List <CTextBox> ctxts = GetCTextBoxes(this.splitContainer1.Panel1); foreach (CTextBox ctxt in ctxts) { if (ctxt.IsFlag == "1") //若是单据号 { if (String.IsNullOrEmpty(ctxt.Text.Trim())) { MessageBox.Show("单据号不许为空!", "软件提示"); ctxt.Focus(); return; } else { if (ctxt.Text.Trim().Length != ctxt.MaxLength) { MessageBox.Show("单据号位数不正确!", "软件提示"); ctxt.Focus(); return; } } if (cc.IsExistExpressBillCode(ctxt.Text.Trim(), lbxBillTypeCode.SelectedValue.ToString())) { MessageBox.Show("该单据号已经存在!", "软件提示"); ctxt.Focus(); return; } } else { if (String.IsNullOrEmpty(ctxt.Text.Trim())) { if (MessageBox.Show(ctxt.ControlName + "为空,是否继续", "软件提示", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.No) { ctxt.Focus(); return; } } } strSql = "INSERT INTO tb_BillText(BillTypeCode,ControlId,ExpressBillCode,ControlText) VALUES( '" + lbxBillTypeCode.SelectedValue.ToString() + "','" + ctxt.ControlId + "','" + ctxtExpressBillCode.Text.Trim() + "','" + ctxt.Text.Trim() + "')"; strSqls.Add(strSql); } if (strSqls.Count > 0) { if (dataOper.ExecDataBySqls(strSqls)) { //设置<打印文档>的边距 Margins margin = new Margins(0, 0, 0, 0); pd.DefaultPageSettings.Margins = margin; //设置<打印文档>的纸张大小 PaperSize pageSize = new PaperSize("快递单打印", Convert.ToInt32(MillimetersToPixel(Convert.ToInt32(dtBillType.Rows[0]["BillWidth"]), fDpiX)), Convert.ToInt32(MillimetersToPixel(Convert.ToInt32(dtBillType.Rows[0]["BillHeight"]), fDpiY))); pd.DefaultPageSettings.PaperSize = pageSize; //ppd.Document = pd; //ppd.ShowDialog(); pd.Print(); } else { MessageBox.Show("保存失败,无法打印", "软件提示"); return; } } }
private void toolPrint_Click(object sender, EventArgs e) { string strSql = null; //声明表示SQL语句的字符串 List <string> strSqls = new List <string>(); //创建字符串列表 //实例化List<CTextBox> List <CTextBox> ctxts = GetCTextBoxes(this.splitContainer1.Panel1); foreach (CTextBox ctxt in ctxts) //循环所有的文本输入框 { if (ctxt.IsFlag == "1") //若是单据号控件 { if (String.IsNullOrEmpty(ctxt.Text.Trim())) //若单据号为空 { MessageBox.Show("单据号不许为空!", "软件提示"); ctxt.Focus();//单据号控件获得焦点 return; } else { if (ctxt.Text.Trim().Length != ctxt.MaxLength)//若单据号位数不正确 { MessageBox.Show("单据号位数不正确!", "软件提示"); ctxt.Focus(); return; } } //若数据库中已存在当前的单据号码 if (cc.IsExistExpressBillCode(ctxt.Text.Trim(), lbxBillTypeCode.SelectedValue.ToString())) { MessageBox.Show("该单据号已经存在!", "软件提示"); ctxt.Focus(); return; } } else { if (String.IsNullOrEmpty(ctxt.Text.Trim()))//若当前控件的Text属性值为空 { if (MessageBox.Show(ctxt.ControlName + "为空,是否继续", "软件提示", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.No) { ctxt.Focus(); return; } } } //表示插入新快递单的某项信息 strSql = "INSERT INTO tb_BillText(BillTypeCode,ControlId,ExpressBillCode,ControlText)VALUES('" + lbxBillTypeCode.SelectedValue.ToString() + "', '" + ctxt.ControlId + "', '" + ctxtExpressBillCode.Text.Trim() + "','" + ctxt.Text.Trim() + "')"; strSqls.Add(strSql);//向strSqls中添加SQL字符串 } if (strSqls.Count > 0) { if (dataOper.ExecDataBySqls(strSqls))//若保存快递单数据成功 { //设置<打印文档>的边距 Margins margin = new Margins(0, 0, 0, 0); pd.DefaultPageSettings.Margins = margin; //设置<打印文档>的纸张大小 PaperSize pageSize = new PaperSize("快递单打印", Convert.ToInt32(MillimetersToPixel(Convert.ToInt32(dtBillType.Rows[0]["BillWidth"]), fDpiX)), Convert.ToInt32(MillimetersToPixel(Convert.ToInt32(dtBillType.Rows[0]["BillHeight"]), fDpiY))); pd.DefaultPageSettings.PaperSize = pageSize; //设置打印文档的纸张大小 printDialog1.Document = pd; //开始打印快递单 printDialog1.ShowDialog(); //显示打印对话框,以便进行批量打印 } else { MessageBox.Show("保存失败,无法打印", "软件提示"); return; } } }