-3

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
    When asking a question about a problem caused by your code, you will get much better answers if you provide code people can use to reproduce the problem. See http://stackoverflow.com/help/mcve – Baddack Dec 27 '16 at 23:18
  • 1
    [edit] your question and add the code. Be sure to format it aswell – Jeremy Thompson Dec 28 '16 at 01:32

1 Answers1

0

Have a look at this link. It worked for me

http://www.hanselman.com/blog/TheWeeklySourceCode31SingleInstanceWinFormsAndMicrosoftVisualBasicdll.aspx