C#e位置...................................... [英] C# The e Location......................................

查看:110
本文介绍了C#e位置......................................的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码

this is my code

private void panel2_MouseClick(object sender, MouseEventArgs e)
    {

        Label newlabel = new Label();
        panel2.Controls.Add(newlabel);
        newlabel.Text = "0";
        newlabel.Location = new Point (e.Location.X, 7);

    }



出于某种原因,当我像在中间那样单击时会出现一个标签,但是当我在新标签上单击鼠标右键时,不会产生新标签,它们只会从左侧产生,有人可以帮忙吗?



for some reason when I click like in the middle a label spawns but when I click right from the new label, a new label doesn''t spawn, they only spawn from the left, can anyone plz help?

推荐答案

这是因为一个标签隐藏了另一个标签.添加此行newlabel.Size=new Size(10,15);定义标签的大小,或者在添加新标签之前删除已添加的标签.
That is because of one label hiding another. Add this line newlabel.Size=new Size(10,15); to define a size for the label or else remove the labels already added before adding a new one.


首先,当您单击其他控件时,例如新创建的Label,它将在分派到面板之前消耗您的事件.创建新事件时,请考虑将其添加到面板的其他子级.

另一个原因是:如果单击右侧的面板,则可以在面板的右侧剪切新标签.当您对如此简单的事情感到困惑时,请始终使用调试器:它会向您显示是否触发了事件以及您创建的对象的所有参数.

您的代码似乎没有任何应用程序,但据我了解:这只是实验.

—SA
First, when you click on some other Control, such as newly created Label, it will consume your event before it is dispatched to your Panel. Consider adding new event to other children of the panel as you created them.

Another reason is this: new label can be clipped by the right side of your panel if you click on the right side. Always use the debugger when you''re puzzled with such simple things: it will show your you if the event is fired or not and all the parameters of the object you create.

You code does not seem to have any application, but I understand: this is just experimenting.

—SA


这篇关于C#e位置......................................的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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