【C#教程】C#实现类似电影APP的表单展示的思路

首先,来看下效果:

代码:

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 FilmSample
{
    public partial class Form_mainWin : Form
    {
        List<FilmLayout> layouts; //存放创建的组件
        int num;
        public Form_mainWin()
        {
            InitializeComponent();
            num = 0;
        }

        private void Form1_mainWin_Load(object sender, EventArgs e)
        {
            layouts = new List<FilmLayout>();
        }
        void layout_base_MouseClick(object sender, MouseEventArgs e)
        {
            MessageBox.Show("groupbox被点击!");
        }

        private void button_addcontrol_Click(object sender, EventArgs e)
        {
            
            FilmLayout fl = new FilmLayout();
            this.flowLayoutPanel1.Controls.Add(fl.getBaseLayout());
            fl.getBaseLayout().MouseClick += new MouseEventHandler(layout_base_MouseClick);
            layouts.Add(fl);
        }
    }
    public class FilmLayout
    {
        private GroupBox layout_base; //基础组件
        private PictureBox picturebox; //显示海报
        private Label name; //显示电影名称
        private Label detail; //电影描述
        /**
         * 本类构造函数
         */
        public FilmLayout()
        {
            picturebox = new PictureBox();
            name = new Label();
            detail = new Label();
            layout_base = new GroupBox();
            //位置初始化
            layout_base.Width = 144;
            layout_base.Height = 195;
            picturebox.Width = 144;
            picturebox.Height = 140;
            picturebox.Left = 0;
            picturebox.Top = 0;
            picturebox.Image = new Bitmap(@"C:\Users\879897637\Desktop\sample.jpg");
            picturebox.SizeMode = PictureBoxSizeMode.StretchImage;
            layout_base.Controls.Add(picturebox);
            name.Text = "电影名称";
            name.Left = 5;
            name.Top = this.picturebox.Height + 5;
            detail.Text = "电影描述..";
            detail.Left = 5;
            detail.Top = this.picturebox.Height + this.name.Height + 10;
            //向根布局添加组件
            this.layout_base.Controls.Add(this.name);
            this.layout_base.Controls.Add(this.detail);
        }
        /**
         *  获取根布局组件 GroupBox 
         */
        public GroupBox getBaseLayout()
        {
            return this.layout_base;
        }
        /**
         * 设置label组件的text属性
         */
        public void setLabelText(string name)
        {
            this.name.Text = name;
        }
    }
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值