开发者

Custom control components setting position C#

开发者 https://www.devze.com 2023-03-24 03:55 出处:网络
I have custom control - using Win Forms, that contains four TextBoxes, all have property to turn them off or on - I just setting visible parameter on them.

I have custom control - using Win Forms, that contains four TextBoxes, all have property to turn them off or on - I just setting visible parameter on them. I would like to change size and position of the custom control - for example, when I turn off first textbox, I would like to change position of all 3 componets below him, to get them higher. Of course, I would like to work it with every TextBox - every TextBoxes, below TextBox I am changing position, should change po开发者_StackOverflow中文版sition.

I cant achieve it with changing of Position of TextBox in its own property - I can ask TextBox on top of me, if its property is set to on or of, but it dont works, because I dont know order of setting property in the application.

I can change position of TextBox below me - in the property of Top textbox, but I can do that with only one TextBox below, I dont know and cant find out, if two TextBoxes below are not off and fourth TextBox should be on position of second.

I cant change it by using some variable - when I change it, other TextBoxes dont care about it and they have set their position before.

So do you have any idea how could I achieve it?


The FlowLayoutPanel is designed for exactly this kind of behavior. Place your textboxes inside a FlowLayoutPanel, and then when you set the visible property of one or more of them to false, the other textboxes will automatically move up (or over if that's how you have it set up).


If you want for some reason do it manually, just make a chain of controls.

public class CustomTextBox
{
public CustomTextBox(CustomTextBox previousSibling)
{
    PreviousSibling = previousSibling;
}

public CustomTextBox PreviousSibling { get; private set; }

public CustomTextBox PreviousVisibleSibling
{
    get
    {
        if (PreviousSibling == null)
        {
            return null;
        }
        return PreviousSibling.Visible ? PreviousSibling : PreviousSibling.PreviousVisibleSibling
    }
}

}

0

精彩评论

暂无评论...
验证码 换一张
取 消