• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
绯色梧桐绯色月
博客园    首页    新随笔    联系   管理    订阅  订阅
C#窗体自定义控件

 1 using System;
 2 using System.Collections.Generic;
 3 using System.ComponentModel;
 4 using System.Drawing;
 5 using System.Data;
 6 using System.Linq;
 7 using System.Text;
 8 using System.Threading.Tasks;
 9 using System.Windows.Forms;
10 
11 namespace WindowsFormsApplication1
12 {
13     public partial class TestControl : UserControl
14     {
15         private string UserName="";
16         public TestControl()
17         {
18             InitializeComponent();
19         }
20         public TestControl(string uid)
21         {
22             InitializeComponent();
23             UserName = uid;
24         }
25 
26         private void TestControl_Load(object sender, EventArgs e)
27         {
28             YongHuDA da = new YongHuDA();
29             YongHu data = da.Select(UserName);
30 
31             pictureBox1.BackgroundImage = Image.FromFile(data.Pic);
32             pictureBox1.BackgroundImageLayout = ImageLayout.Zoom;
33 
34             label1.Text = data.Nick;
35             label2.Text = data.Qian;
36 
37             button1.Tag = data.Uid;
38         }
39 
40         private void pictureBox1_Click(object sender, EventArgs e)
41         {
42             //label1.Text;
43             this.ParentForm.Controls["label1"].Text = label1.Text;
44 
45         }
46 
47         private void button1_Click(object sender, EventArgs e)
48         {
49 
50         }
51 
52        
53 
54 
55 
56     }
57 }

 1 using System;
 2 using System.Collections.Generic;
 3 using System.ComponentModel;
 4 using System.Data;
 5 using System.Drawing;
 6 using System.Linq;
 7 using System.Text;
 8 using System.Threading.Tasks;
 9 using System.Windows.Forms;
10 
11 namespace WindowsFormsApplication1
12 {
13     public partial class Form1 : Form
14     {
15         public Form1()
16         {
17             InitializeComponent();
18         }
19 
20         private void Form1_Load(object sender, EventArgs e)
21         {
22             YongHuDA da = new YongHuDA();
23             List<YongHu> list = da.Select();
24 
25             foreach (YongHu data in list)
26             {
27                 TestControl ctrl = new TestControl(data.Uid);
28                 flowLayoutPanel1.Controls.Add(ctrl);
29             }
30         }
31     }
32 }

 

愿我有生之年,得见您君临天下。 吾辈必当勤勉,持书仗剑耀中华。
posted on 2016-08-29 16:16  绯色梧桐绯色月  阅读(613)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3