AutoSizeMode 열거형

정의

컨트롤의 AutoSize 속성이 활성화될 때 컨트롤이 동작하는 방법을 지정합니다.

public enum class AutoSizeMode
public enum AutoSizeMode
type AutoSizeMode = 
Public Enum AutoSizeMode
상속
AutoSizeMode

필드

GrowAndShrink 0

컨트롤이 내용에 따라 확장되거나 축소됩니다. 컨트롤의 크기는 수동으로 조정할 수 없습니다.

GrowOnly 1

필요에 따라 컨트롤이 내용에 맞게 확장되기는 하지만 컨트롤의 Size 속성 값보다 작은 크기로 축소되지는 않습니다. 폼의 크기를 조정할 수 있지만 폼에 포함된 컨트롤이 숨겨질 만큼 폼을 작게 만들 수는 없습니다.

예제

다음 코드 예제에서는 내용에 맞게 자동으로 크기를 조정 하는 코드를 사용 하 여 만든 폼을 보여 줍니다. 때 실행 되는, 양식에 표시 됩니다는 Label, TextBox URL을 입력 하는 것에 대 한 및 Button 사용자의 기본 웹 브라우저 내에서 해당 URL을 표시 합니다. 코드 예제에서는 FlowLayoutPanel 레이아웃에 포함 된 뒤 다른 컨트롤과 설정 합니다 AutoSizeAutoSizeMode 성장 시키고 해당 폼의 내용에 맞게 축소 합니다.

private void Form1_Load(object sender, EventArgs e)
{
    this.AutoSize = true;
    this.AutoSizeMode = AutoSizeMode.GrowAndShrink;
    this.Text = "URL Opener";

    flowPanel = new FlowLayoutPanel();
    flowPanel.AutoSize = true;
    flowPanel.AutoSizeMode = AutoSizeMode.GrowAndShrink;
    this.Controls.Add(flowPanel);

    urlLabel = new Label();
    urlLabel.Name = "urlLabel";
    urlLabel.Text = "URL:";
    urlLabel.Width = 50;
    urlLabel.TextAlign = ContentAlignment.MiddleCenter;
    flowPanel.Controls.Add(urlLabel);

    urlTextBox = new TextBox();
    urlTextBox.Name = "urlTextBox";
    urlTextBox.Width = 250;
    flowPanel.Controls.Add(urlTextBox);

    urlButton = new Button();
    urlButton.Name = "urlButton";
    urlButton.Text = "Open URL in Browser";
    urlButton.Click += new EventHandler(urlButton_Click);
    flowPanel.Controls.Add(urlButton);
}

void urlButton_Click(object sender, EventArgs e)
{
    try
    {
        Uri newUri = new Uri(urlTextBox.Text);
    }
    catch (UriFormatException uriEx)
    {
        MessageBox.Show("Sorry, your URL is malformed. Try again. Error: " + uriEx.Message);
        urlTextBox.ForeColor = Color.Red;
        return;
    }
    
    // Valid URI. Reset any previous error color, and launch the URL in the 
    // default browser.
    // NOTE: Depending on the user's settings, this method of starting the
    // browser may use an existing window in an existing Web browser process.
    // To get around this, start up a specific browser instance instead using one of
    // the overloads for Process.Start. You can examine the registry to find the
    // current default browser and launch that, or hard-code a specific browser.
    urlTextBox.ForeColor = Color.Black;
    Process.Start(urlTextBox.Text);
}
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Me.AutoSize = True
    Me.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink
    Me.Text = "URL Opener"

    flowPanel = New FlowLayoutPanel()
    flowPanel.AutoSize = True
    flowPanel.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink
    Me.Controls.Add(flowPanel)

    urlLabel = New Label()
    urlLabel.Name = "urlLabel"
    urlLabel.Text = "URL:"
    urlLabel.Width = 50
    urlLabel.TextAlign = ContentAlignment.MiddleCenter
    flowPanel.Controls.Add(urlLabel)

    urlTextBox = New TextBox()
    urlTextBox.Name = "urlTextBox"
    urlTextBox.Width = 250
    flowPanel.Controls.Add(urlTextBox)

    urlButton = New Button()
    urlButton.Name = "urlButton"
    urlButton.Text = "Open URL in Browser"
    flowPanel.Controls.Add(urlButton)
End Sub


Private Sub urlButton_Click(ByVal sender As Object, ByVal e As EventArgs) Handles urlButton.Click
    Try
        Dim newUri As New Uri(urlTextBox.Text)
    Catch uriEx As UriFormatException
        MessageBox.Show(("Sorry, your URL is malformed. Try again. Error: " + uriEx.Message))
        urlTextBox.ForeColor = Color.Red
        Return
    End Try

    ' Valid URI. Reset any previous error color, and launch the URL in the 
    ' default browser.
    ' NOTE: Depending on the user's settings, this method of starting the
    ' browser may use an existing window in an existing Web browser process.
    ' To get around this, start up a specific browser instance instead using one of
    ' the overloads for Process.Start. You can examine the registry to find the
    ' current default browser and launch that, or hard-code a specific browser.
    urlTextBox.ForeColor = Color.Black
    Process.Start(urlTextBox.Text)
End Sub

설명

컨트롤에 대 한 얻을 수 있는 동일한 동작이 생성 GrowAndShrink 값을 설정 합니다 AutoSize 속성을 사용 되었지만

AutoSizeMode 속성 MinimumSize 하 고 MaximumSize 속성은 적용 되지만 현재 값을 Size 속성은 무시 됩니다.

적용 대상

추가 정보