您的位置:首页 > 编程语言 > C#

C#实验8Windows应用编程

2016-05-25 17:29 363 查看
2 设计如图所示窗体。窗体上有两个按钮:一个显示文本,一个显示图片。单击上面按钮或按下 Alt+B键,可以弹出如图消息框。单击下面按钮也可显示。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show("单击了我","提示",MessageBoxButtons.OKCancel,MessageBoxIcon.Warning);
}

private void button2_Click(object sender, EventArgs e)
{
MessageBox.Show("单击了我", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
}

private void button1_KeyDown(object sender, KeyEventArgs e)
{
if (e.Alt&&e.KeyCode==Keys.B)
{
MessageBox.Show("单击了我","提示",MessageBoxButtons.OKCancel,MessageBoxIcon.Warning);
}
}

private void Form1_Load(object sender, EventArgs e)
{
this.KeyPreview = true;
}

private void button2_KeyDown(object sender, KeyEventArgs e)
{
if (e.Alt && e.KeyCode == Keys.B)
{
MessageBox.Show("单击了我", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
}
}

}
}




5窗体上有一个文本框(多行且带有垂直滚动条)、一个标签(字体颜色红色、自号16)、一个按钮(该按钮被单击时,实现将文本复制至标签)。

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

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

private void button1_Click(object sender, EventArgs e)
{
label1.Text = textBox1.SelectedText;
}
}
}




6窗体有两个文本框:一个文本框最多输入字符6个;一个文本框输入任何内容都显示*号。再添加一个按钮、两个单选按钮。实现单击按钮后,根据单选按钮,将文本框中内容显示在标签。

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

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

private void button1_Click(object sender, EventArgs e)
{
if (radioButton1.Checked)
label1.Text = textBox1.Text;
if (radioButton2.Checked)
label1.Text = textBox2.Text;
}

}
}


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: