3.C#编程学习——窗体二
使用Run方法来自动使窗体成为可见的。自动使窗体成为可见的。
Run函数
源码如下:
usingSystem.Windows.Forms;
classRunFormBetter
{
publicstaticvoid Main()
{
Form form = newForm();
form.Text = "My Very Own Form";
Application.Run(form);
}
}
Application.Run使程序进入了一个消息循环。
窗体属性
usingSystem.Drawing;
usingSystem.Windows.Forms;
classFormProperties
{
publicstaticvoid Main()
{
Form form = newForm();
form.Text = "Form Properties";
form.Width *= 2;
form.Height /= 2;
form.FormBorderStyle = FormBorderStyle.FixedSingle;
form.MaximizeBox = false;
form.Cursor = Cursors.Hand;
form.StartPosition = FormStartPosition.CenterScreen;
Application.Run(form);
}
}
窗体大小
usingSystem;
usingSystem.Drawing;
usingSystem.Windows.Forms;
classFormSize : Form
{
publicstaticvoid Main()
{
Application.Run(newFormSize());
}
public FormSize()
{
Text = "Form Size";
BackColor = Color.White;
}
protectedoverridevoid OnMove(EventArgs ea)
{
Invalidate();
}
protectedoverridevoid OnResize(EventArgs ea)
{
Invalidate();
}
protectedoverridevoid OnPaint(PaintEventArgs pea)
{
Graphics grfx = pea.Graphics;
string str = "Location: "+ Location + "\n"+
"Size: " + Size + "\n" +
"Bounds: " + Bounds + "\n" +
"Width: " + Width + "\n" +
"Height:" + Height + "\n" +
"Left: " + Left + "\n" +
"Top: " + Top + "\n" +
"Right: " + Right + "\n" +
"Bottom: " + Bottom + "\n\n" +
"DesktopLocation: " + DesktopLocation + "\n" +
"DesktopBounds: " + DesktopBounds + "\n\n" +
"ClientSize: " + ClientSize + "\n" +
"ClientRectangle: " + ClientRectangle;
grfx.DrawString(str, Font, Brushes.Black, 0, 0);
}
}
从Control继承而来的From对象有14个属性。