开发者

User Controls design time support

We have a class that automatically scales all the controls on a form when the user resizes the form. All that is needed is to instantiate the class in the form once on form load (set and forget).

The problem is that you have to pass the original designer's dimensions on form load. This means it has to be hardcoded, and must be manually changed if the designer changes the size on the form during design t开发者_如何学Cime.

I am thinking of changing this to be a component that can be dropped on the form. I am thinking that that will allow me to grab the designer's settings as it happens in InitializeComponents(), so that you don't have to grab it later on form load.

However, I have no experience with UserControls.

I am not looking to set a default hardcoded property value at design time, but rather I want it to be set to the size of the form's at design time, and as it changes in InitializeComponents() for the form it will change for this control.

Can anyone point me to some tutorial that will tell me about design time support, and how to do this?

I am also looking (less important) to restrict this control to be dropped only on a Form.

EDIT: I am not looking for a solution for the scalling. I want to know how to set properties of a user control at design time to be bound to another control's property (change as that control changes) at design time.


As per @Blorgbeard's comment - it sounds you should probably be using anchoring/docking along with some of the nice layout controls (FlowPanel/TableLayoutPanel). Alternatively, more complex sizing operations can be done in SetBoundsCore which I believe will give you sizing support at both runtime and design time:

    protected override void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified)
    {
        // TODO: override parameter values (if in the specified set) with whatever values
        // that you calculate them to be. E.g. lock it as fixed width

        base.SetBoundsCore(x, y, width, height, specified);

        // TODO: update the size of child controls accordingly. 
    }

Though I would say that nowadays most "complex sizing operations" (e.g. scaling child controls as a % of total size) should be manageable with the TableLayoutPanel.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜