C#实验8Windows应用编程

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;
        }

        
    }
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值