在父容器中移动标签 [英] moving label in parent container

查看:44
本文介绍了在父容器中移动标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好

i有2个标签和一个图片框

2个标签将图片框作为父母

i想要将label1移动到label2位置

i使用以下代码



hi there
i have 2 labels and a picturebox
the 2 labels have the picturebox as parent
i want to move label1 to label2 location
i use the following code

private void Form1_Load(object sender, EventArgs e)
        {
            label2.Text = "stop here         ";
            make_item_transparent(label1, pictureBox1);
            make_item_transparent(label2, pictureBox1);
            
        }
        private void marquee_label(Label l)
        {
            if (l.Left > label2.Location.Y)
                l.Left = 0;
            else
                l.Left = l.Left + 1;
        }

        private void make_item_transparent(Label label, PictureBox bar)
        {
            var pos = this.PointToScreen(label.Location);
            pos = bar.PointToClient(pos);
            label.Parent = bar;
            label.Location = pos;
            label.BackColor = Color.Transparent;
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            marquee_label(label1);
        }







i肯定是对的

但是我可能错过了什么

label1没有移动到label2的确切位置







帮帮我PLZ



thanx很多



代码块固定 - OriginalGriff [ / edit]




i am sure its right
but i may miss something
label1 doesn't move to the exact location of label2



help me plz

thanx alot

[edit]Code block fixed - OriginalGriff[/edit]

推荐答案

marquee_label的逻辑搞砸了。



您正在比较label1。左(基本上是X坐标)到label2.Location.Y(基本上是Y坐标或label2.Top)。因此,如果左侧位置大于label2.Top它会被重新抨击为0.



我相信如果你想要你想对label2.Left进行比较它们重叠,或者label2.Left - label1.Width,如果你想让它们相互对立。
The logic of marquee_label is messed up.

You're comparing label1.Left (basically the X-coordinate) to label2.Location.Y (basically the Y-coordinate or label2.Top). Therefore, if that Left position is greater than label2.Top it gets slammed back to 0.

I believe you want to do that comparison against label2.Left if you want them to overlap, or label2.Left - label1.Width if you want them to be up against each other.


这篇关于在父容器中移动标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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