C#

Moderators: None (Apply to moderate this forum)
Number of threads: 2722
Number of posts: 5749

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Problem with tabs Posted by leeq3 on 7 Mar 2009 at 4:49 PM
Hi.
My goal is to create a text editor with tabs, so I can open multiple files in tabs. My problem is that i cannot access controls in tab pages. I can only access first page. I designed first page in visual editor. Other pages may be created by clicking specified button.

Code of this button (click event):

private void tripNewpage_Click(object sender, EventArgs e)
{
    TabPage newtab = new TabPage("new");
    MyTabs.Controls.Add(newtab);
    RichTextBox rchText = new RichTextBox();
    rchText.Name = "rchText";
    rchText.ContextMenuStrip = contextMenuStrip1;
    rchText.Dock = DockStyle.Fill;
    MyTabs.SelectedTab = newtab;
    newtab.Controls.Add(rchText);
}


This creates a new tab with a richtextbox control. I'm able to write inside the control, but i cannot use functions i used in first page.

Code of button that edites rchText control which is automatically created in first tab after running program:

private void tripBold_Click(object sender, EventArgs e)
        {
                if (rchText.SelectionFont == null)
                {
                    return;
                }

                FontStyle style = rchText.SelectionFont.Style;

                if (rchText.SelectionFont.Bold)
                {
                    style &= ~FontStyle.Bold;
                }
                else
                {
                    style |= FontStyle.Bold;
                }
                rchText.SelectionFont = new Font(rchText.SelectionFont, style);
                rchText.Select();
        }


I want this button (bold function) to work with new richtextboxes created by tripNewpage_Click function.

How to do that?

Sorry for my english.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.