473,507 Members | 2,395 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

text color in textbox

In the multiple line textbox, is it possible that every sentences shows
different color ?
For example,
test sentence 1 : red
test sentence 2 : blue
....

Nov 16 '05 #1
5 5317
No you cannot do it. You have to use another control.
Then you can do it.

"Park" <pe***@camsight.com> wrote in message
news:u2*************@tk2msftngp13.phx.gbl...
In the multiple line textbox, is it possible that every sentences shows
different color ?
For example,
test sentence 1 : red
test sentence 2 : blue
...


Nov 16 '05 #2
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace WindowsApplication3
{
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox textBox1;
private System.ComponentModel.Container components = null;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.ListView listView1;

ArrayList show = new ArrayList();
private System.Windows.Forms.ColumnHeader columnHeader1;
int flag;

public Form1()
{
InitializeComponent();
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code

private void InitializeComponent()
{
this.textBox1 = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.listView1 = new System.Windows.Forms.ListView();
this.columnHeader1 = new System.Windows.Forms.ColumnHeader();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(32, 32);
this.textBox1.Name = "textBox1";
this.textBox1.TabIndex = 0;
this.textBox1.Text = "";
this.textBox1.KeyPress += new
System.Windows.Forms.KeyPressEventHandler(this.key Pressed1);
//
// button1
//
this.button1.Location = new System.Drawing.Point(104, 192);
this.button1.Name = "button1";
this.button1.TabIndex = 2;
this.button1.Text = "Show";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// listView1
//
this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.columnHeader1});
this.listView1.GridLines = true;
this.listView1.Location = new System.Drawing.Point(32, 64);
this.listView1.Name = "listView1";
this.listView1.Size = new System.Drawing.Size(216, 120);
this.listView1.TabIndex = 3;
this.listView1.View = System.Windows.Forms.View.Details;
//
// columnHeader1
//
this.columnHeader1.Width = 208;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.listView1);
this.Controls.Add(this.button1);
this.Controls.Add(this.textBox1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);

}
#endregion

[STAThread]
static void Main()
{
Application.Run(new Form1());
}

void keyPressed1(object o, KeyPressEventArgs e)
{
if(e.KeyChar == (char)13)
{
show.Add(textBox1.Text);
textBox1.Clear();
}
}

private void button1_Click(object sender, System.EventArgs e)
{
for(int k= 0; k<show.Count; k++)
{
string [] temp = new string[1];
temp[0] = show[k].ToString();
ListViewItem list = new ListViewItem(temp[0]);
if(flag==0)
{
list.ForeColor = Color.Red;
flag = 1;
listView1.Items.Add(list);
continue;
}

if(flag==1)
{
list.ForeColor = Color.Blue;
flag = 0;
listView1.Items.Add(list);
continue;
}
}
}
}
}

"Park" <pe***@camsight.com> wrote in message
news:u2*************@tk2msftngp13.phx.gbl...
In the multiple line textbox, is it possible that every sentences shows
different color ?
For example,
test sentence 1 : red
test sentence 2 : blue
...

Nov 16 '05 #3
I believe that would be RichTextBox.

-Eric
Nov 16 '05 #4
You might post some example code for Park.
"Eric Cadwell" <ec******@ns.insight.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
I believe that would be RichTextBox.

-Eric

Nov 16 '05 #5
Add a RichTextBox and a Button to a form.

Put this code in...

private void richTextBox1_TextChanged(object sender, System.EventArgs e)
{
string[] lines = richTextBox1.Lines;
int pos = 0;
for (int i = 0; i < lines.Length; i++)
{
int lineLength = lines[i].Length;
richTextBox1.SelectionStart = pos;
richTextBox1.SelectionLength = lineLength;
pos += lineLength + 1;
if ((i % 2) == 0)
richTextBox1.SelectionColor = Color.Red;
else
richTextBox1.SelectionColor = Color.Blue;
}
}
private void button1_Click(object sender, System.EventArgs e)
{
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 10; i++)
sb.Append("line: 1 - red" + Environment.NewLine + "line: 2 - blue" +
Environment.NewLine);
richTextBox1.Text = sb.ToString();
}

.... wire up the events.

HTH;
Eric Cadwell
http://www.origincontrols.com
Nov 16 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
12700
by: Suresh Kumaran | last post by:
Hi All, Does anybody know the sytax in VB.NET to write the contents of a multiline text box to a text file? Appreciate help. Suresh
8
10070
by: Dennis C. Drumm | last post by:
Is there a way to modify the standard context menu shown when someone right clicks in a windows text box and that would work for all open windows applications? The standard context menu for...
10
9116
by: mg | last post by:
I want to enter characters in a TextBox in a WebForm, press a Button in the WebForm, and read the characters that were typed into the TextBox from within the Button_Click event handler. The main...
5
2465
by: Steve S | last post by:
Heres what I want to do...User types into a texbox, clicks a button, the button saves that text to a file. The problem is that when I click the submit button, any changes made to the textbox are...
1
6687
by: Martin | last post by:
Dear Group Sorry for bothering you again but I need expert advice on this. I have placed a HTML textbox on my aspx form and converted it to run as a server control. At some point in my code I...
6
4182
by: Lance Geeck | last post by:
I have a simple form where I am using a dataset called Client. On the data entry screen, there are name, address, city state and zip. I have the fields bound to the dataset field. (Properties...
16
453
by: Adda | last post by:
If I cycle through the MdiChildActivate event of the parent form I can read text in a textbox on the child mdiform -- console.writeline(Me.ActiveMdiChild.Controls(1).Text) But if I have a sub...
11
11098
by: Ron L | last post by:
I have a barcode scanner which uses a "keyboard wedge" program so that the data it scans comes through as if it was typed on a keyboard. I am trying to have the data in the barcode be displayed in...
16
5122
by: mj.redfox.mj | last post by:
Can anyone help? I have a textbox which I'm programatically adding by using the following code: txtTest = New TextBox txtTest.ID = "txtLeft" + cntCount.ToString...
1
4871
by: semomaniz | last post by:
I have a form where i have created the form dynamically. First i manually added a panel control to the web page. Then i added another panel dynamically and inside this panel i created tables. I have...
0
7223
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7111
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
7031
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7485
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5042
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3191
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1542
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
760
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.