为了账号安全,请及时绑定邮箱和手机立即绑定

急~~C#中绘画标签,如何通过标签的Text来改变颜色

急~~C#中绘画标签,如何通过标签的Text来改变颜色

holdtom 2018-12-06 19:04:20
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.Data.SqlClient;namespace WindowsApplication3{    public partial class Form1 : Form    {        public Form1()        {            InitializeComponent();        }        Label[,] label = new Label[256, 256];        public void InitSeats(int seatRow, int seatLine, TabPage tb)        {            for (int i = 0; i < seatRow; i++)            {                for (int j = 0; j < seatLine; j++)                {                    label[i, j] = new Label();                    label[i, j].BackColor = Color.Yellow;                    label[i, j].AutoSize = false;                    label[i, j].Font = new System.Drawing.Font("宋体", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));                    label[i, j].Location = new System.Drawing.Point(59, 60);                    label[i, j].Name = "lbl" + (j + 1).ToString() + "_" + (i + 1).ToString();                    label[i, j].Size = new System.Drawing.Size(50, 25);                    //设置座位号                    label[i, j].Text = (j + 1).ToString() + "-" + (i + 1).ToString();                    label[i, j].TextAlign = ContentAlignment.MiddleCenter;                    label[i, j].Location = new Point(60 + (i * 90), 60 + (j * 60));                    tb.Controls.Add(label[i, j]);                }            }        }        private void button1_Click(object sender, EventArgs e)        {            InitSeats(2, 2, tabPage1);            label[1,2]=new Label();            label[1,2].BackColor=Color.Red;        }    }}在代码最后,我想让label[1,2].BackColor=Color.Red的,可以我的做法不对呀,根本就不变色,还是黄色,请高手指点,谢谢!
查看完整描述

2 回答

?
守着一只汪

TA贡献1872条经验 获得超3个赞

 label[1,2]=new Label();
这句话去掉看看。

实在不行就遍历Controls内所有的label 把你想要的那个更改颜色

查看完整回答
反对 回复 2019-01-21
  • 2 回答
  • 0 关注
  • 655 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信