0

Edit for those who say to use tab control

I would love to use a tab control; yet i have no idea how to go about linking the tab control up from the main form. I would assume that I would have to do something like this:

  1. Create Form with a blank TabControl on it, no pages created.
  2. Create a CustomuserControl (Add -> user Control), with my controls on it.
  3. When a new chat comes in, create a tab control Item, Tab Control Page, add the Custom Control to the Tab Control Page. Add the tab control handle to the hash table, so that when new messages come in, they can be referenced in the proper control.

But, i am so not sure how to do this. For example, I know that I can create custom events inside of the User Control, so that, for example, if each control has a 'bold' button, i can each page that has that control on it, to actually USE the button.

Yet i also need to register message callbacks, so that I can use a MessageGrabber to send data to it, and tha'ts not assigned inside of the UserControl, that's assigned programatically when a new window comes in; but since I have no controls to reference, i can't assign.


KISS Philosophy

Wouldn't it be easier to just create the form, like i do now, and then just dock that form within a window or something? So that, in essence, it's still creating the form, but it's also a separate window?


Original Question

Okay, so i'm stumped (which isn't that big of a surprise when it comes to complex C# logic lol)! What i'm trying to do is the following:

Goal: Setup tabbed chatting for new chat application.

Completed: Open new window whenever a chat message is received, or a user requests a new chat from the roster. This is working perfectly, and opens only a window when the user doesn't already have the chat open. Nice and happy there.

Problem: I dont want windows. Well, i do want A window, but, i do not want tons of separate windows. For example, our Customer Service team may have about 10 active IM windows going at one time, i do not want them to have to have 10 windows tiled there lol. I'd rather they have a single Private IM window, and all 10 tabs docked within the window.

Logic: This is my logic here, which may be flawed, i do apologize:

  • OnMessage: Open new chat window if one doesn't already exist; if one exists, open it as a tab within the current chat window.
  • SendMessage: ^^ ditto ^^

Code Examples:

if (!Util.ChatForms.ContainsKey(msg.From.Bare))
            {
                RosterNode rn = rosterControl1.GetRosterItem(msg.From);
                string nick = msg.From.Bare;
                if (rn != null)
                    nick = rn.Text;
                frmChat f = new frmChat(msg.From, xmpp, nick);
                f.Show();
                f.IncomingMessage(msg);
                return;
            }

Note on above: The Util. function just keeps tracks of what windows are opened inside of a hashtable, that way, when messages come in, they route to the proper window. That is added with the:

Util.ChatForms.Add(m_Jid.Bare.ToLower(), this);

Command in the frmChat() form.

Library in Use: agsxmpp from: http://www.ag-software.de/agsxmpp-sdk/download/

Problem: How can i convert this code to open inside of tabs, instead of windows? Can someone please give me some ideas, and help with that. I just can't seem to wrap my head around that concept.

  • It seems that you have bad design here. More common way to do such things is to have list of 'User' objects wich have list of 'Message' object and expose 'MessageArrived' event. When you create new chat window (or tab) it subscribes to 'MessageArrived' event of corresponding user and updates itself when needed. – Poma Apr 24 '11 at 07:12
  • Would you possibly have a code example of what you are referring too? I'm not an expert at C# yet, so i can only do what I know, or what I find on the inet or in training manuals. An example would help me GREATLY. –  Apr 25 '11 at 16:15
  • I decided, that since i already had a tab control on my main form, that i'd just handle the tab creation there; as i can't seem to get it to create tabs on a new window i'll just use what i already have. Would have love to seen a resolve here, or seen a code example for MDI chidlren, but in all, at least it's working with tabs. Selected the below answer as the accepted, but would have liked other options too :) –  Apr 26 '11 at 13:25

1 Answers1

0

Use TabControl

Poma
  • 8,174
  • 18
  • 82
  • 144
  • These are my assumptions from your answer: **Create new window**, make the tab control modifiers public, in main form, create a new tab whenever the window already exists. In the Util.Add() command make it add the tabControl as the actual ID added. And then highlight the tab when messages come in. Is this what you mean? –  Apr 23 '11 at 14:58
  • Yep. But I think it's better to create window when app starst, just dont show it. Also set WindowClosing handler so that when user hits close button window actually hides. Because of that when user closes chat window and then new message arrives window will 'restore' all tabs opened before. – Poma Apr 24 '11 at 07:06
  • I assume by creating the window already, and just ensuring it's hidden when application is running, that will get around the 'Null Reference Exceptions', that i'm seeing when trying to add tabs to the new window. –  Apr 25 '11 at 16:03