hello
I want to know how I can make a text fielt which has different text in it and each text has seapreated with a number I want this field of text be like a book page but each of text which is seperated with a number when I click on it become red or do somthing else ( event handler for each text).
if i want to explain more i want to write a program to read a book and i want to let the user select the page and when he/she click on the some of the text on the page start reading that part. i have each line and its voice seperately and i can make a text field to print and read line by line but i want the control on lines and have event handler fo each line.
thanks
8 Replies - 672 Views - Last Post: 16 August 2012 - 07:31 AM
#1
A text field which have event handler on spacial parts
Posted 13 August 2012 - 11:23 PM
Replies To: A text field which have event handler on spacial parts
#2
Re: A text field which have event handler on spacial parts
Posted 14 August 2012 - 12:21 AM
Let me clarify what I think you mean.
You have a body of text. You also allow the user to select a page. Presumably, then the text body will change to the text for that page?
Next, when the user clicks a line, that line is highlighted and read aloud. Is that correct?
You have a body of text. You also allow the user to select a page. Presumably, then the text body will change to the text for that page?
Next, when the user clicks a line, that line is highlighted and read aloud. Is that correct?
#3
Re: A text field which have event handler on spacial parts
Posted 14 August 2012 - 09:30 PM
hi and thanks for your reply
yes thats correct.
yes thats correct.
#4
Re: A text field which have event handler on spacial parts
Posted 15 August 2012 - 12:11 AM
Can the user edit the text?
Can the user only select part of a line?
Can the user select part of a line, the next line, and part of a third line?
I'm using these three questions to lead up to the fact that you don't necessarily have to use a text box (or rich text box). If the answer to all the questions is "No", then list box or list view will be sufficient for your needs. This will simplify putting on the line numbers that you indicated in your first paragraph.
And yes, the text can be read out for you. If you look in this C# forum, somebody asked recently about the speech library: http://www.dreaminco...eechlib-net-35/
Can the user only select part of a line?
Can the user select part of a line, the next line, and part of a third line?
I'm using these three questions to lead up to the fact that you don't necessarily have to use a text box (or rich text box). If the answer to all the questions is "No", then list box or list view will be sufficient for your needs. This will simplify putting on the line numbers that you indicated in your first paragraph.
And yes, the text can be read out for you. If you look in this C# forum, somebody asked recently about the speech library: http://www.dreaminco...eechlib-net-35/
This post has been edited by Skydiver: 15 August 2012 - 12:12 AM
#5
Re: A text field which have event handler on spacial parts
Posted 15 August 2012 - 07:37 AM
the answer to first and second question is no but to the third is yes i mean that a part that should become red may be more than one line but is seperated with a number and these parts are ordered continuously and one after another without any space something like bellow .when user clicks from one number to another nomber becomes red and start reading.
this is just a test test test test
test test test test test test test
test test test (1) test test test
test test test test test test test
test test test test (2) test test
test test test test test test test
test test test test(3) test test
test test test test test test test
test test test test (4) test test
test test test test test test (5)
this is just a test test test test
test test test test test test test
test test test (1) test test test
test test test test test test test
test test test test (2) test test
test test test test test test test
test test test test(3) test test
test test test test test test test
test test test test (4) test test
test test test test test test (5)
#6
Re: A text field which have event handler on spacial parts
Posted 15 August 2012 - 10:17 AM
It seems to me that it is not "lines" that you are trying to highlight but sentences. So when text is put into the textbox each sentence will be highlighted. Is that correct?
#7
Re: A text field which have event handler on spacial parts
Posted 15 August 2012 - 10:50 PM
some how you are right but I want the control over each part when the user clicks on each part it becomes red and starts reading from that place and then go to the next part and this part becomes black and next part becomes red and go to the end of the book.my be the user clicks on another part the program disable this and start that one .so I want to have control on each part.I think the example on previous post would clear the problem .
#8
Re: A text field which have event handler on spacial parts
Posted 15 August 2012 - 11:39 PM
Thanks for answering all our questions. 
It's looking like the RichTextBox is going to be the control that you'll want to use. It lets you color or highlight runs of text during runtime. This will let you get the effect that you are looking for of highlighting things as you go along.
If you look around the C# forum you'll see Tailean's question about how to color text in a RichTextBox, that will give you a bit of start on things, or you could simply look at the MSDN documentation: http://msdn.microsof....selectioncolor
The RichTextBox also has built in facilities for you to determine where within the text the user has clicked to make figuring out what needs to be highlighted: http://msdn.microsof...dexfromposition
It's looking like the RichTextBox is going to be the control that you'll want to use. It lets you color or highlight runs of text during runtime. This will let you get the effect that you are looking for of highlighting things as you go along.
If you look around the C# forum you'll see Tailean's question about how to color text in a RichTextBox, that will give you a bit of start on things, or you could simply look at the MSDN documentation: http://msdn.microsof....selectioncolor
The RichTextBox also has built in facilities for you to determine where within the text the user has clicked to make figuring out what needs to be highlighted: http://msdn.microsof...dexfromposition
#9
Re: A text field which have event handler on spacial parts
Posted 16 August 2012 - 07:31 AM
Thanks a lot for your answer and here is my first simple code to do that
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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
for (int i = 0; i < 200; i++)
{
richTextBox1.Text += "test ";
}
richTextBox1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.richTextBox1_MouseDown);
}
private void richTextBox1_TextChanged(object sender, EventArgs e)
{
}
private void richTextBox1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
// Determine whether the user clicks the left mouse button and whether it is a double click.
if (e.Clicks == 1 && e.Button == MouseButtons.Left)
{
// Obtain the character index where the user clicks on the control.
int positionToSearch = richTextBox1.GetCharIndexFromPosition(new Point(e.X, e.Y));
// MessageBox.Show(positionToSearch.ToString());
// richTextBox1.Text +=positionToSearch;
richTextBox1.Select(positionToSearch, 20);
richTextBox1.SelectionColor = Color.Red;
richTextBox1.DeselectAll();
}
}
}
}
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote





|