I need to implement a tabbed text editor. Well, the type so that you can work with several files (one file is open in one tab, the other in another), for example, in AkelPad. I wrote a rather clumsy (and, as it turned out, not working) code. The fact is that the TextBox in a new tab does not receive the text from the open file, i.e. it remains empty. Can you tell me who knows what's the matter, what can be done here? You are welcome ;)
One more thing! If it is not difficult, how to stretch the generated text field to the full screen programmatically? Well, that the Dock property was Fill?)) Thank you.
Here is my code:
private void открытьВНовойВкладкеToolStripMenuItem_Click(object sender, EventArgs e) { // Выбор файла (для новой вкладки): openFileDialog1.ShowDialog(); if (openFileDialog1.FileName == null) return; // Ничего не делаем, если файл не выбран // Читаем... try { using (StreamReader sr = new StreamReader(openFileDialog1.FileName)) { TabPage p = new TabPage(openFileDialog1.FileName); // Присваиваем названию новой вкладки название открытого файла tabControl1.TabPages.Add(p); p.Controls.Add(new TextBox()); TextBox textbox = new TextBox(); textbox.Location = new Point(100, 100); // Местоположение нового TextBox textbox.Visible = true; // Видимость textbox.Multiline = true; // Многострочность textbox.Text = sr.ReadToEnd(); // Текст нового TextBox присваивает текст открытого файла sr.Close(); // Всем спасибо, все свободны } } catch (Exception Unknow_error) // Если ошибка (неизвестная) { MessageBox.Show(Unknow_error.Message, "Неизвестная ошибка", MessageBoxButtons.OK); // Показываем сообщение } }