求C#自动生成控件的样例,急~~~

来源:百度知道 编辑:UC知道 时间:2024/06/21 22:49:30
求一个C#自动生成控件的样例,最好带有从数据库中读取信息的,要完整的代码,因为要做项目,初学不会,还请大家帮助
是个自定义控件,里面的例如按钮啥的,是通过代码的编写生成的,并不是手动直接加载的

你可以在百度上搜“动态控件”或者是“代码控件”,下面一段程序是关于动态添加按钮的,需要编写者在windows应用程序中手动先添加静态的一个按钮(将其id属性设为btn)和一个文本框(id=txt_msg)。随后双击窗体form,于后台复制如下代码,F5运行。

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

namespace WindowsApplication9
{
public partial class Form1 : Form
{

private void Form1_Load(object sender, EventArgs e)
{

}

private int count = 0;//用于计数,添加了多少个按钮
public Form1()
{
InitializeComponent();
}

private void btn_addButtons_Click(object sender, EventArgs e)
{
//计数,计算目前是添加的几个按钮
count++;
//计算待添加按钮的位置
int localY = this.btn_addButtons.Height * count;
int localX = 10 * count;