Roy S
posted
95 posts
since
May 01, 2010
from
Belgium
|
|
Re: Multi richtextbox with multi tab
|
|
|
|
|
|
|
|
|
|
|
The richtextbox becomes the only control of the tab so I think you can get it like this: tabControl1.SelectedTab.Controls[0]
|
|
|
|
|
|
Tanmay Sarkar
posted
194 posts
since
May 28, 2010
from
India
|
|
Re: Multi richtextbox with multi tab
|
|
|
|
|
|
|
|
|
|
|
If i wrote "hello world" in rich text box &use the code
tabControl1.SelectedTab.Controls[0]
then the data will be store as
"System.Windows.Forms.RichTextBox, Text: hello world"
not "hello world"
can you help me please!
Thank you!
|
|
|
|
|
|
theLizard
posted
598 posts
since
Oct 18, 2009
from
|
|
Re: Multi richtextbox with multi tab
|
|
|
|
|
|
|
|
|
|
|
in private void TabControl_Click(object sender, EventArgs e)
tp = (TabPage)TabControl.TabPages[TabControl.SelectedIndex]; Control[] controls = tp.Controls.Find("the name of the RichTextBox", false);
RichTextBox rt = (RichTextBox)controls[0]; rt.AppendText("Hello"); rt.SaveFile(@"the path and file name", RichTextBoxStreamType.PlainText);
to open files
rt.LoadFile(@"the path and file name", RichTextBoxStreamType.PlainText);
This is just an example,
in the click event you would get the tab text which might be something like the "c:\folder\the file.txt"
currentFile = tp.Text;
then when you want to save the file
rt.SaveFile(currentFile, RichTextBoxStreamType.PlainText);
in the click event of the RichTextBox you can set which is the current text box in the similar way
global declaration RichTextBox currentTextBox = null;
private void richTextBox1_Click(object sender, EventArgs e) { currentTextBox = (RichTextBox)sender; }
then
currentTextBox .SaveFile(currentFile, RichTextBoxStreamType.PlainText);
|
|
|
|
|
|
Tanmay Sarkar
posted
194 posts
since
May 28, 2010
from
India
|
|
Re: Multi richtextbox with multi tab
|
|
|
|
|
|
|
|
|
|
|
Thank you sir, for your long support.
when i dynamically build it, code is
private void newToolStripMenuItem_Click(object sender, EventArgs e) { TabPage tp = new TabPage(); this.tabControl1.Controls.Add(tp); RichTextBox rt = new RichTextBox(); rt.Size = new System.Drawing.Size(453, 325); rt.Dock = System.Windows.Forms.DockStyle.Fill; tp.Text = "New Doc"; tp.ImageIndex = 0; tp.Controls.Add(rt); }
And as you mention to save the richtextbox, the code is
private void saveToolStripMenuItem_Click(object sender, EventArgs e) { TabPage tp=(TabPage)tabControl1.TabPages[tabControl1.SelectedIndex]; Control[] controls = tp.Controls.Find("rt",false); RichTextBox rt1 = (RichTextBox)controls[0]; rt1.AppendText("Hello"); rt1.SaveFile(@"C:\123.rtf", RichTextBoxStreamType.PlainText); }
in control[] line, you wrote,
Control[] controls = tp.Controls.Find("the name of the RichTextBox", false);
as when i built it i use rt so i write,
Control[] controls = tp.Controls.Find("rt",false);
but it gets an exception,
System.IndexOutOfRangeException: Index was outside the bounds of the array.
help me please.
with regards,
|
|
|
|
|
|
theLizard
posted
598 posts
since
Oct 18, 2009
from
|
|
Re: Multi richtextbox with multi tab
|
|
|
|
|
|
|
|
|
|
|
As I said, you need to manage things.
You cannot declare the rich text box inside the method it must be done globally and you must have an array of text boxes.
RichTextBox[] theBoxes = new RichTextBox[0];
private void newToolStripMenuItem_Click(object sender, EventArgs e) { TabPage tp = new TabPage();
this.tabControl1.Controls.Add(tp);
tp.Name = "re" + IntToStr(this.tabControl1.TabCount);
Array.Resize(ref, theBoxes, theBoxes.Length+1) theBoxes[theBoxes.Length -1] = new RichTextBox(); theBoxes[theBoxes.Length -1].Name = tp.Name;
then to access the text box
Control[] controls = this.tabControl1.Controls.Find(tp.Name,false);
then you can do
controls[0].SaveToFile ....
I have not tested thie so you will need to work it out ...
RichTextBox rt = new RichTextBox(); rt.Size = new System.Drawing.Size(453, 325); rt.Dock = System.Windows.Forms.DockStyle.Fill; tp.Text = "New Doc"; tp.ImageIndex = 0; tp.Controls.Add(rt); }
|
|
|
|
|
|
Tanmay Sarkar
posted
194 posts
since
May 28, 2010
from
India
|
|
Re: Multi richtextbox with multi tab
|
|
|
|
|
|
|
|
|
|
|
thank you sir, it solve now! :)
|
|
|
|
|
|