步步紧追哦^_^


Windows Form 应用程序,New 一个Form--New 一个Button并将其Text更名为"Here!^_^", 然后双击Button,修改代码如下:

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 Cha08Ex01
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
Button btn = sender as Button;
this.Controls.Remove(btn);
btn.Dispose();


Button button = new Button() { Text = "Here!^_^", Width = 60, Height = 24 };

Random random = new Random();
int tmp = random.Next() % this.Width;
button.Left = tmp > this.ClientRectangle.Width - button.Width ? this.ClientRectangle.Width - button.Width : tmp;
tmp = random.Next() % this.Height;
button.Top = tmp > this.ClientRectangle.Height - button.Height ? this.ClientRectangle.Height - button.Height : tmp;

button.Click += new EventHandler(button1_Click);

this.Controls.Add(button);

this.Refresh();
}


}
}

看看效果吧 嘻嘻!

里面要特别注意Button随机位置的设定

参照《C#入门经典》P160 Ch08Ex01改编

优质内容筛选与推荐>>
1、关于代码质量
2、美学心得(第二百零二集) 罗国正
3、Android笔试总结
4、php中九种数学函数的总结
5、swing程序中如何响应鼠标回车事件?


长按二维码向我转账

受苹果公司新规定影响,微信 iOS 版的赞赏功能被关闭,可通过二维码转账支持公众号。

    阅读
    好看
    已推荐到看一看
    你的朋友可以在“发现”-“看一看”看到你认为好看的文章。
    已取消,“好看”想法已同步删除
    已推荐到看一看 和朋友分享想法
    最多200字,当前共 发送

    已发送

    朋友将在看一看看到

    确定
    分享你的想法...
    取消

    分享想法到看一看

    确定
    最多200字,当前共

    发送中

    网络异常,请稍后重试

    微信扫一扫
    关注该公众号