zoukankan      html  css  js  c++  java
  • 用户控件

    一、创建用户控件

    1.新建用户控件

    选择操作空间,右键选择添加,点击用户控件

    2.设计用户控件

    在用户控件中添加几个控件

    3.编写后台功能

            private void First_MouseEnter(object sender, EventArgs e)
            {
                //鼠标移入,背景变红
                this.BackColor = Color.Red;
            }
    
            private void First_MouseLeave(object sender, EventArgs e)
            {
                //鼠标移出,背景恢复
                this.BackColor = Color.Transparent;
            }
    
            private void First_DoubleClick(object sender, EventArgs e)
            {
                //双击控件后两个label发生改变
                Form2 f2 = new Form2(label1.Text, label2.Text);
                f2.Show();
            }

    4.主窗口使用用户控件

    主窗口后台代码

            private void button1_Click(object sender, EventArgs e)
            {
                for (int i = 1; i <= 15; i++)
                {
                    First f = new First();
                    //更改用户控件中pictureBox背景
                    f.pictureBox1.BackgroundImage = Image.FromFile("G:\0425\6、WinForm\2016-7-4\用户控件\用户控件\images\1.png");
                    //更改图片的填充方式
                    f.pictureBox1.BackgroundImageLayout = ImageLayout.Stretch;
                    //更改label标签内容
                    f.label1.Text = "用户" + i;
                    f.label2.Text = "签名" + i;
    
                    flowLayoutPanel1.Controls.Add(f);
                }
    
            }

    鼠标未移入

    鼠标移入

    双击控件

  • 相关阅读:
    洛谷 P1032 子串变换
    RCTF 2017 easyre153
    SUCTF 2016 : dMd
    南邮 base64全家桶
    洛谷 P1908 逆序对
    2019中山大学程序设计竞赛 Triangle
    WhiteHat Contest 11 : re1100
    P1010 幂次方
    洛谷 P1088 火星人
    南邮 骚年来一发吗
  • 原文地址:https://www.cnblogs.com/bosamvs/p/5648050.html
Copyright © 2011-2022 走看看