本文介绍了文本框只读时如何更改文本的前景色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

美好的一天



我自己制作了文本框,我想更改文本框内文本的前景色。



我编写了以下代码,但它没有将文本框内文本的forecolor更改为灰色。



Good day

I made my textboxes reaadonly and I want to change the forecolor of the text inside of the textboxes.

I have written the following code, but it is not changing the forecolor of the text inside of the textbox to grey.

txtVersion.ForeColor = Color.Gray;





如果文本框是只读的,我该如何更改文本的前景色? ?



Thanx



How can I change the forecolor of the text, when the textbox is made readonly?

Thanx

推荐答案

using System;
using System.Drawing;
using System.Windows.Forms;

// Requires a form with 2 text boxes and 2 buttons

public partial class Form1 : Form {
  private readonly Color[] rainbow = new Color[] {
    Color.Red,
    Color.Orange,
    Color.Yellow,
    Color.Green,
    Color.Blue,
    Color.Indigo,
    Color.Violet
  };

  private Int32 foreIdx, backIdx;

  public Form1() {
    InitializeComponent();
    backIdx = rainbow.Length - 1;
    NormalTextBox.Text = "Standard text box";
    ReadOnlyTextBox.Text = "Read only text box";
  }

  private void ForeColBtn_Click(object sender, EventArgs e) {
    NormalTextBox.ForeColor = rainbow[foreIdx];
    ReadOnlyTextBox.ForeColor = rainbow[foreIdx];
    foreIdx = ++foreIdx % rainbow.Length;
  }

  private void BackColBtn_Click(object sender, EventArgs e) {
    NormalTextBox.BackColor = rainbow[backIdx];
    ReadOnlyTextBox.BackColor = rainbow[backIdx];
    backIdx = ++backIdx % rainbow.Length;
  }
}





玩得开心,



Alan。



Have fun,

Alan.




这篇关于文本框只读时如何更改文本的前景色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 08:18