I'm having trouble with a bit of code here. What I'm trying to do is paste multiple images(generated from a helper function) into a RichTextBox. Here's my code:
string tempText = "For the arithmetic progression $a_1, a_2, a_3, ... a_9$ it's known that $a_2 + a_8 = 8$. The sum $a_1 + a_2 + a_4 + a_5 + a_6 + a_8 + a_9$ is equal to:\nA) 14;\tB) 16;\tC) 36;\tD) 32.";
for (int i = 0, lastOcc = 0, numDoll = 0; i < tempText.Length; i++)
{
if (tempText[i] == '$')
{
numDoll++;
if (numDoll % 2 == 1)
{
problemText.Text += tempText.Substring(lastOcc, i - lastOcc);
}
else
{
string equation = tempText.Substring(lastOcc, i - lastOcc);
MessageBox.Show(equation);
try
{
CreateGifFromEq(equation, "temp.gif");
Bitmap eq = new Bitmap("temp.gif");
//eq.Dispose();
Clipboard.SetDataObject(eq);
DataFormats.Format f = DataFormats.GetFormat(DataFormats.Bitmap);
//problemText.ReadOnly = false;
this.problemText.Paste(f);
eq.Dispose();
//problemText.ReadOnly = true;
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
lastOcc = i + 1;
}
}
problemText.Text += tempText.Substring(tempText.LastIndexOf('$') + 1, tempText.Length - tempText.LastIndexOf('$') - 1);
The images generate without any problem, and the text seperates properly. Only problem I'm seeing is pasting.
The following on a seperate blank project, however, works without any problems:
try
{
CreateGifFromEq("a_1, a_2, a_3, ... a_9", "temp.gif");
Bitmap eq = new Bitmap("temp.gif");
Clipboard.SetDataObject(eq);
DataFormats.Format f = DataFormats.GetFormat(DataFormats.Bitmap);
this.problemText.Paste(f);
eq.Dispose();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
What do I seem to be missing?
P.S. I CAN paste images manually.