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

                  private bool isMouseDown = false;
                  private Point FormLocation;     //form的location
                  private Point mouseOffset;      //鼠標的按下位置
                  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 閱讀(459) 評論(0)  編輯  收藏 所屬分類: C# WinForm

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

          導(dǎo)航

          統(tǒng)計

          常用鏈接

          留言簿(3)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 大石桥市| 大连市| 察隅县| 临泉县| 天气| 丰城市| 共和县| 江孜县| 山阳县| 修文县| 凭祥市| 濮阳县| 文成县| 康保县| 石屏县| 慈利县| 南雄市| 抚远县| 类乌齐县| 宁城县| 察雅县| 嘉善县| 施甸县| 濮阳县| 吐鲁番市| 大荔县| 根河市| 蓬莱市| 彝良县| 吴桥县| 浦县| 乐至县| 夏河县| 朝阳区| 敦化市| 武夷山市| 个旧市| 彭州市| 汤阴县| 潜山县| 石楼县|