本文整理汇总了C#中System.Windows.Forms.Form.AutoSizeMode属性的典型用法代码示例。如果您正苦于以下问题:C# Form.AutoSizeMode属性的具体用法?C# Form.AutoSizeMode怎么用?C# Form.AutoSizeMode使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类System.Windows.Forms.Form
的用法示例。
在下文中一共展示了Form.AutoSizeMode属性的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);
}