C# double click files to open in notepad tabs

225 views Asked by At

How to double click on text files to open in notepad in seperate tabs?

Please point me in the right direction.

In my program.cs I use the following:

 static void Main(string[] args)
    {
        String thisprocessname = Process.GetCurrentProcess().ProcessName;
        if (Process.GetProcesses().Count(p => p.ProcessName == thisprocessname) > 1)
        {
            return;
        }
if (args.Length != 0)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1(args[0]));
        }
        else
        Application.Run(new Form1());
    }

In my main.cs I use the following:

 public Form1(string filename)
    {

        InitializeComponent();

            if (filename != null)
        {
            try
            {
        StreamReader sr = new StreamReader(filename);
        tabtitlecount = count.ToString();
        TabPage tp = new TabPage(sub_title + tabtitlecount);
        RichTextBox rtb = new RichTextBox();
        rtb.Dock = DockStyle.Fill;
        tp.Controls.Add(rtb);
        tabControl1.TabPages.Add(tp);
        this.tabControl1.SelectedTab = tp;
                this.GetRichTextBox().Text = sr.ReadToEnd();
                sr.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
    }

Obviously with the above mentioned code, when I double click on a text file, it opens the application with the text file in it's own tab (which is correct), however, when I double click on a second text file, it doesn't do anything - where is should open the second text file in it's own tab again.

What I would like to do is to open a text files with a double click in their own tabs without opening multiple instances of the same application.

1

There are 1 answers

0
Jaco Hendriks On