PDA

Click to See Complete Forum and Search --> : Finding tab based on tag *resolved*


Colonel Klink
Sep 17th, 2003, 08:47 AM
im making an irc client...

here is the scenario

when you for example join a channel, it adds a tabpage to the tabcontrol. when this happens, i add to the newly created tabpage in its tag the channel name.

now with that in mind... say i join 2 channels... #channel1 and #channel2... the page's tag for #channel1 is #channel1 and the same for #channel2

now, when i recieve an message event, i need to know which tabpage to send the text to via its tag, and output the text to a textbox on that tab

how do i do that?

something like... if tabpage.tag = "#channel1" then print "blah" to txtbox on tabpage where tabpage.tag = "#channel1"

toto
Sep 17th, 2003, 11:51 PM
Hey Colonel,

I'm not quite sure exactly how to do this but try creating a method that auto creates a channel window, by doing something like the following. There is another method that is more complicated, but here is a possible solution.



System.Collections.Specialized.NameValueCollection chatareatext;

private void CreateWindow(string channelname)
{
string chattext = "";
chatareatext.Add(channelname, chattext);
}

private void TabChange(int i)
{
tbChatArea = (string) chatareatext[i];
}

private void ReceivedChatRoomText(string chatroom, string text)
{
for (int i = 0; i < chatareatext.Count; i++)
{
if (chatarea.Keys[i] == chatroom)
{
chatarea[i] += text;
if (tabcontrol.selectedindex == i)
{
textchatarea.Text += text;
}
return;
}
}

// if not
CreateWindow(chatroom);

// now it exists, recall self to update
ReceivedChatRoomText(string chatroom, string text);
}




:confused: :eek: :mad: :p :( :) :D ;) :rolleyes: :cool: :eek:


Mitchel

hellswraith
Sep 18th, 2003, 12:38 AM
You are going to do something like this:

string myString = "#Channel1";

foreach(TabPage page in TabControl.TabPages)
{
if(page.Text == myString)
{
// page is your tab page, do your code here.
}
}

toto
Sep 18th, 2003, 01:07 AM
Hellswraith with the simple solution!

Hey hell I wanted to use that but I can't figure out..to create the new tab page, whats the easiest way without using my own method to create a new tab page...I want to create it in the designer, then copy it over to create a new page...probably not possible like that..


Mitchel

Colonel Klink
Sep 18th, 2003, 06:29 AM
omg hellswraith you little ripper!

thanks mate :)