Click here to Skip to main content
12,946,816 members (50,081 online)
Rate this:
Please Sign up or sign in to vote.
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.
Posted 23-Dec-12 8:44am
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?
schalk1984 23-Dec-12 15:16pm

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 23-Dec-12 15:17pm
Read this Article on how to debug.

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
jibesh 23-Dec-12 15:30pm
Check my solution
schalk1984 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."
schalk1984 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
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Define two constructor in your TXTEditor class

//which is generated by default
public TXTEditor()
//new Contructor
public TXTEditor(string fileName)
//your code goes here
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

Thank you helped solve the problem Jibesh

public Form1()
       public Form1(string filename)
           if (filename != null)
                   //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);

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

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 4,919
CHill60 3,235
Maciej Los 2,508
Jochen Arndt 1,935
ppolymorphe 1,795

Advertise | Privacy | Mobile
Web02 | 2.8.170518.1 | Last Updated 23 Dec 2012
Copyright © CodeProject, 1999-2017
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