I am trying to write this program to tell the user if the name he entered is on the list of most popular names, for girls or boys. The problem I am having is that my button click wont display the message boxes that I have coded. I have been stuck on this problem for a while and I cant seem to get it to display.
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void LoadNames(object sender, EventArgs e)
{
const int size = 200;
string[] names = new string[size];
string[] names1 = new string[size];
int index = 0;
int index1 = 0;
StreamReader inputfile1;
StreamReader inputfile2;
inputfile1 = File.OpenText(#"F:\C# HW\CH07_HW_07\BoysNames.txt");
inputfile2 = File.OpenText(#"F:\C# HW\CH07_HW_07\GirlsNames.txt");
while (!inputfile1.EndOfStream && index < names.Length)
{
names[index] = inputfile1.ReadLine();
index++;
}
while (!inputfile2.EndOfStream && index1 < names1.Length)
{
names1[index1] = inputfile2.ReadLine();
index1++;
}
}
private Boolean FindBoyname()
{
const int size = 200;
string[] BoyNames = new string[size];
int index = 0;
string boyname = textBox1.Text;
Boolean Boyname = false;
StreamReader inputfile1;
inputfile1 = File.OpenText(#"F:\C# HW\CH07_HW_07\BoysNames.txt");
while (!inputfile1.EndOfStream && index < BoyNames.Length)
{
BoyNames[index] = inputfile1.ReadLine();
if (String.Equals(boyname, BoyNames[index], StringComparison.OrdinalIgnoreCase) == true)
{
Boyname = true;
}
index++;
}
return Boyname;
}
private Boolean FindGirlname()
{
const int size = 200;
string[] GirlNames = new string[size];
int index = 0;
string girlname = textBox2.Text;
Boolean Girlname = false;
StreamReader inputfile1;
inputfile1 = File.OpenText(#"F:\C# HW\CH07_HW_07\GirlsNames.txt");
while (!inputfile1.EndOfStream && index < GirlNames.Length)
{
GirlNames[index] = inputfile1.ReadLine();
if (String.Equals(girlname, GirlNames[index], StringComparison.OrdinalIgnoreCase) == true)
{
Girlname = true;
}
index++;
}
return Girlname;
}
private void button1_Click(object sender, EventArgs e)
{
Boolean boy;
Boolean girl;
boy = FindBoyname();
girl = FindGirlname();
if (boy.Equals(true))
{
MessageBox.Show(textBox1.Text + " is among the most popular boy names!");
}
if (boy.Equals(false))
{
MessageBox.Show(textBox1.Text + " is not among the most popular boy names.");
}
if (girl.Equals(true))
{
MessageBox.Show(textBox2.Text + " is among the most popular girl names!");
}
if (girl.Equals(false))
{
MessageBox.Show(textBox2.Text + " is not among the most popular girl names.");
}
}
}
Most likely the button1.Click event is't subscribed with this void button1_Click event handler. Check it in design code or in the visual designer
If you remove all the code that has nothing to do with showing a message box you get:
I am trying to write this program to tell the user if the name he entered is on the list of most popular names, for girls or boys. The problem I am having is that my button click wont display the message boxes that I have coded. I have been stuck on this problem for a while and I cant seem to get it to display.
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Boolean boy;
Boolean girl;
if (boy.Equals(true))
{
MessageBox.Show(textBox1.Text + " is among the most popular boy names!");
}
if (boy.Equals(false))
{
MessageBox.Show(textBox1.Text + " is not among the most popular boy names.");
}
if (girl.Equals(true))
{
MessageBox.Show(textBox2.Text + " is among the most popular girl names!");
}
if (girl.Equals(false))
{
MessageBox.Show(textBox2.Text + " is not among the most popular girl names.");
}
}
}
This code doesn't wire up your event anywhere, so have a look inside InitializeComponent and see if it does so there.
You're looking for a line that reads:
button1.Click += button1_Click;
If it's not there, then that'll be why your code isn't showing anything.
Related
I want to create a webform with 4 types of phones like: LG, xiaomi, samsung and iphone. They will be in an Array and I will insert them into dynamic radiobuttonList in the page init.
Also, the user will have a textbox where he will put an amount of money he has. The user will also have a button that will calc if he have the budget for the selected phone from the list.
After the user selects the phone, write in the budget and press the button
he will get "in budget" or "not enough budget".
The class have property of the array to insert the all the array from the page init and will have 2 functions:
One function will take the budget number > will go to the 2nd function that will see the selected phone and the budget > do its calcs and return the result into the 1st func that will give the feedback.
Now where I am stuck:
if the class isnt made global - and i put it in init or in button click - it wont work, so im looking for a way to make it work but without putting it global
so far i managed to inject the selected value into a class property and than compare - but i want to know if there is a way that this can happen with array inside class property
maybe if anyone can help me out and refer me to a guide where i can learn more about this subject (how inject selected value into function of a class and etc) ill be glad! as everything i see is C# with console but i work with ASP.NET WEB APPLICATION (.netframework)
enter code here
namespace gfjsr{
public partial class WebForm1 : System.Web.UI.Page{
phone InsertUserInfo = new phone();
protected void Page_init(object sender, EventArgs e){
string[] myArr = new string[] { "samsung", "IPHONE", "XIAOMI","LG"};
RadioButtonList phoneList = new RadioButtonList();
phoneList.ID = "radioList";
for (int i = 0; i< myArr.Length; i++)
{
ListItem li = new ListItem();
li.Text = myArr[i];
li.Value = i.ToString();
phoneList.Items.Add(li);
}
Panel1.Controls.Add(phoneList);
Label budgetLb = new Label();
budgetLb.ID = "budglb";
budgetLb.Text = "write your budget";
Panel1.Controls.Add(budgetLb);
TextBox insertBudg = new TextBox();
insertBudg.ID = "budgTxt";
Panel1.Controls.Add(insertBudg);
Button myBtn = new Button();
myBtn.ID = "btn1";
myBtn.Click += new EventHandler(btn1_click);
myBtn.Text = "result";
Panel1.Controls.Add(myBtn);
Label Labelfeedback = new Label();
Labelfeedback.ID = "feedback";
Labelfeedback.Text = "";
Panel1.Controls.Add(Labelfeedback);
}
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btn1_click(object sender, EventArgs e)
{
InsertUserInfo.phoneChosen = ((RadioButtonList)FindControl("radioList")).SelectedItem.Text;
double UserBudget =
Convert.ToDouble(((TextBox)FindControl("budgTxt")).Text);
InsertUserInfo.BudgetYN(UserBudget);
((Label)FindControl("feedback")).Text = InsertUserInfo.feedback; }}}
namespace gfjsr{
public class phone{
private string _phoneChosen;
public string phoneChosen
{
get { return _phoneChosen; }
set { _phoneChosen = value; }
}
private string _feedback;
public string feedback
{
get { return _feedback; }
set { _feedback = value; }
}
public double Func1(string x)
{
double phonePrice = 0;
if( x == "samsung")
{
phonePrice = 4000;
}
if (x == "IPHONE")
{
phonePrice = 3500;
}
if (x == "XIAOMI")
{
phonePrice = 3000;
}
if (x == "LG")
{
phonePrice = 2000;
}
return phonePrice;
}
public void BudgetYN(double y)
{
if(y >= Func1(_phoneChosen))
{
_feedback = "positive";
}
else
{
_feedback = "no";
}
}
}
}
In form1 designer:
In label1 the counting numbers out of numbers in label25.
In the middle i added another label just for the "/"
but the result when i'm running the program is that there is a big space/s between the labels: I tried to move the "/" and label25 as much as i can to the left close to label1 but it's not a good way to do it.
What is the best way to achieve it ?
In form1 i have this class:
public class MyProgress
{
public string Report1 { get; set; }
public string Report2 { get; set; }
public string Report3 { get; set; }
public string Report4 { get; set; }
}
Then the method DirSearch where i also making report progress of backgroundworker1:
int numberofdirs = 0;
void DirSearch(string rootDirectory, string filesExtension, string[] textToSearch, BackgroundWorker worker, DoWorkEventArgs e)
{
List<string> resultsoftextfound = new List<string>();
List<string> resultsoftextfound1 = new List<string>();
List<string> filePathList = new List<string>();
int numberoffiles = 0;
try
{
filePathList = SearchAccessibleFilesNoDistinct(rootDirectory, null,worker,e).ToList();
}
catch (Exception err)
{
string ad = err.ToString();
}
label21.Invoke((MethodInvoker)delegate
{
label21.Text = "Phase 2: Searching in files";
});
MyProgress myp = new MyProgress();
myp.Report4 = filePathList.Count.ToString();
foreach (string file in filePathList)
{
try
{
_busy.WaitOne();
if (worker.CancellationPending == true)
{
e.Cancel = true;
return;
}
bool reportedFile = false;
for (int i = 0; i < textToSearch.Length; i++)
{
if (File.ReadAllText(file).IndexOf(textToSearch[i], StringComparison.InvariantCultureIgnoreCase) >= 0)
{
resultsoftextfound.Add(file + " " + textToSearch[i]);
if (!reportedFile)
{
numberoffiles++;
myp.Report1 = file;
myp.Report2 = numberoffiles.ToString();
myp.Report3 = textToSearch[i];
backgroundWorker1.ReportProgress(0, myp);
reportedFile = true;
}
}
}
numberofdirs++;
label1.Invoke((MethodInvoker)delegate
{
label1.Text = numberofdirs.ToString();
label1.Visible = true;
});
}
catch (Exception)
{
}
}
}
In this line i report the overall files count:
myp.Report4 = filePathList.Count.ToString();
Then later reporting the number of files count:
myp.Report2 = numberoffiles.ToString();
And updating label1:
label1.Invoke((MethodInvoker)delegate
{
label1.Text = numberofdirs.ToString();
label1.Visible = true;
});
This is the backgorundworker1 dowork event:
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
BackgroundWorker worker = sender as BackgroundWorker;
_stopwatch.Restart();
string[] values = textBox1.Text.Split(new string[] { ",," }, StringSplitOptions.None);
DirSearch(textBox3.Text, textBox2.Text, values, worker, e);
_stopwatch.Stop();
}
And the progresschanged event:
private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
MyProgress mypro = (MyProgress)e.UserState;
ListViewCostumControl.lvnf.Items.Add(mypro.Report1);
label15.Text = mypro.Report2;
label25.Text = mypro.Report4;
label15.Visible = true;
if (ListViewCostumControl.lvnf.Items.Count > 9)
textBox4.Enabled = true;
}
In the end what i want to do when running the program is to display the count of files out of overall files for example: 21 / 244 where 21 is the counter.
If you want to use three different labels take the following steps:
Add on your form "FlowLayoutPanel"
Change it "Auto-Size" property to "True"
Put your labels on it
Go to the properties of each label and set "Margin" to "0; 6; 0; 0",
"0; 3; 0; 0" and "0; 0; 0; 0".
It would look like so.
P.S. I would suggest you to use only one label and put it there as formatted text.
Try changing the text alignment in the label controls. Align the leftmost label to the right and the rightmost label to the left. Align the "/" character label to "center" and make it very narrow. Then adjust all to have the same text baseline with the horizontal alignment tool.
in this program, when the Recall button (recallBtn_Click()) is clicked, it calls a method (that calculates directions) from another class which should then call the showPath() method. the show path method should then display its output in a textBox. But the values don't show even though i can see from debugging that the values are being sent to the text box. can anybody tell me where i went wrong?
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
storeRetSelect.SelectedIndex = 0;
PrioritySelect.SelectedIndex = 0;
}
public void showPath(List<PathFinderNode> mPath)
{
var T = new Form1().directionsTextBox;
foreach (PathFinderNode node in mPath)
{
if ((node.X - node.PX) > 0) { T.Text += "Right" + System.Environment.NewLine ; }
if ((node.X - node.PX) < 0) { T.Text += "Left" + System.Environment.NewLine; }
if ((node.Y - node.PY) > 0) { T.Text += "UP" + System.Environment.NewLine; }
if ((node.Y - node.PY) < 0) { T.Text += "Down" + System.Environment.NewLine; }
}
}
private void recallBtn_Click(object sender, EventArgs e)
{
var path = new pathPlan();
string desigString = inputTextBox.Text;
int[] desig = new int[3];
for (int i = 0; i < desigString.Length; i++) { desig[i] = (int)char.GetNumericValue(desigString[i]); }
path.Recall(desig[1], desig[2], (-1) * desig[0]);
}
}
With this line you are initialising a new object and get the reference of the textbox there.
var T = new Form1().directionsTextBox;
But I assume you want to use the textbox of the form which is allready open. Change the line to the following to access the textbox of the current object.
var T = this.directionsTextBox;
I am working on a quiz project which also allows user to add new questions.
I have an array list in which questions are stored and retrieved for displaying. Each object saved in the array list contains 5 strings.
Question
Right answer
Wrong answer 1
Wrong answer 2
Wrong answer 3
How can I randomly select objects from the array list to be displayed on the screen? And how can I shuffle the 4 answers (as radio buttons) so that the right answer appears at different positions each time?
namespace quiz
{
public partial class Quiz : Form
{
private ArrayList Questionslist;
public Quiz(ArrayList list)
{
InitializeComponent();
Questionslist = list;
}
int index = 0;
private void Quiz_Load(object sender, EventArgs e)
{
//creating an object of class Question and copying the object at index1 from arraylist into it
Question q = (Question)Questionslist[index];
//to display the contents
lblQs.Text = q.Quest;
radioButtonA1.Text = q.RightAnswer;
radioButtonA2.Text = q.WrongAnswer1;
radioButtonA3.Text = q.WrongAnswer2;
radioButtonA4.Text = q.WrongAnswer3;
}
private int Score = 0;
private void radioButtonA1_CheckedChanged(object sender, EventArgs e)
{
//if checkbox is checked
//displaying text in separate two lines on messagebox
if (radioButtonA1.Checked == true)
{
MessageBox.Show("Well Done" + Environment.NewLine + "You Are Right");
Score++;
index++;
if (index < Questionslist.Count)
{
radioButtonA1.Checked = false;
radioButtonA2.Checked = false;
radioButtonA3.Checked = false;
radioButtonA4.Checked = false;
Quiz_Load(sender, e);
}
else
{
index--;
MessageBox.Show("Quiz Finished" + Environment.NewLine + "your Score is" + Score);
Close();
}
}
}
private void radioButtonA2_CheckedChanged(object sender, EventArgs e)
{
if (radioButtonA2.Checked == true)
{
MessageBox.Show("Sorry" + Environment.NewLine + "You Are Wrong");
Close();
}
}
private void radioButtonA3_CheckedChanged(object sender, EventArgs e)
{
if (radioButtonA3.Checked == true)
{
MessageBox.Show("Sorry" + Environment.NewLine + "You Are Wrong");
Close();
}
}
private void radioButtonA4_CheckedChanged(object sender, EventArgs e)
{
if (radioButtonA4.Checked == true)
{
MessageBox.Show("Sorry" + Environment.NewLine + "You Are Wrong");
Close();
}
}
}
}
this is the code for class question
namespace quiz
{
[Serializable()]
public class Question : ISerializable
{
public String Quest;
public String RightAnswer;
public String WrongAnswer1;
public String WrongAnswer2;
public String WrongAnswer3;
public Question()
{
Quest = null;
RightAnswer=null;
WrongAnswer1=null;
WrongAnswer2=null;
WrongAnswer3=null;
}
//serialization function
public void GetObjectData(SerializationInfo info, StreamingContext context)
{
info.AddValue("Question", Quest);
info.AddValue("Right Answer", RightAnswer);
info.AddValue("WrongAnswer1",WrongAnswer1);
info.AddValue("WrongAnswer2",WrongAnswer2);
info.AddValue("WrongAnswer3",WrongAnswer3);
}
//deserializaton constructor
public Question(SerializationInfo info, StreamingContext context)
{
Quest = (String)info.GetValue("Question", typeof(String));
RightAnswer=(String)info.GetValue("Right Answer",typeof(String));
WrongAnswer1=(String)info.GetValue("WrongAnswer1",typeof(String));
WrongAnswer2=(String)info.GetValue("WrongAnswer2",typeof(String));
WrongAnswer3=(String)info.GetValue("WrongAnswer3",typeof(String));
}
}
}
You know which one is the 'right' answer based on the Text property. One approach would be to store the answers in an array and shuffle the array before assigning it to the radio buttons:
// You're going to make questionList a List<Question> because if you like
// Right answers you know that ArrayList is Wrong.
Question q = questionList[index];
// You should move this next bit to the Question class
string[] answers = new string[]
{
q.RightAnswer,
q.WrongAnswer1,
q.WrongAnswer2,
q.WrongAnswer3
};
// Using the Fisher-Yates shuffle from:
// http://stackoverflow.com/questions/273313/randomize-a-listt-in-c-sharp
Shuffle(answers);
// Ideally: question.GetShuffledAnswers()
radioButtonA1.Text = answers[0];
radioButtonA2.Text = answers[1];
radioButtonA3.Text = answers[2];
radioButtonA4.Text = answers[3];
Then later, all you need is a single radio button event handler that they all share:
private void radioButton_CheckedChanged(object sender, EventArgs e)
{
RadioButton rb = (RadioButton)sender;
Question q = questionList[index];
//if checkbox is checked
//displaying text in separate two lines on messagebox
if (rb.Checked && q.RightAnswer == rb.Text)
{
// Move your code to another method
// MessageBox.Show("Well Done" + Environment.NewLine + "You Are Right");
UserSelectedCorrectAnswer();
}
else if (rb.Checked)
{
// They checked the radio button, but were wrong!
// MessageBox.Show("Sorry" + Environment.NewLine + "You Are Wrong");
UserSelectedWrongAnswer();
}
}
Pick a random string from ArrayList:
string randomPick(ArrayList strings)
{
return strings[random.Next(strings.Length)];
}
You might consider having a Question class. That would contain a string Text member for the question (because I think Question.Question is silly, Question.Text makes more sense when read). Since you mentioned an ArrayList (not because I think it's the best solution), you can have one of those as a member as well which would contain all the potential answers.
When you create a question, you can display Question.Text, then use the function above to randomly pick an answer. Then use RemoveAt(index) on the answers to ensure you don't duplicate answers.
I'd make a Question class containing the question, the right answer and a list of possible answers, and have methods that return the possible answers in randomized order and compares a guess to the correct answer. It could look something like this:
class Question
{
String question;
String rightAnswer;
List<String> possibleAnswers = new ArrayList<String>();
public Question(String question, String answer, List<String> possibleAnswers)
{
this.question = question;
this.rightAnswer = answer;
this.possibleAnswers.addAll(possibleAnswers);
this.possibleAnswers.add(this.rightAnswer);
}
public List<String> getAnswers()
{
Collections.shuffle(possibleAnswers);
return possibleAnswers;
}
public boolean isCorrect(String answer)
{
return answer.equals(correctAnswer);
}
}
You should encapsulate all the questions in a class. For example, create a class named Question. This class can contain 5 variables: String question, String answer1, String answer2, String answer3 and String answer4.
Save all your questions in a database or read them from a file and load them on the start of the program.
Use the Random class to randomly select a question and to 'shuffle' the 4 questions.
Here's a method that will work:
public List<string> Randomize(string[] numbers)
{
List<string> randomized = new List<string>();
List<string> original = new List<string>(numbers);
Random r = new Random();
while (original.Count > 0) {
int index = r.Next(original.Count);
randomized.Add(original[index]);
original.RemoveAt(index);
}
return randomized;
}
just adapt it to string array instead of int array
The shuffle is probably a standard question, but I guess this will work:
// Warning: Not a thread-safe type.
// Will be corrupted if application is multi-threaded.
static readonly Random randomNumberGenerator = new Random();
// Returns a new sequence whose elements are
// the elements of 'inputListOrArray' in random order
public static IEnumerable<T> Shuffle<T>(IReadOnlyList<T> inputListOrArray)
{
return GetPermutation(inputListOrArray.Count).Select(x => inputListOrArray[x]);
}
static IEnumerable<int> GetPermutation(int n)
{
var list = Enumerable.Range(0, n).ToArray();
for (int idx = 0; idx < n; ++idx)
{
int swapWith = randomNumberGenerator.Next(idx, n);
yield return list[swapWith];
list[swapWith] = list[idx];
}
}
If you don't have IReadOnlyList<T> (.NET 4.5), just use IList<T>. The incoming object is not mutated.
thanks to all of u who answered my question.i did it this way.
private void Quiz_Load(object sender, EventArgs e)
{
displayQs();
}
private void displayQs()
{
Random _random = new Random();
int z = _random.Next(Questions.Count);
Question q = (Question)Questions[z];
Qslbl.Text = q.Quest;
DisplayAns(q, _random);
}
private void DisplayAns(Question q, Random _random)
{
int j = 0;
int[] array = new int[4];
for (int i = 0; j <= 3; i++)
{
int x = _random.Next(4);
x++;
if (array.Contains(x))
{
continue;
}
else
{
array[j] = x;
j++;
string answer = null;
if (j == 1)
answer = q.RightAnswer;
else if (j == 2)
answer = q.WrongAnswer1;
else if (j == 3)
answer = q.WrongAnswer2;
else if (j == 4)
answer = q.WrongAnswer3;
if (x == 1)
radioButton1.Text = answer;
else if (x == 2)
radioButton2.Text = answer;
else if (x == 3)
radioButton3.Text = answer;
else if (x == 4)
radioButton4.Text = answer;
}
}
}
I am creating a tool in Visual C#.Net. The algorithm of the tool is to check for all space/s before/after a parenthesis and create an error message for the found errors.
For example: input is ( Text )
Error will be raise because space before and after the parenthesis is detected.
If errors are found the code will add the errors in listview1.items().
To make my question much clearer for you here's my code:
private void button1_Click(object sender, EventArgs e)
{
int error_counter = 0;
listView1.Items.Clear();
//requirement 8c
//check for a space in open and close parenthesis
Regex test = new Regex(#"\(\s.+\s\)|\[\s.+\s\]|\{\s.+\s\}", RegexOptions.IgnoreCase);
MatchCollection matchlist = test.Matches(richTextbox1.Text);
if (matchlist.Count > 0)
{
for (int i = 0; i < matchlist.Count; i++)
{
Match firstMatch = matchlist[i];
string firstMatch_string = firstMatch.ToString();
string[] errors = new string[matchlist.Count];
errors[i] = "Ommit Space between a bracket";
listView1.Items.Add(errors[i]);
error_counter++;
}
}
}
private void listView1_ItemActivate(object sender, EventArgs e)
{
if (listView1.SelectedItems.Count > 0)
{
ListViewItem item = listView1.SelectedItems[0];
MessageBox.Show(item.ToString());
}
}
What I looking for is that all of the items of my listview1 will be clickable, and after a click was made by the user the tool will highlight the error found in the richtextbox1.
Thanks for all your help guys!
As someone already told you, use the Index and Length properties of the Match class. Here's a short example implementing a weird textbox selection strategy. But it works effectively demonstrating the concept:
public partial class Form1 : Form
{
List<Error> errors = new List<Error>();
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
errors = new List<Error>();
listView1.Items.Clear();
foreach(Match m in Regex.Matches(richTextBox1.Text, #"(\(\s+|\s+\)|\[\s+|\s+\]|\{\s+|\s+\})", RegexOptions.IgnoreCase))
{
//you may decide to differentiate the msg according to the specific problem
Error error = new Error(m, "Ommit Space between a bracket");
this.errors.Add(error);
listView1.Items.Add(error.msg);
}
}
private void listView1_SelectedIndexChanged(object sender, EventArgs e)
{
if (listView1.SelectedIndices.Count > 0)
{
Error error = errors[listView1.SelectedIndices[0]];
Select(richTextBox1, error);
}
}
private static void Select(RichTextBox rtb, Error e) {
string o = rtb.Text;
rtb.Clear();
for (int i = 0; i < o.Length; i++)
{
if (i >= e.index && i <= e.index + e.length)
{
rtb.SelectionColor = Color.White;
rtb.SelectionBackColor = Color.Red;
}
else
{
rtb.SelectionColor = Color.Black;
rtb.SelectionBackColor = Color.White;
}
rtb.AppendText(o[i].ToString());
}
}
}
public class Error
{
public int index;
public int length;
public string value;
public string msg;
public Error(Match m, string msg)
{
this.index = m.Index;
this.length = m.Length;
this.value = m.Value;
this.msg = msg;
}
}
The Match object (like firstMatch) has two usefull properties here : Index and Length.
They give you the position and the length of the match in question in the original text.
With that in your knowledge, you just have to implement the highlight in the richTextBox !