RichTextBox

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tank

    RichTextBox

    I have RichTextBox in my dialog. Currently, I am loading the content from a
    file. Is there anyway to have the text 'binded' to it during compile time ?
    The idea is not to distribute the rtf file when installing the application.


  • Paul Ledger

    #2
    RE: RichTextBox

    Could you use a resource file?

    "Tank" wrote:
    [color=blue]
    > I have RichTextBox in my dialog. Currently, I am loading the content from a
    > file. Is there anyway to have the text 'binded' to it during compile time ?
    > The idea is not to distribute the rtf file when installing the application.
    >
    >
    >[/color]

    Comment

    • Tank

      #3
      Re: RichTextBox

      Er.. how ? The problem is the text consists of a mix of bolded and
      non-bolded text. Also some words use different font.

      "Paul Ledger" <PaulLedger@dis cussions.micros oft.com> wrote in message
      news:6C3CE466-6C85-4821-A619-903E35CD4AD0@mi crosoft.com...[color=blue]
      > Could you use a resource file?
      >
      > "Tank" wrote:
      >[color=green]
      > > I have RichTextBox in my dialog. Currently, I am loading the content[/color][/color]
      from a[color=blue][color=green]
      > > file. Is there anyway to have the text 'binded' to it during compile[/color][/color]
      time ?[color=blue][color=green]
      > > The idea is not to distribute the rtf file when installing the[/color][/color]
      application.[color=blue][color=green]
      > >
      > >
      > >[/color][/color]


      Comment

      • Paul Ledger

        #4
        Re: RichTextBox

        true but the underlying RTF is just tagged text....

        {\rtf1\ansi\ans icpg1252\deff0\ deflang2057{\fo nttbl{\f0\fnil\ fcharset0 Microsoft Sans Serif;}}
        \viewkind4\uc1\ pard\f0\fs17 Here is the text\par
        }

        "Tank" wrote:
        [color=blue]
        > Er.. how ? The problem is the text consists of a mix of bolded and
        > non-bolded text. Also some words use different font.
        >
        > "Paul Ledger" <PaulLedger@dis cussions.micros oft.com> wrote in message
        > news:6C3CE466-6C85-4821-A619-903E35CD4AD0@mi crosoft.com...[color=green]
        > > Could you use a resource file?
        > >
        > > "Tank" wrote:
        > >[color=darkred]
        > > > I have RichTextBox in my dialog. Currently, I am loading the content[/color][/color]
        > from a[color=green][color=darkred]
        > > > file. Is there anyway to have the text 'binded' to it during compile[/color][/color]
        > time ?[color=green][color=darkred]
        > > > The idea is not to distribute the rtf file when installing the[/color][/color]
        > application.[color=green][color=darkred]
        > > >
        > > >
        > > >[/color][/color]
        >
        >
        >[/color]

        Comment

        • Magnus Krisell

          #5
          Re: RichTextBox

          You can include the RTF file as an embedded resource and load it from
          the assembly.

          Add the file:
          Project -> Add Existing Item

          Right click on it in Solution Explorer and select:
          Build Action -> Embedded Resource

          Then use code like this to load it:

          using System.Reflecti on;

          Assembly assembly = Assembly.GetExe cutingAssembly( );
          using (Stream stream =
          assembly.GetMan ifestResourceSt ream("RTFtest.t estFile.rtf"))
          {
          richTextBox.Loa dFile(stream, RichTextBoxStre amType.RichText );
          }

          where 'RTFtest' is the default namespace for the project.

          - Magnus

          "Tank" <anonymous@disc ussions.microso ft.com> wrote in message
          news:uIDivYwaEH A.3476@tk2msftn gp13.phx.gbl...[color=blue]
          > I have RichTextBox in my dialog. Currently, I am loading the content from[/color]
          a[color=blue]
          > file. Is there anyway to have the text 'binded' to it during compile time[/color]
          ?[color=blue]
          > The idea is not to distribute the rtf file when installing the[/color]
          application.[color=blue]
          >
          >[/color]


          Comment

          • Tank

            #6
            Re: RichTextBox

            I have a rtf file "abc.rtf", namespace is MyNamespace.

            assembly.GetMan ifestResourceSt ream("MyNamespa ce.abc.rtf")) gave me an error.

            Is that the correct way to specify the resource name ?


            "Magnus Krisell" <magkr747@NOSPA Mstudent.liu.se > wrote in message
            news:O3cJ43xaEH A.1248@TK2MSFTN GP11.phx.gbl...[color=blue]
            > You can include the RTF file as an embedded resource and load it from
            > the assembly.
            >
            > Add the file:
            > Project -> Add Existing Item
            >
            > Right click on it in Solution Explorer and select:
            > Build Action -> Embedded Resource
            >
            > Then use code like this to load it:
            >
            > using System.Reflecti on;
            >
            > Assembly assembly = Assembly.GetExe cutingAssembly( );
            > using (Stream stream =
            > assembly.GetMan ifestResourceSt ream("RTFtest.t estFile.rtf"))
            > {
            > richTextBox.Loa dFile(stream, RichTextBoxStre amType.RichText );
            > }
            >
            > where 'RTFtest' is the default namespace for the project.
            >
            > - Magnus
            >
            > "Tank" <anonymous@disc ussions.microso ft.com> wrote in message
            > news:uIDivYwaEH A.3476@tk2msftn gp13.phx.gbl...[color=green]
            > > I have RichTextBox in my dialog. Currently, I am loading the content[/color][/color]
            from[color=blue]
            > a[color=green]
            > > file. Is there anyway to have the text 'binded' to it during compile[/color][/color]
            time[color=blue]
            > ?[color=green]
            > > The idea is not to distribute the rtf file when installing the[/color]
            > application.[color=green]
            > >
            > >[/color]
            >
            >[/color]


            Comment

            • Tank

              #7
              Re: RichTextBox

              Thanks. I got it. Please ignore my last post.

              "Magnus Krisell" <magkr747@NOSPA Mstudent.liu.se > wrote in message
              news:O3cJ43xaEH A.1248@TK2MSFTN GP11.phx.gbl...[color=blue]
              > You can include the RTF file as an embedded resource and load it from
              > the assembly.
              >
              > Add the file:
              > Project -> Add Existing Item
              >
              > Right click on it in Solution Explorer and select:
              > Build Action -> Embedded Resource
              >
              > Then use code like this to load it:
              >
              > using System.Reflecti on;
              >
              > Assembly assembly = Assembly.GetExe cutingAssembly( );
              > using (Stream stream =
              > assembly.GetMan ifestResourceSt ream("RTFtest.t estFile.rtf"))
              > {
              > richTextBox.Loa dFile(stream, RichTextBoxStre amType.RichText );
              > }
              >
              > where 'RTFtest' is the default namespace for the project.
              >
              > - Magnus
              >
              > "Tank" <anonymous@disc ussions.microso ft.com> wrote in message
              > news:uIDivYwaEH A.3476@tk2msftn gp13.phx.gbl...[color=green]
              > > I have RichTextBox in my dialog. Currently, I am loading the content[/color][/color]
              from[color=blue]
              > a[color=green]
              > > file. Is there anyway to have the text 'binded' to it during compile[/color][/color]
              time[color=blue]
              > ?[color=green]
              > > The idea is not to distribute the rtf file when installing the[/color]
              > application.[color=green]
              > >
              > >[/color]
              >
              >[/color]


              Comment

              • Tank

                #8
                Re: RichTextBox

                Thanks. It works fine that way.

                Another question is :

                How do I get the default namespace of the project programatically ? The idea
                is not to hardcode the parameter "RTFtest.testFi le.rtf" so that I can do
                something like this :

                assembly.GetMan ifestResourceSt ream(GetDefault ProjNameSpace() +".testFile.rtf "
                ));

                Thanks in advance.


                "Magnus Krisell" <magkr747@NOSPA Mstudent.liu.se > wrote in message
                news:O3cJ43xaEH A.1248@TK2MSFTN GP11.phx.gbl...[color=blue]
                > You can include the RTF file as an embedded resource and load it from
                > the assembly.
                >
                > Add the file:
                > Project -> Add Existing Item
                >
                > Right click on it in Solution Explorer and select:
                > Build Action -> Embedded Resource
                >
                > Then use code like this to load it:
                >
                > using System.Reflecti on;
                >
                > Assembly assembly = Assembly.GetExe cutingAssembly( );
                > using (Stream stream =
                > assembly.GetMan ifestResourceSt ream("RTFtest.t estFile.rtf"))
                > {
                > richTextBox.Loa dFile(stream, RichTextBoxStre amType.RichText );
                > }
                >
                > where 'RTFtest' is the default namespace for the project.
                >
                > - Magnus
                >
                > "Tank" <anonymous@disc ussions.microso ft.com> wrote in message
                > news:uIDivYwaEH A.3476@tk2msftn gp13.phx.gbl...[color=green]
                > > I have RichTextBox in my dialog. Currently, I am loading the content[/color][/color]
                from[color=blue]
                > a[color=green]
                > > file. Is there anyway to have the text 'binded' to it during compile[/color][/color]
                time[color=blue]
                > ?[color=green]
                > > The idea is not to distribute the rtf file when installing the[/color]
                > application.[color=green]
                > >
                > >[/color]
                >
                >[/color]


                Comment

                Working...