Thread: Text Editor

  1. #1
    Registered User
    Join Date
    Feb 2005
    Posts
    38

    Text Editor

    I am finishing up my text editor that saves the font and size and then displays the text according to the saved info. So far I have the program writing the font name and size then $$ to mark the end of my font info and the beginning of the saved text.

    First problem. Everytime I save the file it writes the font and size again. Suggestions?

    Second problem. When I display the file I want only the text to show. More suggestions?

    Code:
    private: System::Void OpenBtn_Click(System::Object *  sender, System::EventArgs *  e)
    			 {
    	OpenFileDialog * fd = new OpenFileDialog();
    	if(fd->ShowDialog() == DialogResult::OK)
    	{
    	FileStream * fs = new FileStream(fd->FileName,  FileMode::Open);
    	StreamReader * sr = new StreamReader(fs);
    	String * s = sr->ReadLine();
    	 textBox1->Text = s;
    	sr->Close();
    	}
        }
    
    	private: System::Void SaveBtn_Click(System::Object *  sender, System::EventArgs *  e)
    			 {
    				SaveFileDialog * fd = new SaveFileDialog();
              if(fd->ShowDialog() == DialogResult::OK)
                  {
    	FileStream * fs = new FileStream(fd->FileName, FileMode::OpenOrCreate);
    	StreamWriter * sw = new StreamWriter(fs);
    	sw->Write(textBox1->Font->Name);
    	sw->Write(textBox1->Font->Size);
    	sw->Write("$$");
    	sw->WriteLine(textBox1->Text);
    	sw->Flush();
    	sw->Close();
               }
          }
    
    private: System::Void FontBtn_Click(System::Object *  sender,      System::EventArgs *  e)
    			 {
             FontDialog* fd = new FontDialog();
             fd->Font = FontLine;
    				
              if(fd->ShowDialog() == DialogResult::OK)
    	{
    	 FontLine = fd->Font;
    	 textBox1->Font = FontLine;
    	 }
              }
         };
    }

  2. #2
    Registered User
    Join Date
    Aug 2002
    Location
    Hermosa Beach, CA
    Posts
    446
    Can't you just save the Font and size in the registry, and then save the user data as text?
    The crows maintain that a single crow could destroy the heavens. Doubtless this is so. But it proves nothing against the heavens, for the heavens signify simply: the impossibility of crows.

  3. #3
    Shibby willc0de4food's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    378
    yes - you can :]
    RegCreateKeyEx
    in the left hand pane there are all of the other registry functions that you'll need for querying / closing the registry keys as needed.

    also - check this out: http://www.endurasoft.com/techtalk/regdemo1.htm
    Last edited by willc0de4food; 12-12-2005 at 07:09 PM.
    Registered Linux User #380033. Be counted: http://counter.li.org

  4. #4
    Registered User
    Join Date
    Feb 2005
    Posts
    38
    Can't save to the registry. The information is supposed to be saved to a file and when the file is open, my text editor will read the font name and size then display as such.

    Was actually trying to use fontfamily.
    Last edited by MB1; 12-13-2005 at 11:41 AM.

  5. #5
    Registered User
    Join Date
    Aug 2002
    Location
    Hermosa Beach, CA
    Posts
    446
    It looks like you are using .NET to code this, so why not make the file format be XML, since there are classes in the Framework for reading XML format files. Then you could do something like:

    Code:
    <File>
    <Font>Times New Roman</Font>
    <FontSize>16</FontSize>
    <Body>Hello World!</Body>
    </File>
    The crows maintain that a single crow could destroy the heavens. Doubtless this is so. But it proves nothing against the heavens, for the heavens signify simply: the impossibility of crows.

  6. #6
    Registered User
    Join Date
    Feb 2005
    Posts
    38
    My file shows the font and size then ##

    like this->Microsoft Sans Serif8.25## testing one two three

    When I open the file, text editor is supposed to read the saved format of Microsoft Sans Serif and font size 8.25 then output "testing one two three" in that font and size.

    I need the code to put in my open button click handler so that this happens.

    Your <font> sounds easy. I can't do it that way.
    Last edited by MB1; 12-13-2005 at 02:21 PM.

  7. #7
    Registered User
    Join Date
    Aug 2002
    Location
    Hermosa Beach, CA
    Posts
    446
    Doesn't the String class have a split method, i.e. you could split the text from the ReadLine call using "##" as the characters to split on. But how do you know where the Font ends and the Size begins?
    The crows maintain that a single crow could destroy the heavens. Doubtless this is so. But it proves nothing against the heavens, for the heavens signify simply: the impossibility of crows.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. creating very simple text editor using c
    By if13121 in forum C Programming
    Replies: 9
    Last Post: 10-19-2010, 05:26 PM
  2. C++ For Text Editor?
    By bmroyer in forum C++ Programming
    Replies: 12
    Last Post: 04-05-2005, 02:17 AM
  3. struct question
    By caduardo21 in forum Windows Programming
    Replies: 5
    Last Post: 01-31-2005, 04:49 PM
  4. help about text editor
    By nag in forum C++ Programming
    Replies: 2
    Last Post: 04-24-2003, 11:45 AM
  5. Making a text editor
    By neandrake in forum C++ Programming
    Replies: 5
    Last Post: 02-26-2002, 11:43 PM