本文整理匯總了C#中System.Windows.Forms.Form.AutoSize屬性的典型用法代碼示例。如果您正苦於以下問題:C# Form.AutoSize屬性的具體用法?C# Form.AutoSize怎麽用?C# Form.AutoSize使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類System.Windows.Forms.Form
的用法示例。
在下文中一共展示了Form.AutoSize屬性的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Form1_Load
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);
}