Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
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 23-Dec-12 8:44am
Comments
jibesh at 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 at 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 at 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 at 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 at 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
jibesh at 23-Dec-12 15:30pm
   
Check my solution
schalk1984 at 23-Dec-12 15:53pm
   
now its giving me a error when i test it "object reference not set to an instance of an object."
 
it also create a new instance of a form with no objects
schalk1984 at 23-Dec-12 15:37pm
   
now its giving me a error when i test it "object reference not set to an instance of an object."
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Define two constructor in your TXTEditor class
 
eg:
//which is generated by default
public TXTEditor()
{
InitializeComponent();
}
 
//new Contructor
public TXTEditor(string fileName)
{
//your code goes here
}
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Thank you helped solve the problem Jibesh
 
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);
               }
           }
}
  Permalink  

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



Advertise | Privacy | Mobile
Web02 | 2.8.141022.2 | Last Updated 23 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100