版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Ming_5257/article/details/82083584
机房重构已经进行了半个月了,刚开始的时候是很期待的,因为这次是C#语言的重构,很想看看面向对象技术在机房重构的应用。
这次机房一边实现功能,一边进行优化。
1.对主窗体的优化
1.首先主窗体没有采用之前的敲VB的时候用的MDI窗体,因为MDI窗体优化起来比较死板。所以这次用的就是普通窗体。
2.首先是整个窗体的圆角化,相比于之前的窗体边角进行圆角化之后,感觉更加美观。
using System.Drawing.Drawing2D;
public void SetWindowRegion()
{
System.Drawing.Drawing2D.GraphicsPath FormPath;
FormPath = new System.Drawing.Drawing2D.GraphicsPath();
Rectangle rect = new Rectangle(0, 0, this.Width, this.Height);
FormPath = GetRoundedRectPath(rect, 10);
this.Region = new Region(FormPath);
}
private GraphicsPath GetRoundedRectPath(Rectangle rect, int radius)
{
int diameter = radius;
Rectangle arcRect = new Rectangle(rect.Location, new Size(diameter, diameter));
GraphicsPath path = new GraphicsPath();
// 左上角
path.AddArc(arcRect, 180, 90);
// 右上角
arcRect.X = rect.Right - diameter;
path.AddArc(arcRect, 270, 90);
// 右下角
arcRect.Y = rect.Bottom - diameter;
path.AddArc(arcRect, 0, 90);
// 左下角
arcRect.X = rect.Left;
path.AddArc(arcRect, 90, 90);
path.CloseFigure();//闭合曲线
return path;
}
//这个代码写在需要进行圆角化的窗体的Resize事件中
private void frmStudentUI_Resize(object sender, EventArgs e)
{
SetWindowRegion();
}
2、菜单栏
菜单栏采用工具ToolStrip。这个工具栏非常灵活,在里面可以添加标签框,还有下拉菜单,还有按钮。
3、容器
容器主要用了GroupBox,还有panel。
panel容器的主要作用是将其他窗体状态里面。这样普通窗体也就有了父窗体类似的功能。
frmStudentInfo frmstudentinfo = new frmStudentInfo();//实例化窗体
frmstudentinfo.TopLevel = false;
frmstudentinfo.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;//将窗体设置为无边框
frmstudentinfo.WindowState = FormWindowState.Maximized;//窗体打开后默认最大化
frmpanel.Controls.Add(frmstudentinfo);//将要打开的窗体放进容器中
frmstudentinfo.BackColor = this.BackColor;
frmstudentinfo.Show();//打开窗体
未完待续……