Hi,
I made a tool that compares the texts from 2 richtextboxes and then marks the characters that are different in red. An option needs me to overlap these 2 text data to show the exact difference. I used a picturebox which is contained in a panel and draw the characters in respective colors using Graphics class. Everything is working fine, but for some reason I need to click the button twice to be able to see something on picturebox. There is nothing assigned as event handlers to either picturebox or panel. Below is the code for that, in the last line I used the sleep method to actually see what happens. Surprisingly when the system is in sleep for these 2 seconds, I can actually see the data correctly, but after these 2 seconds the picturebox is clear. I click on the button again and this time it stays even after the 2 seconds sleep. Please tell me where I am going wrong ? Any help is really appreciated.
Also, I am using the latest Visual Studio 2010 Beta, Ultimate version, maybe this is also a reason, but just want to make sure before I make a new project in older version. As no backward compatibility is supported by MS.
Thank You Once Again in Advance...
I made a tool that compares the texts from 2 richtextboxes and then marks the characters that are different in red. An option needs me to overlap these 2 text data to show the exact difference. I used a picturebox which is contained in a panel and draw the characters in respective colors using Graphics class. Everything is working fine, but for some reason I need to click the button twice to be able to see something on picturebox. There is nothing assigned as event handlers to either picturebox or panel. Below is the code for that, in the last line I used the sleep method to actually see what happens. Surprisingly when the system is in sleep for these 2 seconds, I can actually see the data correctly, but after these 2 seconds the picturebox is clear. I click on the button again and this time it stays even after the 2 seconds sleep. Please tell me where I am going wrong ? Any help is really appreciated.
Also, I am using the latest Visual Studio 2010 Beta, Ultimate version, maybe this is also a reason, but just want to make sure before I make a new project in older version. As no backward compatibility is supported by MS.
Thank You Once Again in Advance...
Code:
private void button2_Click(object sender, EventArgs e)
{
richTextBox1.Font = fontDialog1.Font;
richTextBox2.Font = fontDialog1.Font;
richTextBox1.Visible = false;
richTextBox2.Visible = false;
Point ptr = new Point();
pictureBox2.Show();
pictureBox2.Size = panel1.Size;
ptr = panel1.Location;
ptr.X -= 100;
ptr.Y -= 70;
panel1.Show();
Graphics g = pictureBox2.CreateGraphics();
Graphics.FromHwnd(pictureBox2.Handle);
g.Flush();
Font myFont = fontDialog1.Font;
if (richTextBox1.Text == "" || richTextBox2.Text == "")
MessageBox.Show("No Data Found !");
label1.Text = "Old Laser Checksum:";
label2.Text = "New Laser Checksum:";
getcrcs();
int x = 0, y = 0;
int y1 = 0;
int[] larr = new int[richTextBox2.Lines.GetLength(0)];
int index = 0, maxindex = 0;
foreach (String abc in richTextBox2.Lines)
{
larr[maxindex] = abc.Length;
maxindex++;
}
index = 0;
foreach (String s in richTextBox1.Lines)
{
y = 0;
ptr.Y += (int)fontDialog1.Font.GetHeight();
Point ptr1 = new Point();
ptr1 = groupBox1.Location;
ptr.X = ptr1.X;
foreach (char c in s.ToCharArray())
{
if (index < maxindex)
{
if (larr[index] > y)
{
richTextBox2.SelectionStart = x + y - y1;
richTextBox2.SelectionLength = 1;
richTextBox1.SelectionStart = x + y;
richTextBox1.SelectionLength = 1;
string temp = richTextBox2.SelectedText;
ptr.X += (int)fontDialog1.Font.Size;
foreach (char cc in temp.ToCharArray())
{
if (cc != c)
{
g.DrawString(cc.ToString(), fontDialog1.Font, Brushes.Red, new Point(ptr.X, ptr.Y));
g.DrawString(c.ToString(), fontDialog1.Font, Brushes.Red, new Point(ptr.X, ptr.Y));
if(cc == 'f' || cc == 'i' || cc == 'j' || cc == 'l' || cc == 'r' || cc == 't')
ptr.X -= 5;
if (cc == 'm' || cc == 'w')
ptr.X += 4;
}
else
{
g.DrawString(cc.ToString(), fontDialog1.Font, Brushes.Black, new Point(ptr.X, ptr.Y));
g.DrawString(c.ToString(), fontDialog1.Font, Brushes.Black, new Point(ptr.X, ptr.Y));
if (cc == 'f' || cc == 'i' || cc == 'j' || cc == 'l' || cc == 'r' || cc == 't')
ptr.X -= 5;
if (cc == 'm' || cc == 'w')
ptr.X += 4;
}
break;
}
}
}
else
{
y1++;
}
y++;
}
x += s.Length + 1;
index++;
}
panel1.Show();
stat = g.Save();
g.Flush();
Thread.Sleep(2000);
}[
Comment