您的位置:首页 > 其它

毕业设计 动态标注公式的实现

2007-05-21 14:22 375 查看

6.2生产通知单界面及代码



图6-3
//在图片上创建文本框
private void pictureBox1_MouseDoubleClick(object sender, MouseEventArgs e)
{
//确定点
Point pt=new Point(e.X,e.Y);
//生成文本
GenTextBox(pt, mark);
mark++;//标记值
}
//保存数据
private void btn_Save_Click(object sender, EventArgs e)
{
string sImage = img_path; //得到图片存储位置
string Formula_id = TB_Formual.Text.Trim();//得到公式编号;
DrawLabel DL = new DrawLabel(); //标注点业务处理类
DL.DelPoint(Formula_id); //删除原始结点
foreach (Control tr in Pic_Image.Controls) //查询图片控件中所有控件
{
if (tr.GetType() == typeof(TextBox)) //得到控件类型为文本框
{
TextBox cutb = (TextBox)tr; //创建文本框类
Point pt = cutb.Location; //得到文本框位置
int value =Convert.ToInt32(cutb.Text.ToString());//得到文本框值
DL.SavePoint(pt.X, pt.Y, value, Formula_id);//保存值
}
}
FrmProduct FP = new FrmProduct(odt_id,Formula_id,sImage);//显示生产通知单窗体
FP.Show();
}
//移除控件
private void RemoveAllText()
{
int length=Pic_Image.Controls.Count;//得到控件数目
for (int i = 0; i <length;i++ )
{
this.Pic_Image.Controls.Remove(Pic_Image.Controls[0]);//移除
}
}
//加载图片
private void btn_LoadImg_Click(object sender, EventArgs e)
{
RemoveAllText();//移除已有控件
OPF_Image.Filter = "Image Files(*.jgp)|*.jpg";//过滤图片类型
OPF_Image.Multiselect = false;
OPF_Image.FileName = "";
if (OPF_Image.ShowDialog() == DialogResult.OK)
{
Pic_Image.Image = Image.FromFile(OPF_Image.FileName);//加载图片
img_path = OPF_Image.FileName;//保存图片路径
}
btn_Save.Enabled = true;//保存按钮可用
}
//自动生成文本框及样式
private void GenTextBox(Point pt, int mark)
{
this.tb = new System.Windows.Forms.TextBox();//创建文本框
Point dot = pt; //文本框位置
this.tb.Location = new System.Drawing.Point(dot.X, dot.Y);
this.tb.Name = "textBox" + mark.ToString();//文本框名称
this.tb.Size = new System.Drawing.Size(30, 20);//文本框大小
this.tb.TabIndex = mark;//序号
this.tb.BorderStyle = BorderStyle.None;//无边框
this.tb.BackColor = Color.White;//背景为白色
this.tb.MouseLeave += new System.EventHandler(this.TBMouseLeave);//文本框不可编辑
this.tb.MouseEnter += new System.EventHandler(this.TBMouseEnter);//文本框可编辑
this.tb.DoubleClick += new System.EventHandler(this.TBRemove);//删除控件
this.Pic_Image.Controls.Add(tb); //在图片中增加文本框
}
//当鼠标离开时使文本不可编辑
private void TBMouseLeave(object sender, EventArgs e)
{
TextBox cuTB = (TextBox)sender;
cuTB.ReadOnly = true;
}
//当鼠标进入时使文本可编辑
private void TBMouseEnter(object sender, EventArgs e)
{
TextBox cuTB = (TextBox)sender;
cuTB.ReadOnly = false;
}
//删除文本控件
private void TBRemove(object sender, EventArgs e)
{
TextBox cuTB = (TextBox)sender;
if (MessageBox.Show("确定要删除!") == DialogResult.OK)
{
this.Pic_Image.Controls.Remove(cuTB);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐