為工具欄添加鼠標(biāo)的“按下、移動、松開”三個事件,用來移動窗體

                  private bool isMouseDown = false;
                  private Point FormLocation;     //form的location
                  private Point mouseOffset;      //鼠標(biāo)的按下位置
                  private void toolStrip1_MouseDown(object sender, MouseEventArgs e)
                  {
                      if (e.Button == MouseButtons.Left)
                      {
                          isMouseDown = true;
                          FormLocation = this.Location;
                          mouseOffset = Control.MousePosition;
                      }

                  }

                  private void toolStrip1_MouseUp(object sender, MouseEventArgs e)
                  {
                      isMouseDown = false;
                  }

                  private void toolStrip1_MouseMove(object sender, MouseEventArgs e)
                  {
                      int _x = 0;
                      int _y = 0;
                      if (isMouseDown)
                      {
                          Point pt = Control.MousePosition;
                          _x = mouseOffset.X - pt.X;
                          _y = mouseOffset.Y - pt.Y;

                          this.Location = new Point(FormLocation.X - _x, FormLocation.Y - _y);
                      }

                  }

          posted on 2012-04-27 16:50 SkyDream 閱讀(465) 評論(0)  編輯  收藏 所屬分類: C# WinForm

          <2012年4月>
          25262728293031
          1234567
          891011121314
          15161718192021
          22232425262728
          293012345

          導(dǎo)航

          統(tǒng)計

          常用鏈接

          留言簿(3)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 锡林浩特市| 扎兰屯市| 邮箱| 平顶山市| 开化县| 水富县| 博客| 开鲁县| 方城县| 永胜县| 西丰县| 姜堰市| 丰城市| 东城区| 安塞县| 沅江市| 六安市| 辽宁省| 鞍山市| 巴中市| 宿州市| 白朗县| 竹溪县| 临夏市| 鄱阳县| 温泉县| 六枝特区| 木兰县| 阳春市| 隆林| 瑞昌市| 肇庆市| 普兰县| 河西区| 大城县| 龙南县| 庐江县| 呼和浩特市| 衡东县| 万安县| 洮南市|