zoukankan      html  css  js  c++  java
  • winform PictureBox图片上动态添加Label或其他控件

      效果图:

    代码:

     //分页或者多次加载时,需要删除之前产生的lable等控件
       for (int tabID = 0; tabID < 15; tabID++)
                {
                    foreach (Control control in this.tableLayoutPanel2.Controls)
                    {
    
                        // 遍历所有TextBox...
                        if (control is PictureBox)
                        {
                            PictureBox t = (PictureBox)control;
    if (control.TabIndex == tabID) { if (tabID > list.Count - 1) { for (int i = tabID; i < 15; i++) { //this.tableLayoutPanel2.Controls.Remove(control); t.ImageLocation = null; t.Controls.Remove(t.Controls[tabID.ToString()]); string d = ("NO" + tabID.ToString()); t.Controls.Remove(t.Controls[d]); t.Tag = -1; } break; } t.ImageLocation = list[tabID].VehicleImage; t.Tag = (list[tabID].Id).ToString(); string m = ("NO" + tabID.ToString()); t.Controls.Remove(t.Controls[tabID.ToString()]); t.Controls.Remove(t.Controls[m]); Label C = new Label(); C.Parent = t; C.Width = 100; C.Text = list[tabID].VehicleNumber; C.Font = new Font("", 15); C.ForeColor = Color.Black; C.Dock = DockStyle.Top; C.BackColor = Color.Transparent; C.TextAlign = ContentAlignment.TopLeft; C.AutoSize = false; C.Name = "NO" + tabID.ToString(); Label B = new Label(); B.Parent = t; B.Width = 100; B.Text = list[tabID].VehicleZT; B.Font = new Font("", 18); switch (list[tabID].VehicleZT) { case "待派": B.ForeColor = Color.Blue; break; case "已派": B.ForeColor = Color.Green; break; case "维修": B.ForeColor = Color.Yellow ; break; case "停驶": B.ForeColor = Color.Red; break; } B.Dock = DockStyle.Bottom; B.BackColor = Color.Transparent; B.TextAlign = ContentAlignment.BottomRight; B.AutoSize = false; B.Name = tabID.ToString(); } } } }
  • 相关阅读:
    揭秘 HashMap 实现原理(Java 8)
    并发容器之写时拷贝的 List 和 Set
    Maven 整合 SSH 框架
    Hibernate框架学习之注解配置关系映射
    Hibernate框架学习之注解映射实体类
    单用户,多设备登录问题
    ios scrollview button 延时点击问题
    Android 的 AlarmManager 和 wakeLock联合使用
    ios bitcode 机制对 dsym 调试文件的影响
    信息类型的异步更新方法
  • 原文地址:https://www.cnblogs.com/bonnie-w/p/11157680.html
Copyright © 2011-2022 走看看