幽灵行动荒野地图面积:帮帮忙做2道C#的题目

来源:百度文库 编辑:查人人中国名人网 时间:2024/04/28 07:26:40
本人刚刚开始自学c# 2道题没找到例子 大家帮忙做一下 谢谢
题目一
要求:
⒈创建一个C# Windows应用程序,在类名为Form1的窗体上放入三个名为textBox1、textBox2和textBox3的单行文本框和两个名为 button1、button2的按钮
⒉三个文本框在初始状态下内容清空,其中textBox3为只读
⒊button1、button2按钮的标签文本分别为 add 和 exit 。button1 在初始状态下为不可用(即控件背景色显示为淡灰色)
⒋当textBox1、textBox2中都输入内容后button1即成为可用状态
⒌在textBox1和textBox2中分别输入两个数字后单击button1时, textBox3中应显示这两个数字相加的和
⒍如果textBox1或textBox2中输入了非数字内容, 则单击button1时,textBox3中应显示 err
⒎单击 button2按钮结束整个程序运行

题目二
要求:
⒈创建一个C# Windows应用程序,在类名为Form1的窗体上有一个名为mainMenu1的主菜单控件和一个名为statusBar1的状态条控件。另外还需设计一个类名为Form2的窗体
⒉状态条statusBar1由两个状态条面板(Panel)组成,每当改变Form1窗口的大小时,statusBar1上两个Panel可以实时显示该窗口的宽度和高度(注意:面板内容仅显示窗体宽高的整型数值)
⒊按照下图设计Form1的主菜单(注意:需严格按照给定的菜单项顺序进行排列),对其中单项标签文本为 show 、 hide 的两项分别设置快捷键CtrlS和CtrlH
┌————┐ ┌———┐ ┌———┐
│ file │ │ exit │ │ help │
├————┴—┬——┴———┴———┴———┘
│ show │
│ hide │
│ maximized │
└——————┘
⒋单击标签文本为 show 的菜单项时可以显示类名为Form2的窗体,单击 hide 的菜单项时使Form2窗体隐藏
⒌单击标签文本为 maximized 的菜单项时使Form2窗体再次以最大化状态显示
⒍单击标签文本为 exit 菜单项时可以结束整个程序运行

第一道我只写出一部分,窗口定义的那些就不写了~
using System.Text.RegularExpressions;
private void button1_Click(object sender, EventArgs e)
{
Regex Re = new Regex(@"^\d*$");
if (this.textBox1.Text != "" && this.textBox2.Text != "")
if (Re.Match(this.textBox1.Text).Success && Re.Match(this.textBox2.Text).Success)
this.textBox3.Text = (Convert.ToInt32(this.textBox1.Text) + Convert.ToInt32(this.textBox2.Text)).ToString();
else
this.textBox3.Text = "ER";
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
if (this.textBox1.Text != "" && this.textBox2.Text != "")
this.button1.Enabled = true;
else
this.button1.Enabled = false;
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
if (this.textBox1.Text != "" && this.textBox2.Text != "")
this.button1.Enabled = true;
else
this.button1.Enabled = false;
}
private void button2_Click(object sender, EventArgs e)
{
Application.Exit();
}
}

第2道:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace p2
{
partial class Form1
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null;

/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows 窗体设计器生成的代码

/// <summary>
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.menuStrip1 = new System.Windows.Forms.MenuStrip();
this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.showToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.hideToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.maximizedToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.helpToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.statusStrip1 = new System.Windows.Forms.StatusStrip();
this.toolStripStatusLabel1 = new System.Windows.Forms.ToolStripStatusLabel();
this.menuStrip1.SuspendLayout();
this.statusStrip1.SuspendLayout();
this.SuspendLayout();
//
// menuStrip1
//
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.fileToolStripMenuItem,
this.exitToolStripMenuItem,
this.helpToolStripMenuItem});
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
this.menuStrip1.Name = "menuStrip1";
this.menuStrip1.Size = new System.Drawing.Size(292, 24);
this.menuStrip1.TabIndex = 0;
this.menuStrip1.Text = "menuStrip1";
//
// fileToolStripMenuItem
//
this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.showToolStripMenuItem,
this.hideToolStripMenuItem,
this.maximizedToolStripMenuItem});
this.fileToolStripMenuItem.Name = "fileToolStripMenuItem";
this.fileToolStripMenuItem.Size = new System.Drawing.Size(41, 20);
this.fileToolStripMenuItem.Text = "File";
//
// showToolStripMenuItem
//
this.showToolStripMenuItem.Name = "showToolStripMenuItem";
this.showToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control |

System.Windows.Forms.Keys.S)));
this.showToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
this.showToolStripMenuItem.Text = "Show";
this.showToolStripMenuItem.Click += new System.EventHandler(this.showToolStripMenuItem_Click);
//
// hideToolStripMenuItem
//
this.hideToolStripMenuItem.Name = "hideToolStripMenuItem";
this.hideToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control |

System.Windows.Forms.Keys.H)));
this.hideToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
this.hideToolStripMenuItem.Text = "Hide";
this.hideToolStripMenuItem.Click += new System.EventHandler(this.hideToolStripMenuItem_Click);
//
// maximizedToolStripMenuItem
//
this.maximizedToolStripMenuItem.Name = "maximizedToolStripMenuItem";
this.maximizedToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
this.maximizedToolStripMenuItem.Text = "maximized ";
this.maximizedToolStripMenuItem.Click += new System.EventHandler(this.maximizedToolStripMenuItem_Click);
//
// exitToolStripMenuItem
//
this.exitToolStripMenuItem.Name = "exitToolStripMenuItem";
this.exitToolStripMenuItem.Size = new System.Drawing.Size(41, 20);
this.exitToolStripMenuItem.Text = "Exit";
this.exitToolStripMenuItem.Click += new System.EventHandler(this.exitToolStripMenuItem_Click);
//
// helpToolStripMenuItem
//
this.helpToolStripMenuItem.Name = "helpToolStripMenuItem";
this.helpToolStripMenuItem.Size = new System.Drawing.Size(41, 20);
this.helpToolStripMenuItem.Text = "Help";
//
// statusStrip1
//
this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.toolStripStatusLabel1});
this.statusStrip1.Location = new System.Drawing.Point(0, 244);
this.statusStrip1.Name = "statusStrip1";
this.statusStrip1.Size = new System.Drawing.Size(292, 22);
this.statusStrip1.TabIndex = 1;
this.statusStrip1.Text = "statusStrip1";
//
// toolStripStatusLabel1
//
this.toolStripStatusLabel1.Name = "toolStripStatusLabel1";
this.toolStripStatusLabel1.Size = new System.Drawing.Size(41, 17);
this.toolStripStatusLabel1.Text = "Label1";
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.statusStrip1);
this.Controls.Add(this.menuStrip1);
this.MainMenuStrip = this.menuStrip1;
this.Name = "Form1";
this.Text = "Form1";
this.ClientSizeChanged += new System.EventHandler(this.Form1_ClientSizeChanged);
this.Load += new System.EventHandler(this.Form1_Load);
this.menuStrip1.ResumeLayout(false);
this.menuStrip1.PerformLayout();
this.statusStrip1.ResumeLayout(false);
this.statusStrip1.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.MenuStrip menuStrip1;
private System.Windows.Forms.ToolStripMenuItem fileToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem showToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem hideToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem maximizedToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem exitToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem helpToolStripMenuItem;
private System.Windows.Forms.StatusStrip statusStrip1;
private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel1;
private Form2 F = new Form2();
}
public Form1()
{
InitializeComponent();
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void Form1_Load(object sender, EventArgs e)
{
this.toolStripStatusLabel1.Text = "(" + this.Width.ToString() + "," + this.Height.ToString() + ")";
}
private void Form1_ClientSizeChanged(object sender, EventArgs e)
{
this.toolStripStatusLabel1.Text = "(" + this.Width.ToString() + "," + this.Height.ToString() + ")";
}
private void showToolStripMenuItem_Click(object sender, EventArgs e)
{
F.Show();
}
private void hideToolStripMenuItem_Click(object sender, EventArgs e)
{
F.Hide();
}
private void maximizedToolStripMenuItem_Click(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Maximized;
}
}

这个问题并不难啊
首先题一:
也就是创建一个四则运算的小程序罢了,只要在关键地方加上求和公式即可.
第二个:找准form2.show();
form2.close();
且要让form1为form2的父窗体,将会很简单阿。而对于form2的最大化只需要将一个属性设置一下即可(我记不太清了),而对于退出也就更简单了
application.exit()搞定了

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace WindowsApplication2
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.TextBox textBox3;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;

public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();

//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}

/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.textBox3 = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// label1
//
this.label1.Font = new System.Drawing.Font("宋体", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label1.Location = new System.Drawing.Point(112, 56);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(40, 23);
this.label1.TabIndex = 0;
this.label1.Text = "+";
//
// label2
//
this.label2.Font = new System.Drawing.Font("宋体", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.label2.Location = new System.Drawing.Point(272, 56);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(24, 23);
this.label2.TabIndex = 1;
this.label2.Text = "=";
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(0, 56);
this.textBox1.Name = "textBox1";
this.textBox1.TabIndex = 2;
this.textBox1.Text = "";
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(160, 56);
this.textBox2.Name = "textBox2";
this.textBox2.TabIndex = 3;
this.textBox2.Text = "";
this.textBox2.TextChanged += new System.EventHandler(this.textBox2_TextChanged);
//
// button1
//
this.button1.Location = new System.Drawing.Point(248, 144);
this.button1.Name = "button1";
this.button1.TabIndex = 4;
this.button1.Text = "exit";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Enabled = false;
this.button2.Location = new System.Drawing.Point(72, 144);
this.button2.Name = "button2";
this.button2.TabIndex = 5;
this.button2.Text = "add";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// textBox3
//
this.textBox3.Location = new System.Drawing.Point(304, 56);
this.textBox3.Name = "textBox3";
this.textBox3.ReadOnly = true;
this.textBox3.TabIndex = 6;
this.textBox3.Text = "";
this.textBox3.TextChanged += new System.EventHandler(this.textBox3_TextChanged);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(432, 270);
this.Controls.Add(this.textBox3);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private void textBox3_TextChanged(object sender, System.EventArgs e)
{

}

private void textBox2_TextChanged(object sender, System.EventArgs e)
{
button2.Enabled = true;
}

private void button1_Click(object sender, System.EventArgs e)
{
Application.Exit();
}

private void button2_Click(object sender, System.EventArgs e)
{
try
{
double d1 = double.Parse(textBox1.Text);
double d2 = double.Parse(textBox2.Text);
double d3 = d1 + d2;
textBox3.Text = d3.ToString();
}
catch (FormatException)
{
textBox1.Text = "Err";
}
}
}
}

欢迎电脑高手来我的QQ群啊