|
楼主 |
发表于 2014-6-24 14:37:17
|
显示全部楼层
//当鼠标指针位于控件上并按下鼠标键时发生
private void node_MouseDown(object sender, MouseEventArgs e)
{
mouse_offset = new Point(e.X, e.Y);
}
//鼠标移到控件上发生
private void node_MouseMove(object sender, MouseEventArgs e)
{
Control control = (Control)sender;
if (e.Button == MouseButtons.Left)
{
control.Left = control.Left + e.X - mouse_offset.X;
control.Top = control.Top + e.Y - mouse_offset.Y;
}
this.label6.Text = "横坐标:" + control.Left + "\n纵坐标:" + control.Top;
y1 = Convert.ToInt16(control.Left.ToString());
z1= Convert.ToInt16(control.Top.ToString());
}
//在鼠标指针离开控件时发生
private void node_MouseLeave(object sender, EventArgs e)
{
//修改数据库
PictureBox pb = sender as PictureBox;
string t = "";
//已添加的节点
for (int j = 0; j < dst.Tables[0].Rows.Count; j++)
{
if (pb.Name == node[j].Name)
t = node[j].Name;
}
//当前添加的节点
for (int i = dst.Tables[0].Rows.Count; i < icount; i++)
{
if (pb.Name == node.Name)
t = node.Name;
}
MySqlConnection conn = new MySqlConnection("server=127.0.0.1;user=root;database=smart_agriculture;port=3306;Charset=utf8;");
conn.Open();
//更新节点坐标
MySqlCommand Cmd = new MySqlCommand("update node_message set cod_x='" + y1 + "',cod_y='" + z1 + "' where add_mac='" + t + "';", conn);
Cmd.ExecuteNonQuery();
conn.Close();
}
这三个函数就是我用于控制pictureBox移动的
|
|