개인 코드 라이브러리의 C#이동식 버튼 "관련 코드"

1547 단어 C#
Technorati 태그:
C# ,
이동식 코드 ,
누름단추
        #region      “    ”



        Point mouse_offset;

        private void Button_MouseDown(object sender , MouseEventArgs e)

        {

            mouse_offset = e.Location; //        “  ”         mouse_offset

        }



        private void Button_MouseMove(object sender , MouseEventArgs e)

        {



            if ( e.Button == MouseButtons.Left )

            {

                //                  。

                int left = PointToClient(Control.MousePosition).X - mouse_offset.X;

                int top = PointToClient(Control.MousePosition).Y - mouse_offset.Y;

                

                //      

                if(left<0)

                    left=0;

                if ( left > this.Width )

                    left = this.Width - ( (Button)sender ).Width;



                //      

                if ( top < 0 )

                    top = 0;

                if ( top > this.Height )

                    top = this.Height - ( (Button)sender ).Height;



                

                ( (Button)sender ).Left = left;

                ( (Button)sender ).Top = top;

            }

        }



        #endregion

좋은 웹페이지 즐겨찾기