在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
阅读全文:http://www.cckan.net/forum.php?mod=viewthread&tid=363
导读部分
一周要过去了,本来打算多写点的,还是时间不够啊,费话不多说,开始写代码,今天 我们要做的是一个窗体,这个窗体是基于窗体FormBase,就是我们上一节所说到的 基窗体FormBase与基用户控件FormBase1的实现 里面的FormBase窗体, 有关 FormBase的实现还请大家去看相应文章,这里不再做过多的说明。 我们先看一下实现的效果吧,第一张图是 实现,第二张是正常使用时的样子
下面看一下怎么实现吧, 第一步,创建窗体 我们右键单击文件夹选择添加窗体就行了,名称当时是“ FunctionFormBase”,然后单击确定,我们的窗体的大小不需要做任何的修改,那是因为那是继承自窗体FormBase而来的,上节我们讲过了, 他的大小是固定的,所以在这里不用再做设置; 只要这样一行继承的语句就OK了
/// <summary>
/// FunctionFormBase基窗体 /// 是构造EntryForm和SkinForm窗体的基础 /// </summary> public partial class FunctionFormBase : FormBase
第二步,窗体的UI布局实现 我们可以看到第一张图,就是窗体的UI布局,相信大家一看就能明白是怎么实现 的,我还是大致的说一下是怎么会事吧。窗体一共是三个Panel 代码实现为:
代码
//
// ptbTopMiddle // this.ptbTopMiddle.Dock = System.Windows.Forms.DockStyle.Fill; this.ptbTopMiddle.Location = new System.Drawing.Point(10, 0); this.ptbTopMiddle.Name = "ptbTopMiddle"; this.ptbTopMiddle.Size = new System.Drawing.Size(669, 31); this.ptbTopMiddle.TabIndex = 2; this.ptbTopMiddle.TabStop = false; // pnlBackGroup // this.pnlBackGroup.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.pnlBackGroup.Dock = System.Windows.Forms.DockStyle.Fill; this.pnlBackGroup.Location = new System.Drawing.Point(0, 31); this.pnlBackGroup.Name = "pnlBackGroup"; this.pnlBackGroup.Size = new System.Drawing.Size(689, 444); this.pnlBackGroup.TabIndex = 9; // // ptbBottomMiddle // this.ptbBottomMiddle.Dock = System.Windows.Forms.DockStyle.Fill; this.ptbBottomMiddle.Location = new System.Drawing.Point(10, 0); this.ptbBottomMiddle.Name = "ptbBottomMiddle"; this.ptbBottomMiddle.Size = new System.Drawing.Size(669, 37); this.ptbBottomMiddle.TabIndex = 3;
在ptbTopMiddle左面是一个lblText 右面是两个CommandButton,这个控件是 我自己写的实现方法后面会提到这里不做详细说明,在ptbTopMiddle的两端分别是两个Panel,用来实现窗体的边角,和低部的ptbBottomMiddle 形式是一样的,下面我给出这些控件的初始代码
代码
// // pnlRight // this.pnlRight.Controls.Add(this.ptbRight); this.pnlRight.Dock = System.Windows.Forms.DockStyle.Right; this.pnlRight.Location = new System.Drawing.Point(687, 31); this.pnlRight.Name = "pnlRight"; this.pnlRight.Size = new System.Drawing.Size(2, 444); this.pnlRight.TabIndex = 7; // // ptbRight // this.ptbRight.Dock = System.Windows.Forms.DockStyle.Fill; this.ptbRight.Location = new System.Drawing.Point(0, 0); this.ptbRight.Name = "ptbRight"; this.ptbRight.Size = new System.Drawing.Size(2, 444); this.ptbRight.TabIndex = 0; this.ptbRight.TabStop = false; // // pnlLeft // this.pnlLeft.Controls.Add(this.ptbLeft); this.pnlLeft.Dock = System.Windows.Forms.DockStyle.Left; this.pnlLeft.Location = new System.Drawing.Point(0, 31); this.pnlLeft.Name = "pnlLeft"; this.pnlLeft.Size = new System.Drawing.Size(2, 444); this.pnlLeft.TabIndex = 6; // // ptbLeft // this.ptbLeft.Dock = System.Windows.Forms.DockStyle.Fill; this.ptbLeft.Location = new System.Drawing.Point(0, 0); this.ptbLeft.Name = "ptbLeft"; this.ptbLeft.Size = new System.Drawing.Size(2, 444); this.ptbLeft.TabIndex = 0; this.ptbLeft.TabStop = false; // // ptbBottomRight // this.ptbBottomRight.Dock = System.Windows.Forms.DockStyle.Right; this.ptbBottomRight.Location = new System.Drawing.Point(679, 0); this.ptbBottomRight.Name = "ptbBottomRight"; this.ptbBottomRight.Size = new System.Drawing.Size(10, 37); this.ptbBottomRight.TabIndex = 2; this.ptbBottomRight.TabStop = false; // // ptbBottomLeft // this.ptbBottomLeft.Dock = System.Windows.Forms.DockStyle.Left; this.ptbBottomLeft.Location = new System.Drawing.Point(0, 0); this.ptbBottomLeft.Name = "ptbBottomLeft"; this.ptbBottomLeft.Size = new System.Drawing.Size(10, 37); this.ptbBottomLeft.TabIndex = 0; this.ptbBottomLeft.TabStop = false; this.pnlBackGroup.TabIndex = 9; // // lblText // this.lblText.BackColor = System.Drawing.Color.Transparent; this.lblText.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.lblText.Location = new System.Drawing.Point(27, 3); this.lblText.Name = "lblText"; this.lblText.Size = new System.Drawing.Size(273, 24); this.lblText.TabIndex = 5; this.lblText.Text = "Text"; this.lblText.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; this.lblText.MouseMove += new System.Windows.Forms.MouseEventHandler(this.Caption_MouseMove); this.lblText.MouseUp += new System.Windows.Forms.MouseEventHandler(this.caption_MouseUp); // // lblText // this.lblText.BackColor = System.Drawing.Color.Transparent; this.lblText.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.lblText.Location = new System.Drawing.Point(27, 3); this.lblText.Name = "lblText"; this.lblText.Size = new System.Drawing.Size(273, 24); this.lblText.TabIndex = 5; this.lblText.Text = "Text"; this.lblText.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; this.lblText.MouseMove += new System.Windows.Forms.MouseEventHandler(this.Caption_MouseMove); this.lblText.MouseUp += new System.Windows.Forms.MouseEventHandler(this.caption_MouseUp); // // pnlCaption // this.pnlCaption.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.pnlCaption.Controls.Add(this.lblText); this.pnlCaption.Controls.Add(this.btnMin); this.pnlCaption.Controls.Add(this.btnClose); this.pnlCaption.Controls.Add(this.ptbTopMiddle); this.pnlCaption.Controls.Add(this.ptbTopRight); this.pnlCaption.Controls.Add(this.ptbTopLeft); this.pnlCaption.Dock = System.Windows.Forms.DockStyle.Top; this.pnlCaption.Location = new System.Drawing.Point(0, 0); this.pnlCaption.Name = "pnlCaption"; this.pnlCaption.Size = new System.Drawing.Size(689, 31); this.pnlCaption.TabIndex = 5; // // btnMin // this.btnMin.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.btnMin.BackColor = System.Drawing.Color.Transparent; this.btnMin.ImageTransparentColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(0)))), ((int)(((byte)(255))))); this.btnMin.Location = new System.Drawing.Point(610, 0); this.btnMin.MouseDownImage = null; this.btnMin.MouseMoveImage = null; this.btnMin.Name = "btnMin"; this.btnMin.NormalImage = null; this.btnMin.Size = new System.Drawing.Size(31, 22); this.btnMin.TabIndex = 4; this.btnMin.ToolTip = "关闭"; this.btnMin.Click += new System.EventHandler(this.btnMin_Click); // // btnClose // this.btnClose.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.btnClose.ImageTransparentColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(0)))), ((int)(((byte)(255))))); this.btnClose.Location = new System.Drawing.Point(642, 0); this.btnClose.MouseDownImage = null; this.btnClose.MouseMoveImage = null; this.btnClose.Name = "btnClose"; this.btnClose.NormalImage = null; this.btnClose.Size = new System.Drawing.Size(37, 22); this.btnClose.TabIndex = 4; this.btnClose.ToolTip = "关闭"; this.btnClose.Click += new System.EventHandler(this.btnClose_Click); // // ptbTopMiddle // this.ptbTopMiddle.Dock = System.Windows.Forms.DockStyle.Fill; this.ptbTopMiddle.Location = new System.Drawing.Point(10, 0); this.ptbTopMiddle.Name = "ptbTopMiddle"; this.ptbTopMiddle.Size = new System.Drawing.Size(669, 31); this.ptbTopMiddle.TabIndex = 2; this.ptbTopMiddle.TabStop = false; this.ptbTopMiddle.MouseMove += new System.Windows.Forms.MouseEventHandler(this.Caption_MouseMove); this.ptbTopMiddle.MouseUp += new System.Windows.Forms.MouseEventHandler(this.caption_MouseUp); // // ptbTopRight // this.ptbTopRight.Dock = System.Windows.Forms.DockStyle.Right; this.ptbTopRight.Location = new System.Drawing.Point(679, 0); this.ptbTopRight.Name = "ptbTopRight"; this.ptbTopRight.Size = new System.Drawing.Size(10, 31); this.ptbTopRight.TabIndex = 1; this.ptbTopRight.TabStop = false; // // ptbTopL |
请发表评论