coperations07
asked on
Template for .rtf
Hi,
I'm trying to create a program to organize the apps at my company. I've set up a VB.Net form w/ a richTextBox that gets populated w/ an rtf file when a user selects an app from a drop down box. I want to keep these rtf files in a consistent format. Something like....
About:
(Words go here...)
Installation:
(Words go here...)
Developer:
(Words go here...)
I'd like it to be to where the About,Installation,Develop er....cann ot be edited or deleted, but everything else can. What might be the best way to do this?
Thanks,
Dave
I'm trying to create a program to organize the apps at my company. I've set up a VB.Net form w/ a richTextBox that gets populated w/ an rtf file when a user selects an app from a drop down box. I want to keep these rtf files in a consistent format. Something like....
About:
(Words go here...)
Installation:
(Words go here...)
Developer:
(Words go here...)
I'd like it to be to where the About,Installation,Develop
Thanks,
Dave
If developer's richtextbox text length will increase a scroll bar will be appear :)
ASKER
Is there a way to do this with a single rtb or is multiple the only way to go? There's probably 50 or so Apps and there's probably a couple more titles I'll put in the rtb. That's gonna be a lot of rtf files to house if I have to have a seperate rtf for each title. It's not terrible I don't guess, but I'd rather have 1 file per app if possible.
One way as I see:
Public Class Form1
Public list As List(Of String)
Public templates() As String = New String() {"About", "Installation", "devlopers"}
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
LoadTemplates()
End Sub
Private Sub LoadTemplates()
ComboBox1.Items.AddRange(CType(templates, Object))
For Each i In ComboBox1.Items
RichTextBox1.SelectionFont = New Font(RichTextBox1.SelectionFont.FontFamily, 14.0F, FontStyle.Bold) ' if default size is 12 you heading should be greater like 14
RichTextBox1.Text += i.ToString() + ":" + vbCrLf + vbCrLf + vbCrLf + vbCrLf
RichTextBox1.SelectionFont = New Font(RichTextBox1.SelectionFont.FontFamily, FontStyle.Bold)
Next
End Sub
End Class
RunTimeView.PNG
specify items in this array:
Public templates() As String = New String() {"About", "Installation", "devlopers" , ............}
it will load template from combobox.
Public templates() As String = New String() {"About", "Installation", "devlopers" , ............}
it will load template from combobox.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Yes I know it is editable but template is a predefine structure, which is declared by the designer, so will just enter the text between headings.
Hello, coperations07,
Re: "That's gonna be a lot of rtf files to house if I have to have a seperate rtf for each title. "
I like wizzie83's suggestion. You can combine the RTF from each of the RichTextBoxes before saving to a single file.
Cheers,
Randy
Re: "That's gonna be a lot of rtf files to house if I have to have a seperate rtf for each title. "
I like wizzie83's suggestion. You can combine the RTF from each of the RichTextBoxes before saving to a single file.
Cheers,
Randy
ASKER
Yeah I could combine, but that would change a lot. I would like to view and edit from the same form. I'd have to have a different rtb to bring the combined rtf back into so it could be viewed later. And it will also be edited when different versions, bug fixes,....etc happen.
Hi, coperations07,
Maybe I'm missing something because I don't know all of your requirements/constraints, but this doesn't seem so difficult to me.
When you combine the sections, just embed your own "custom" RTF codes as delimiters. Then when it is time to view (or edit) you use these delimiters to divide the imported RTF text into sections. You could use a different "sub-code" for each section and use the sub-codes to allocate the sections to the appropriate RichTextBox. This way, new sections introduced (or old sections removed) during version changes won't make pre-existing RTF files unusable.
Cheers,
Randy
p.s. RTF reader applications should ignore codes they do not recognize, so as long as your custom codes are unique they should not cause problems for other apps that may read your files.
Maybe I'm missing something because I don't know all of your requirements/constraints, but this doesn't seem so difficult to me.
When you combine the sections, just embed your own "custom" RTF codes as delimiters. Then when it is time to view (or edit) you use these delimiters to divide the imported RTF text into sections. You could use a different "sub-code" for each section and use the sub-codes to allocate the sections to the appropriate RichTextBox. This way, new sections introduced (or old sections removed) during version changes won't make pre-existing RTF files unusable.
Cheers,
Randy
p.s. RTF reader applications should ignore codes they do not recognize, so as long as your custom codes are unique they should not cause problems for other apps that may read your files.
ASKER
I think this is what I'm looking for omegaomega. I'm not familiar with using rtf for anything like this, so this was kind of what I was asking. Could you give me a good starting point for using sections w/ rtf?
thx,
Dave
thx,
Dave
Hello, coperations07,
See the attached snippet for a simple example using wizzie83's idea and the sections you have specified. The form contains three RichTextBoxes with three corresponding labels, a TextBox that specifies the file name and two Buttons, one for loading the specified file and one for saving to the specified file. For clarity I have attached an image of the sample application in use.
You will see that (unlike wizzie83's suggestion) I prefer to keep borders around the RichTextBoxes to show their boundaries. As Shahan_Developer points out, scroll bars will appear if the text exceeds the boundaries, so we might as well show the user where those boundaries are.
Beginning and closing the main RTF section (as indicated in the comments within the cmdSave_Click method) allows the file saved by this application to be opened by other applications that can read RTF files (such as MS-Word).
Cheers,
Randy
See the attached snippet for a simple example using wizzie83's idea and the sections you have specified. The form contains three RichTextBoxes with three corresponding labels, a TextBox that specifies the file name and two Buttons, one for loading the specified file and one for saving to the specified file. For clarity I have attached an image of the sample application in use.
You will see that (unlike wizzie83's suggestion) I prefer to keep borders around the RichTextBoxes to show their boundaries. As Shahan_Developer points out, scroll bars will appear if the text exceeds the boundaries, so we might as well show the user where those boundaries are.
Beginning and closing the main RTF section (as indicated in the comments within the cmdSave_Click method) allows the file saved by this application to be opened by other applications that can read RTF files (such as MS-Word).
Cheers,
Randy
Imports System.IO
Public Class Form1
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
txtFile.Text = "D:\Tests\VB Trials\RTF Example\Sample1.rtf"
End Sub
Private Sub cmdSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSave.Click
Dim swrFile As StreamWriter = Nothing
Try
swrFile = New StreamWriter(txtFile.Text)
swrFile.Write("{\rtf1 ") ' Begin main rtf section.
swrFile.Write("\wwSection About: \par " & rtbAbout.Rtf)
swrFile.Write("\wwSection Installation: \par " & rtbInstallation.Rtf)
swrFile.Write("\wwSection Developer: \par " & rtbDeveloper.Rtf)
swrFile.Write("}") ' Close main rtf section.
Catch ex As Exception
MsgBox("Failed to save file!" & vbCrLf & vbCrLf & ex.Message)
Finally
If (swrFile IsNot Nothing) Then
swrFile.Close()
End If
End Try
End Sub
Private Sub cmdLoad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdLoad.Click
Dim srdFile As StreamReader = Nothing
Try
srdFile = New StreamReader(txtFile.Text)
Dim straDelimiter() As String = {"\wwSection"}
Dim straRTF() As String = srdFile.ReadToEnd().Split(straDelimiter, StringSplitOptions.RemoveEmptyEntries)
For Each strRTF As String In straRTF
If (strRTF.StartsWith(" About: \par ")) Then
rtbAbout.Rtf = strRTF.Substring(13)
ElseIf (strRTF.StartsWith(" Installation: \par ")) Then
rtbInstallation.Rtf = strRTF.Substring(20)
ElseIf (strRTF.StartsWith(" Developer: \par ")) Then
rtbDeveloper.Rtf = strRTF.Substring(17)
End If
Next strRTF
Catch ex As Exception
MsgBox("Failed to load file!" & vbCrLf & vbCrLf & ex.Message)
Finally
If (srdFile IsNot Nothing) Then
srdFile.Close()
End If
End Try
End Sub
End Class
RTF-Example.jpg
Thanks, SouthMod.
Hi, coperations07,
I suggest that you mark wizzie83's first post (ID: 32991594) as the answer as it shows the basis of the solution. You might mark my post ( ID: 33009169) as an assisted solution. You could allocate all the points to wizzie83 (as I'm not here for the points anyway).
Cheers,
Randy
Hi, coperations07,
I suggest that you mark wizzie83's first post (ID: 32991594) as the answer as it shows the basis of the solution. You might mark my post ( ID: 33009169) as an assisted solution. You could allocate all the points to wizzie83 (as I'm not here for the points anyway).
Cheers,
Randy
ASKER
Thanks for the help guys. I'll probably post a follow up question later because I haven't gotten this to work like I need it to yet. I'll wait until I have more time to work on it though.
Above the 3 richtextboxes but a label with the title.
form.png