Click here to Skip to main content
15,910,277 members
Home / Discussions / C#
   

C#

 
GeneralRe: Log file in C# Pin
Colin Angus Mackay28-Mar-09 10:02
Colin Angus Mackay28-Mar-09 10:02 
AnswerRe: Log file in C# Pin
King Julien27-Mar-09 23:32
King Julien27-Mar-09 23:32 
GeneralRe: Log file in C# Pin
Colin Angus Mackay28-Mar-09 9:54
Colin Angus Mackay28-Mar-09 9:54 
GeneralRe: Log file in C# Pin
King Julien29-Mar-09 19:43
King Julien29-Mar-09 19:43 
GeneralRe: Log file in C# Pin
Colin Angus Mackay29-Mar-09 21:22
Colin Angus Mackay29-Mar-09 21:22 
QuestionRaw Mouse Input (C#) Pin
Al Mendoza27-Mar-09 15:49
Al Mendoza27-Mar-09 15:49 
AnswerRe: Raw Mouse Input (C#) Pin
Eddy Vluggen28-Mar-09 1:17
professionalEddy Vluggen28-Mar-09 1:17 
QuestionNeed some help with active MDI in a tabcontrol Pin
deaddog420127-Mar-09 15:05
deaddog420127-Mar-09 15:05 
I'm having some trouble getting control on the active mdi child of a richtextbox that is inside of a tab control. All the common text editor functions work in the first richtextbox. Like a right click contextmenu, toolbar functions, font etc. Its name is RichTextBox. I have a treeview control that I added a doubleclick event that creates a new mdi tabpage in the existing tabcontrol and in that tabpage adds a new mdichild richtextbox containing the text of the file that was clicked in the double click event. The tabpage and the richtextbox are named the name of the file + 1 to the count of the current number of tabs. I also have some buttons on the main form that will open specific text files in the original richtextbox (this is easy enough since I have a static richtextbox with a name I can point to) What Im having trouble with is getting control of the currently active richtextbox. this.ActiveMdiChild does not seem to work. I would like to eliminate the static richtextbox and change all the controls in the mainform to point to the active mdichild instead. I think part of my problem maybe that the tabpage is also called as the active mdichild in order to handle my close events(this was recommended in order to have easier control in making them the active) i have put on the tab. I tried it with a different name but that didn't seem to help either. An example of one of the ways I have tried to get control is from the msdn forums. All i get

// Determine the active child form.
          Form activeChild = this.ActiveMdiChild;

          // If there is an active child form, find the active control, which
          // in this example should be a RichTextBox.
          if (activeChild != null)
          {
              try
              {
                  RichTextBox theBox = (RichTextBox)activeChild.ActiveControl;
                  if (theBox != null)
                  {
                      // Put the selected text on the Clipboard.
                      Clipboard.SetDataObject(theBox.SelectedText);

                  }
              }
              catch
              {
                  MessageBox.Show("You need to select a RichTextBox.");
              }


Th code Im using to create the new tabs with the richtextbox

System.IO.StreamReader StreamReader1 = fi.OpenText();             //reads the currently selected text file
String text = StreamReader1.ReadToEnd();
TextEditorForm editForm = new TextEditorForm();                   // creates a new instance of the mdi child form editform
TabPage childTab = new TabPage();                           //create new tab page
editForm.MdiParent = this;                                        //set as child of this form
editForm.Name = "Child" + createdTab.ToString();                  //sets the name of editform to child + 1
editForm.Text = lblFile.Text;                                     //sets the tabpage text to the file name lblfile.text is the file that is currently in the listbox
childTab.Name = editForm.Name;                                    //make sure name and text are same for easier control
childTab.Text = editForm.Text;                                    //this is for syncrhonize later
TextEditortabControl.TabPages.Add(childTab);                      //add new tab
editForm.richTxtBox.Parent = childTab;                            //attach to tab
editForm.richTxtBox.Name = editForm.Name;                         // naming the rtb the same as the rest for easier control
editForm.richTxtBox.ContextMenu = new ContextMenu();              // does not add the contextmenu
ToolStripMenuItem newtexteditMenuTab = new ToolStripMenuItem();   //create menu to hold tab
newtexteditMenuTab.Text = editForm.Text;                          //make sure the name and text are same to synchonize later
newtexteditMenuTab.Name = editForm.Name;                          // still the same name
newtexteditMenuTab.Click += new EventHandler(newMenuTab_Click);   //add event handler
TextEditortabControl.SelectTab(childTab);                         //this is to make sure that tab page is selected in the same time
editForm.EditText = text;                                         //populates the rtb with the selected text file text
editForm.Show();                                                  //as new form created so that corresponding tab and child form is active
createdTab++;                                                     //increment of course
StreamReader1.Close();


the TextEditorForm

public TextEditorForm()
            {  
                this.richTxtBox = new RichTextBox();                
                this.richTxtBox.Dock = DockStyle.Fill;                
                this.richTxtBox.Multiline = true;                
                this.richTxtBox.ScrollBars = RichTextBoxScrollBars.Vertical;
                this.richTxtBox.WordWrap = true;
                this.richTxtBox.DetectUrls = true;
                this.richTxtBox.Visible = true;
                //this.ContextMenu = new ContextMenu(); this didnt work either
               

                
                // Add the RichTextBox to the Form
                this.Controls.Add(this.richTxtBox);

            }



I know if I can just get 1 control working on the active mdi child the rest will follow easy enough.
This seems like it should work and I'm been stuck on this for a few days now scratching my head and cant figure out what I'm doing wrong maybe more eyes will help. This is my first c# application and I have only been at it for a month or so now so go easy on me lol Smile | :)
AnswerRe: Need some help with active MDI in a tabcontrol Pin
Henry Minute28-Mar-09 11:07
Henry Minute28-Mar-09 11:07 
GeneralRe: Need some help with active MDI in a tabcontrol Pin
deaddog420129-Mar-09 7:53
deaddog420129-Mar-09 7:53 
GeneralRe: Need some help with active MDI in a tabcontrol Pin
deaddog420129-Mar-09 8:21
deaddog420129-Mar-09 8:21 
GeneralRe: Need some help with active MDI in a tabcontrol Pin
Henry Minute29-Mar-09 12:16
Henry Minute29-Mar-09 12:16 
Questionnotification ballon tip Pin
AlexPizzano27-Mar-09 14:53
AlexPizzano27-Mar-09 14:53 
AnswerRe: notification ballon tip Pin
quacks_a_lot28-Mar-09 10:09
quacks_a_lot28-Mar-09 10:09 
QuestionSubmatrix problem Pin
maxflair27-Mar-09 14:42
maxflair27-Mar-09 14:42 
AnswerRe: Submatrix problem Pin
Luc Pattyn27-Mar-09 20:55
sitebuilderLuc Pattyn27-Mar-09 20:55 
GeneralRe: Submatrix problem Pin
maxflair27-Mar-09 23:16
maxflair27-Mar-09 23:16 
QuestionWPF listbox bug? Pin
Viplex27-Mar-09 14:11
Viplex27-Mar-09 14:11 
Answerpls ignore my question Pin
Viplex27-Mar-09 14:29
Viplex27-Mar-09 14:29 
QuestionCross Page Postback Pin
stormcandi27-Mar-09 11:31
stormcandi27-Mar-09 11:31 
QuestionSearching words in a matrix Pin
nike_arh27-Mar-09 10:42
nike_arh27-Mar-09 10:42 
AnswerRe: Searching words in a matrix Pin
Deresen27-Mar-09 12:02
Deresen27-Mar-09 12:02 
GeneralRe: Searching words in a matrix Pin
nike_arh27-Mar-09 12:32
nike_arh27-Mar-09 12:32 
AnswerRe: Searching words in a matrix Pin
Luc Pattyn27-Mar-09 21:21
sitebuilderLuc Pattyn27-Mar-09 21:21 
GeneralRe: Searching words in a matrix Pin
nike_arh27-Mar-09 23:27
nike_arh27-Mar-09 23:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.