Click here to Skip to main content
15,892,697 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I'm designing my own text editor but i'm having bit of a problem.

what I'm trying to do is when you double click on the txt file my program opens up but does not display any text.

I have search the web but all I found is not complete code that I can use in my text editor.

please help.
regards
Posted
Comments
Jibesh 23-Dec-12 14:57pm    
without looking at your code we cannot provide you a better or any solution. the information you posted doesnt reveal anything to us. try debugging your code where you load the file and see what's happening there and post the code what is not working.
schalk1984 23-Dec-12 15:11pm    
the problem is that if i double click on any txt file it only shows a blank textbox.
i don't have any code that makes sense to me that opens a txt in my textbox.

and sorry if you can tell me how to debug using a text file first please?
Jibesh 23-Dec-12 15:17pm    
Read this Article on how to debug. http://www.codeproject.com/Articles/79508/Mastering-Debugging-in-Visual-Studio-2010-A-Beginn

You said you double click on a file and your application open up. it doesnt mean that you done with your application. You need to understand the basics and the process involved in a text editor like load file from the disk and display the file content and later save the file contents to the disk etc etc. so try to search on the net with these information and its not that big task. you can do it and you can find lot of sample code for editors by googling.
schalk1984 23-Dec-12 15:26pm    
my program can open,save, print a file with no problem that is only if my program starts up first and then open a file - no problem here.
but when i double click it does not display any text.

and i did check most sample but none has this code in them
schalk1984 23-Dec-12 15:16pm    
http://www.c-sharpcorner.com/blogs/3308/double-click-on-your-fileextension-open-it-with-your-exe.aspx

is the closes i have found but it gives me a few errors
Error 1 'TXTEditor.Form1' does not contain a constructor that takes 0

what can i do to fix this

Define two constructor in your TXTEditor class

eg:
C#
//which is generated by default
public TXTEditor()
{
InitializeComponent();
}

//new Contructor
public TXTEditor(string fileName)
{
//your code goes here
}
 
Share this answer
 
Thank you helped solve the problem Jibesh

C#
public Form1()
       {
           InitializeComponent();
       }
       public Form1(string filename)
       {
           InitializeComponent();

           if (filename != null)
           {
               try
               {
                   //textBox1.LoadFile(filename); remove this line
                   StreamReader reader = new StreamReader(filename);
                   char[] data = new char[filename.Length];
                   reader.ReadBlock(data, 0, (int)filename.Length);
                   textBox1.Text = new string(data);
                   reader.Close();// and add these lines
               }
               catch (Exception ex)
               {
                   MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
               }
           }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900