因为客户要求程序要在浏览器上运行,但是这些信息(这个程序只在政府某部门内部使用)并不需要公开,所以我们选择使用Windows应用程序,并将该程序嵌入到网页中。。。。
     就我个人做的这部分简单的说下,我负责的是在地图上画标注(“标注”在这里指的是小图标,以后都使用这个定义),对应于不同的情况,需要画出不同的标注,对于该标注需要有拖拽功能并且需要将最后的位置记录下来,以便下次载入时,会显示在上次修改的位置,修改该图标对应的信息,删除该标注,查看该标注的当前信息以及历史信息等。这里先介绍下,控件的拖拽,其原理就是让控件的位置随鼠标一起移动,鼠标移动多少像素那么控件就移动多少,那么接下来事情就很简单了。为了以后方便复用,我封装了一个类,拖拽控件直接调用这个类就成了!
 调用的代码如下:
 using System;
using System; using System.Collections.Generic;
using System.Collections.Generic; using System.ComponentModel;
using System.ComponentModel; using System.Drawing;
using System.Drawing; using System.Data;
using System.Data; using System.Text;
using System.Text; using System.Windows.Forms;
using System.Windows.Forms;
 namespace WinControlLib
namespace WinControlLib

 {
{ public partial class UserControl4 : UserControl
    public partial class UserControl4 : UserControl
 
     {
{
 public UserControl4()
        public UserControl4()
 
         {
{ InitializeComponent();
            InitializeComponent();
 DragControlClass obj=new DragControlClass(button1);
            DragControlClass obj=new DragControlClass(button1);
 }
        }



 }
    } }
}
核心部分是下面这个类:
 using System;
using System; using System.Collections.Generic;
using System.Collections.Generic; using System.Text;
using System.Text; using System.Windows.Forms;
using System.Windows.Forms;
 namespace WinControlLib
namespace WinControlLib

 {
{ public class DragControlClass
    public class DragControlClass
 
     {
{ //待拖动的控件
        //待拖动的控件 private Control m_Control;
        private Control m_Control; //鼠标按下时的x,y坐标
        //鼠标按下时的x,y坐标 private int m_X;
        private int m_X; private int m_Y;
        private int m_Y; public DragControlClass(Control control)
        public DragControlClass(Control control) 
 
         {
{ m_Control = control;
            m_Control = control; m_Control.MouseDown += new MouseEventHandler(control_MouseDown);
            m_Control.MouseDown += new MouseEventHandler(control_MouseDown); m_Control.MouseMove += new MouseEventHandler(contro_MouseMove);
            m_Control.MouseMove += new MouseEventHandler(contro_MouseMove); }
        } private void control_MouseDown(object sender, MouseEventArgs e)
        private void control_MouseDown(object sender, MouseEventArgs e)
 
         {
{ m_X = e.X;
            m_X = e.X; m_Y = e.Y;
            m_Y = e.Y; }
        } private void contro_MouseMove(object sender, MouseEventArgs e)
        private void contro_MouseMove(object sender, MouseEventArgs e)
 
         {
{ if (e.Button == MouseButtons.Left)
            if (e.Button == MouseButtons.Left)
 
             {
{ int x = e.X - m_X;
                int x = e.X - m_X; int y = e.Y - m_Y;
                int y = e.Y - m_Y; this.m_Control.Left += x;
                this.m_Control.Left += x; this.m_Control.Top += y;
                this.m_Control.Top += y;
 }
            } }
        } }
    } }
}
虽然这个类代码不多,却可以节省我们很多的时间,减少很多的重复工作量,这个类可以拖拽继承自System.Windows.Form.Control的控件 ,先说到这里,希望对大家有用。