RichTextBox.RTF not updating properly? Please help!!

S

Speebs

Hello,

I have a little form that people can fill out to generate CD labels
from an RTF template. The template basically contains variables that
are replaced by the text typed into the form.

I also have a "Preview" tab which will show a RichTextBoxcontaining
the output of the label generator (ie. the template, with the
variables replaced).

I am able to load the template into a RichTextBox without problems.
This gives me a RichTextBox containing a CD label with words like
%MIDDLE-LEFT% and the other variables.

Then I have the code below, which replaces the text with whatever is
in the user-edited textboxes (eg. txtMiddleLeft.Text):

Code:
txt_Preview.Rtf = templateRTFText  // this works fine
tmpVar = Replace(templateRTFText, "%MIDDLE-LEFT%",
txtMiddleLeft.Text, , , CompareMethod.Text)  // this works fine
txt_Preview.Rtf = "" // this works fine!
txt_Preview.Rtf = tmpVar // this does not work!

This does not work. The variable tmpVar ends up with the correct,
updated data (I checked by copying it to the clipboard and pasting it
into a new RTF file- the variables were replaced). But the
RichTextBox still contains the template text. If I copy
txt_Preview.Rtf to the clipboard, it still contains the template data.

No errors are generated when I run the last line. Can someone please
help me! How should I be accomplishing this?

Note that I am not using PrintPreviewDialog because I need this to
appear inside an existing tab, and I also have not been able to get
PrintPreviewDialog to work properly (I have limited time for this
project).

Thank you.
 
C

Chris Dunaway

Hello,

I have a little form that people can fill out to generate CD labels
from an RTF template. The template basically contains variables that
are replaced by the text typed into the form.

I also have a "Preview" tab which will show a RichTextBoxcontaining
the output of the label generator (ie. the template, with the
variables replaced).

I am able to load the template into a RichTextBox without problems.
This gives me a RichTextBox containing a CD label with words like
%MIDDLE-LEFT% and the other variables.

Then I have the code below, which replaces the text with whatever is
in the user-edited textboxes (eg. txtMiddleLeft.Text):

Code:
txt_Preview.Rtf = templateRTFText  // this works fine
tmpVar = Replace(templateRTFText, "%MIDDLE-LEFT%",
txtMiddleLeft.Text, , , CompareMethod.Text)  // this works fine
txt_Preview.Rtf = "" // this works fine!
txt_Preview.Rtf = tmpVar // this does not work!

This does not work. The variable tmpVar ends up with the correct,
updated data (I checked by copying it to the clipboard and pasting it
into a new RTF file- the variables were replaced). But the
RichTextBox still contains the template text. If I copy
txt_Preview.Rtf to the clipboard, it still contains the template data.

No errors are generated when I run the last line. Can someone please
help me! How should I be accomplishing this?

Note that I am not using PrintPreviewDialog because I need this to
appear inside an existing tab, and I also have not been able to get
PrintPreviewDialog to work properly (I have limited time for this
project).

Thank you.

Have you set a breakpoint on that line and confirmed that it is being
executed? Something else must be setting the value back. Can you
post a short but complete program that demonstrates the problem?

Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top