控件仅在面板内部移动 [英] Controls move only inside of panel

查看:57
本文介绍了控件仅在面板内部移动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友,

我正在开发一个小项目,在我的项目中,我有一个面板,该面板内部有一些控件,如图片框,文本框等.当鼠标移动时,我只想在此面板内部移动这些控件.我完成了控件的移动,但它也移到了面板的外部.

我想在移动鼠标时仅在面板内部移动控件.

请回复[已删除紧急情况]

[edit]已删除呼喊声-OriginalGriff [/edit]

Dear Friends,

I am developing one small project, in my project i have one panel, inside of this panel have some controls like picture box, text boxes etc.... I want to move this controls only inside of this panel when the mouse move. I finished to move controls but it is moving outside of my panel also.

I want to move controls only inside of panel when i move mouse.

Please reply [Removed Urgency]

[edit]SHOUTING removed - OriginalGriff[/edit]

推荐答案

要解决此问题,请考虑代码段的面板左侧和顶部值,

可能是以下解决方案为您充分利用了!

To resolve this issue, please consider the panel left and top values for your piece of code,

May be the below solution is use full for you!

if(panel1.Left < e.X)
            Control.Left = e.X;
            if(panel1.Top <e.Y)
            Control.Top = e.Y;


在运行时获取面板底部和面板右侧的值,然后调整边界.

希望你能得到我!

祝您编程愉快:)
Get your panel botton and panel right values in the run time and then adjust the boundaries.

Hope you got me!

Happy coding:)


我们无法设置right和bottom属性值!这些值是只读的,因此我们总是只需要修改Top和Left属性.

希望以下方法对您有用!

取2个面板并将它们放在面板的底部和右侧.
根据您的要求设置topBoundary和rightBoundary.我尝试过这种方法效果很好.

We can''t set right and bottom property values! These values are readonly so we always need to modify Top and Left properties only.

Hope the below approach is useful for you!

Take 2 panels and place them in bottom and right side of your panel.
set topBoundary and rightBoundary as per your requirement. I tried this approach is working fine.

int topBoundary;
        int rightBoundary;
        private void Form1_Load(object sender, EventArgs e)
        {
            topBoundary = panel1.Bottom - 60;
            rightBoundary = panel1.Right - 100;
        }

        private void panel1_MouseMove(object sender, MouseEventArgs e)
        {
            checkBox1.Top = e.Y;
            checkBox1.Left = e.X;
        }

        private void panel2_MouseEnter(object sender, EventArgs e)
        {
            checkBox1.Top = topBoundary;
        }

        private void panel3_MouseEnter(object sender, EventArgs e)
        {
            checkBox1.Left = rightBoundary;
        }


这篇关于控件仅在面板内部移动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆