编译后,继承的用户控件的位置重置 [英] Inherited user controls' positions reset after compiling

查看:91
本文介绍了编译后,继承的用户控件的位置重置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我构建了一个UserControl(例如MyBaseControl),它具有广义的行为,包括锚定和停靠十几个控件,包括分割器和锚定在底部的多行TextBox。然后我创建一个新的
'继承的用户控件'(例如MyDerivedControl),我在这里定制它,例如调整大小。当我在设计器中调整MyDerivedControl的大小时,控件会按预期移动。但是,在我编译应用程序的那一刻,MyBaseControl
控件的位置被搞砸了。

In my application I have built a UserControl (e.g. MyBaseControl) that has generalized behaviour including anchoring and docking with a dozen or so controls including splitters and a multi-line TextBox which is anchored on the bottom. I then create a new 'Inherited User Control' (eg MyDerivedControl), where I am customizing this such as resizing. When I resize MyDerivedControl in the designer, the controls move around as expected. However, the moment I compile the application, the placement of the MyBaseControl controls gets screwed up.

好像它与InitializeCompenent()中的操作顺序有关。或类似的东西。我和其他非MS论坛一起看过这些文章都无济于事。

It seems like it has to do with the order of operations in InitializeCompenent() or something like that. I have looked at these articles to no avail, along with other non-MS forums.

用户控件在重建后不断重置属性

选项卡面板问题内的用户控件

我创建了一个简单的示例应用程序,此问题仍然存在,在本例中为Label和TextBox出现在多行TextBox下方的控件最终会移位。在我上面的实际程序中,我也看到TextBox奇怪地调整了
的大小。我希望解决这个更简单的案例能够解释我的其他问题。

I have created a simple sample application where this problem persists, where in this case the Label and TextBox controls that appear below the multi-line TextBox ends up getting shifted in position. In my actual program above I also see the TextBox getting resized strangely. I am hoping that solving this more simple case will shed light on my other problems.

我希望有人有一个具体的解决方案。



以下是解决方案:

https://ufile.io/qzc1v

I am hoping someone has a concrete solution.

Here is the solution:
https://ufile.io/qzc1v

推荐答案

嗨大卫,

我测试了你用OneDrive提供的项目,主要的问题是你没有重置MyDerivedControl类中标签的位置,因此当您调整MyDerivedControl的大小时,标签的位置仍与MyBaseControl
相同:

I tested the project you provided with OneDrive, the main problem is that you do not reset the location for the label in the MyDerivedControl class, so when you resize the MyDerivedControl, the location of the label is still same with MyBaseControl that:

    this.label1.Location = new System.Drawing.Point(4, 119);//in MyBaseControl.Designer.cs

所以我建议你重置一下使用以下步骤在 MyDerivedControl类中标记:

So I suggest you reset the location for the label in the MyDerivedControl class with the following steps:

1,修改访问级别MyBaseControl.Desi中私有到受保护的标签gner.cs:

1, Modify the access level of the label from private to protected in MyBaseControl.Designer.cs:

        //private System.Windows.Forms.Label label1;
        protected System.Windows.Forms.Label label1;
        protected System.Windows.Forms.TextBox txtAnchored;

2,重置 MyDerivedControl类的构造函数中标签的位置:

        public MyDerivedControl()
        {
            InitializeComponent();
            this.label1.Location = new System.Drawing.Point(4, this.txtAnchored.Height + this.txtAnchored.Location.Y);
        }

然后你可以调整  MyDerivedControl和t 他的相对位置不会再改变。

Then you can resize the MyDerivedControl and the relative position will not change again.

希望这会有所帮助!

最好的问候,

Stanly


这篇关于编译后,继承的用户控件的位置重置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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