c#窗体一些功能代码

有些代码现在也不是很懂

1.拖动界面

 //鼠标按住界面拖动
        Point point1;//定义了一个点
        private void Form1_MouseDown_1(object sender, MouseEventArgs e)
        {
            point1 = new Point(-e.X, -e.Y);
        }

        private void Form1_MouseMove_1(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                Point point2 = Control.MousePosition;
                point2.Offset(point1.X, point1.Y);
                Location = point2;
            }
        }

2.移动一个控件的位置

bool isMoveOut;//图片移动操作
        
        private void pictureBox1_MouseEnter_1(object sender, EventArgs e)
        {
            //加号飞出来
            timer1.Enabled = true;
            isMoveOut = true;
            
        }

        private void pictureBox1_MouseLeave_1(object sender, EventArgs e)
        {
            //加号飞回来
            timer1.Enabled = true;
            isMoveOut = false;
            
        }


        private void timer1_Tick(object sender, EventArgs e)
        {
            //加号随时间飞出去
                if (isMoveOut)
                {
                    picMultiUser.Location = new Point(picMultiUser.Location.X + 10, picMultiUser.Location.Y);
                    if (picMultiUser.Location.X >= 258)
                    {
                        timer1.Enabled = false;
                       
                    }

                }
                //加号随时间移回来
                if (!isMoveOut )
                {
                    picMultiUser.Location = new Point(picMultiUser.Location.X - 10, picMultiUser.Location.Y);
                    if (picMultiUser.Location.X <= 190)
                    {
                        timer1.Enabled = false;
                        
                    }
                }
            
        }

 

  • 4
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值