Limit the size of a custom control (C # .net)

I do user control in MS Visual C #, and there is one thing that I just cannot find the answer to:

How to limit the size, the size of which can be changed when viewing?

For a clear example of what I'm asking, the built-in TrackBar control can only be enlarged, not taller, and displays the resize squares on the left and right in design mode. Is there a way to replicate this for a user control?

I tried setting the MinimumSize and MaximumSize values ​​in the constructor for my control, but this does not produce perfect results.

+3
source share
3 answers

, ( / /) , , , .

, . , , , ControlDesigner, , , DesignerAttribute, typeof(IDesigner) ( ControlDesigner- ).



ControlDesigner
Visual Studio.NET

, TrackBar, , ControlDesigner.SelectionRules. ( , ), , ( ). , , , vai SetBoundsCore.

+3

, Control.SetBoundsCore, .

+1

, MaximunSize MinimumSize . , , , , .

:

MinumumSize MaximumSize, net , .

private Size maxSize = new Size(100, 5);
public override Size MaximumSize
{
    get { return base.MaximumSize; }
    set { base.MaximumSize = maxSize; }
}

:

public bool ShouldSerializeMaximumSize()
{
    return false;
}

private void ResetMaximumSize()
{
    me.MaximumSize = maxSize;
}

Windows Forms Desinger: http://msdn.microsoft.com/en-us/library/53b8022e.aspx

+1

Source: https://habr.com/ru/post/1751208/


All Articles