频道栏目
读书频道 > 软件开发 > C# > 深入体验C#项目开发
1.5.2 窗体元素设置文件
2013-03-27 13:07:09     我来说两句
收藏   我要投稿

本文所属图书 > 深入体验C#项目开发

C#是当今使用最为频繁的编程语言之一,一直在开发领域占据重要的地位。本书通过10个综合实例的实现过程,详细讲解了C#在实践项目中的综合运用过程。这些项目从作者的学生时代写起,到项目经理结束,一直贯穿于作...  立即去当当网订购

经过 1.5.1 节的设置操作后,项目的窗体界面基本设计完毕。在窗体元素设置文件Form1.Designer.cs内,定义了各窗体控件的具体设置属性,在下面的内容中将分别进行介绍。

1.控制按钮

窗体右侧的各控制按钮控件的功能是控制游戏的进程,例如游戏开始、载入和保存。对应属性的设置代码如下。

// buttonReplay
this.buttonReplay.Location = new System.Drawing.Point(180, 197);
this.buttonReplay.Name = "buttonReplay";
this.buttonReplay.Size = new System.Drawing.Size(75, 23);
this.buttonReplay.TabIndex = 0;
this.buttonReplay.Text = "重新开始";
this.buttonReplay.UseVisualStyleBackColor = true;
this.buttonReplay.Click += new System.EventHandler(this.buttonReplay_Click);
// buttonReview
this.buttonReview.Location = new System.Drawing.Point(180, 338);
this.buttonReview.Name = "buttonReview";
this.buttonReview.Size = new System.Drawing.Size(75, 23);
this.buttonReview.TabIndex = 1;
this.buttonReview.Text = "Re&view";
this.buttonReview.UseVisualStyleBackColor = true;
this.buttonReview.Click += new System.EventHandler(this.buttonReview_Click);
// trackBarReviewSpeed
this.trackBarReviewSpeed.Location = new System.Drawing.Point(180, 292);
this.trackBarReviewSpeed.Maximum = 15;
this.trackBarReviewSpeed.Minimum = 1;
this.trackBarReviewSpeed.Name = "trackBarReviewSpeed";
this.trackBarReviewSpeed.Size = new System.Drawing.Size(75, 42);
this.trackBarReviewSpeed.TabIndex = 2;
this.trackBarReviewSpeed.Value = 1;
this.trackBarReviewSpeed.Scroll += new System.EventHandler(this.trackBar1_Scroll);
// buttonSave
this.buttonSave.Location = new System.Drawing.Point(180, 238);
this.buttonSave.Name = "buttonSave";
this.buttonSave.Size = new System.Drawing.Size(75, 23);
this.buttonSave.TabIndex = 3;
this.buttonSave.Text = "保存";
this.buttonSave.UseVisualStyleBackColor = true;
this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click);
// buttonLoad
this.buttonLoad.Location = new System.Drawing.Point(180, 267);
this.buttonLoad.Name = "buttonLoad";
this.buttonLoad.Size = new System.Drawing.Size(75, 23);
this.buttonLoad.TabIndex = 4;
this.buttonLoad.Text = "载入";
this.buttonLoad.UseVisualStyleBackColor = true;
this.buttonLoad.Click += new System.EventHandler(this.buttonLoad_Click);
// progressBarReview
this.progressBarReview.Location = new System.Drawing.Point(3, 381);
this.progressBarReview.Name = "progressBarReview";
this.progressBarReview.Size = new System.Drawing.Size(252, 17);
this.progressBarReview.TabIndex = 5;

2.窗体菜单

窗体顶部的各菜单都包含对应的菜单项,甚至还包含子菜单项,其功能是对游戏进行控制和设置,并提供游戏的使用和帮助信息。对应各窗体菜单的属性设置代码如下。

// fileToolStripMenuItem
this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.replayToolStripMenuItem,
this.replayExtendedToolStripMenuItem,
this.saveToolStripMenuItem,
this.loadToolStripMenuItem,
this.reviewToolStripMenuItem,
this.toolStripMenuItemLine,
this.exiToolStripMenuItem});
this.fileToolStripMenuItem.Name = "fileToolStripMenuItem";
this.fileToolStripMenuItem.Size = new System.Drawing.Size(41, 32);
this.fileToolStripMenuItem.Text = "&文件";
// replayToolStripMenuItem
this.replayToolStripMenuItem.Name = "replayToolStripMenuItem";
this.replayToolStripMenuItem.Size = new System.Drawing.Size(166, 22);
this.replayToolStripMenuItem.Text = "重新&开始";
this.replayToolStripMenuItem.Click += new System.EventHandler
(this.replayToolStripMenuItem_Click);
// replayExtendedToolStripMenuItem
this.replayExtendedToolStripMenuItem.Name = "replayExtendedToolStripMenuItem";
this.replayExtendedToolStripMenuItem.Size = new System.Drawing.Size(166, 22);
this.replayExtendedToolStripMenuItem.Text = "Replay(Extended)";
this.replayExtendedToolStripMenuItem.Click += new System.EventHandler
(this.replayExtendedToolStripMenuItem_Click);
// saveToolStripMenuItem
this.saveToolStripMenuItem.Name = "saveToolStripMenuItem";
this.saveToolStripMenuItem.Size = new System.Drawing.Size(166, 22);
this.saveToolStripMenuItem.Text = "&Save";
this.saveToolStripMenuItem.Click += new System.EventHandler
(this.saveToolStripMenuItem_Click);
// loadToolStripMenuItem
this.loadToolStripMenuItem.Name = "loadToolStripMenuItem";
this.loadToolStripMenuItem.Size = new System.Drawing.Size(166, 22);
this.loadToolStripMenuItem.Text = "&Load";
this.loadToolStripMenuItem.Click += new System.EventHandler
(this.loadToolStripMenuItem_Click);
// reviewToolStripMenuItem
this.reviewToolStripMenuItem.Name = "reviewToolStripMenuItem";
this.reviewToolStripMenuItem.Size = new System.Drawing.Size(166, 22);
this.reviewToolStripMenuItem.Text = "Re&view";
this.reviewToolStripMenuItem.Click += new System.EventHandler
(this.reviewToolStripMenuItem_Click);
// toolStripMenuItemLine
this.toolStripMenuItemLine.Name = "toolStripMenuItemLine";
this.toolStripMenuItemLine.Size = new System.Drawing.Size(163, 6);
// exiToolStripMenuItem
this.exiToolStripMenuItem.Name = "exiToolStripMenuItem";
this.exiToolStripMenuItem.Size = new System.Drawing.Size(166, 22);
this.exiToolStripMenuItem.Text = "E&xit";
this.exiToolStripMenuItem.Click += new System.EventHandler
(this.exiToolStripMenuItem_Click);
// optionToolStripMenuItem
this.optionToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.styleToolStripMenuItem});
this.optionToolStripMenuItem.Name = "optionToolStripMenuItem";
this.optionToolStripMenuItem.Size = new System.Drawing.Size(65, 32);
this.optionToolStripMenuItem.Text = "&设置选项";
// styleToolStripMenuItem
this.styleToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.style1ToolStripMenuItem,
this.style2ToolStripMenuItem,
this.style3ToolStripMenuItem});
this.styleToolStripMenuItem.Name = "styleToolStripMenuItem";
this.styleToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
this.styleToolStripMenuItem.Text = "&Style";
//
// style1ToolStripMenuItem
this.style1ToolStripMenuItem.Name = "style1ToolStripMenuItem";
this.style1ToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
this.style1ToolStripMenuItem.Tag = "";
this.style1ToolStripMenuItem.Text = "style1";
this.style1ToolStripMenuItem.Click += new System.EventHandler
(this.style1ToolStripMenuItem_Click);
// style2ToolStripMenuItem
this.style2ToolStripMenuItem.Name = "style2ToolStripMenuItem";
this.style2ToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
this.style2ToolStripMenuItem.Text = "style2";
this.style2ToolStripMenuItem.Click += new System.EventHandler
(this.style1ToolStripMenuItem_Click);
// style3ToolStripMenuItem
this.style3ToolStripMenuItem.Name = "style3ToolStripMenuItem";
this.style3ToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
this.style3ToolStripMenuItem.Text = "style3";
this.style3ToolStripMenuItem.Click += new System.EventHandler
(this.style1ToolStripMenuItem_Click);
// helpToolStripMenuItem
this.helpToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.keyboardToolStripMenuItem,
this.aboutToolStripMenuItem});
this.helpToolStripMenuItem.Name = "helpToolStripMenuItem";
this.helpToolStripMenuItem.Size = new System.Drawing.Size(65, 32);
this.helpToolStripMenuItem.Text = "&游戏帮助";
// keyboardToolStripMenuItem
this.keyboardToolStripMenuItem.Name = "keyboardToolStripMenuItem";
this.keyboardToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
this.keyboardToolStripMenuItem.Text = "&操作键";
this.keyboardToolStripMenuItem.Click += new System.EventHandler
(this.keyBoardToolStripMenuItem_Click);
// aboutToolStripMenuItem
this.aboutToolStripMenuItem.Name = "aboutToolStripMenuItem";
this.aboutToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
this.aboutToolStripMenuItem.Text = "&关于";
this.aboutToolStripMenuItem.Click += new System.EventHandler
(this.aboutToolStripMenuItem_Click);
// menuStripMain
this.menuStripMain.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.fileToolStripMenuItem,
this.optionToolStripMenuItem,
this.helpToolStripMenuItem});
this.menuStripMain.Location = new System.Drawing.Point(0, 0);
this.menuStripMain.Name = "menuStripMain";
this.menuStripMain.Size = new System.Drawing.Size(260, 24);
this.menuStripMain.TabIndex = 6;
this.menuStripMain.Text = "menuStrip1";

3.图片列表控件和窗体总体设置

窗体内插入了图片列表控件,其功能是设置游戏的外观显示样式,供用户根据个人喜好进行选择。而窗体总体设置属性的功能是设置窗体Form1的对应属性。上述各窗体选项属性的设置代码如下。

// imageList1
this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer) (resources.GetObject("imageList1.ImageStream")));
this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
this.imageList1.Images.SetKeyName(0, "1");
this.imageList1.Images.SetKeyName(1, "2");
this.imageList1.Images.SetKeyName(2, "3");
this.imageList1.Images.SetKeyName(3, "4");
this.imageList1.Images.SetKeyName(4, "5");
this.imageList1.Images.SetKeyName(5, "6");
this.imageList1.Images.SetKeyName(6, "7");
// imageList2
this.imageList2.ImageStream = ((System.Windows.Forms.ImageListStreamer)
(resources.GetObject("imageList2.ImageStream")));
this.imageList2.TransparentColor = System.Drawing.Color.Transparent;
this.imageList2.Images.SetKeyName(0, "1");
this.imageList2.Images.SetKeyName(1, "2");
this.imageList2.Images.SetKeyName(2, "3");
this.imageList2.Images.SetKeyName(3, "4");
this.imageList2.Images.SetKeyName(4, "5");
this.imageList2.Images.SetKeyName(5, "6");
this.imageList2.Images.SetKeyName(6, "7");
// saveFileDialog1
this.saveFileDialog1.Filter = "youxi records files(*.trf))|*.trf";
// imageList3
this.imageList3.ImageStream = ((System.Windows.Forms.ImageListStreamer)
(resources.GetObject("imageList3.ImageStream")));
this.imageList3.TransparentColor = System.Drawing.Color.Transparent;
this.imageList3.Images.SetKeyName(0, "1");
this.imageList3.Images.SetKeyName(1, "2");
this.imageList3.Images.SetKeyName(2, "3");
this.imageList3.Images.SetKeyName(3, "4");
this.imageList3.Images.SetKeyName(4, "5");
this.imageList3.Images.SetKeyName(5, "6");
this.imageList3.Images.SetKeyName(6, "7");
// Form1
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.SystemColors.ActiveBorder;
this.ClientSize = new System.Drawing.Size(260, 410);
this.Controls.Add(this.progressBarReview);
this.Controls.Add(this.buttonLoad);
this.Controls.Add(this.buttonSave);
this.Controls.Add(this.trackBarReviewSpeed);
this.Controls.Add(this.buttonReview);
this.Controls.Add(this.buttonReplay);
this.Controls.Add(this.menuStripMain);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MainMenuStrip = this.menuStripMain;
this.MaximizeBox = false;
this.Name = "Form1";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "youxi";
this.Load += new System.EventHandler(this.Formyouxi_Load);
((System.ComponentModel.ISupportInitialize)(this.trackBarReviewSpeed)). EndInit();
this.menuStripMain.ResumeLayout(false);
this.menuStripMain.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();

2005年7月9日,傍晚,窗体界面一定要美观

连续编写了一天的代码,现在心中还想着明天的编码工作,我感觉好累。作为桌面系统,窗体界面的美感十分重要。好的窗体效果能给客户带来视觉冲击,也会留下好的印象。当然最直接的好处是增加客户的满意度,让项目通过。在具体美化时,我们通常会用一些漂亮的素材图片作为背景,并用CSS来配合控件和信息的显示。至于具体怎么样搭配,就要根据客户和设计师的喜好了。总结完毕之后,我决定早点休息,为接下来的编码工作养精蓄锐。

您对本文章有什么意见或着疑问吗?请到论坛讨论您的关注和建议是我们前行的参考和动力  
上一篇:1.5.1 制作游戏窗体
下一篇:1.6 编码实现
相关文章
图文推荐
排行
热门
最新书评
文章
下载
读书
特别推荐

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训 | 举报中心

版权所有: 红黑联盟--致力于做实用的IT技术学习网站