1. 程式人生 > >C#認證考試第三章

C#認證考試第三章

pac png strip form ips pub 選擇 背景 第三章

ps:因為前面請假,沒能在規定時間做出總結,現在補上

如果你看了第三章的內容,你會發現第三章在著重跟我們講解對Windows窗體的設計,其中包括窗體背景、前景色、字體顏色、位置等。

由於是窗體程序,並且由於題意運行的結果有多種,我就不一一貼代碼和運行結果圖了。

下面我就簡單的貼一個代碼吧,因為後面的雖然題不同,但是邏輯都差不多,無非就是不同的要求需要不同的方法。

技術分享

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace test3_1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void 大ToolStripMenuItem1_Click(object sender, EventArgs e)
{
this.Size = new System.Drawing.Size(600, 400);
toolStripStatusLabel1.Text = "大窗體";
}

private void 中ToolStripMenuItem1_Click(object sender, EventArgs e)
{
this.Size = new System.Drawing.Size(300,200);
toolStripStatusLabel1.Text = "中窗體";
}

private void 小ToolStripMenuItem1_Click(object sender, EventArgs e)
{
this.Size = new System.Drawing.Size(150, 120);
toolStripStatusLabel1.Text = "小窗體";
}

private void button1_Click(object sender, EventArgs e)
{
this.Size = new System.Drawing.Size(600, 400);
toolStripStatusLabel1.Text = "大窗體";
}

private void button2_Click(object sender, EventArgs e)
{
this.Size = new System.Drawing.Size(300, 200);
toolStripStatusLabel1.Text = "中窗體";
}

private void button3_Click(object sender, EventArgs e)
{
this.Size = new System.Drawing.Size(150, 120);
toolStripStatusLabel1.Text = "小窗體";
}

}

根據題意,我們需要將窗體改變後的結果顯示出來,這就需要一個名字為StripStatus的控件,
這個控件顯示窗體狀態的方法如下:

將控件拖入後,選擇這選項。

技術分享

技術分享

為了實現題意要求的菜單,過程如下:

1,找到名為menuStrip1的控件,拉入窗體如下圖

技術分享

根據它的提示輸入你的菜單名字,然後根據題意設計子菜單

技術分享

具體算法,請參照我上面的代碼,我就不貼運行結果了。

C#認證考試第三章