Dock Windows Forms(选项卡式聊天界面)
为那些说使用选项卡控件的人进行编辑
我很想使用选项卡控件;但我不知道如何从主窗体链接选项卡控件。我假设我必须这样做:
- 创建带有空白 TabControl 的表单,不创建页面。
- 创建一个 CustomuserControl(添加 -> 用户控件),其中包含我的控件。
- 当新的聊天进来时,创建一个选项卡控件项目,选项卡控制页面,将自定义控件添加到选项卡控制页面。将选项卡控件句柄添加到哈希表中,以便当新消息进入时,可以在适当的控件中引用它们。
但是,我非常不知道该怎么做。例如,我知道我可以在用户控件内部创建自定义事件,因此,例如,如果每个控件都有一个“粗体”按钮,我可以在每个具有该控件的页面上实际使用该按钮。
然而,我还需要注册消息回调,以便我可以使用 MessageGrabber 向其发送数据,并且这不是在 UserControl 内部分配的,而是在新窗口进入时以编程方式分配的;但由于我没有可供参考的控件,因此我无法分配。
KISS 哲学
像我现在一样创建表单,然后将该表单停靠在窗口或其他东西中不是更容易吗?那么,本质上,它仍然在创建表单,但它也是一个单独的窗口?
原始问题
好吧,我很困惑(对于复杂的 C# 逻辑来说,这并不是什么大惊喜,哈哈)!我想做的是:
目标:为新的聊天应用程序设置选项卡式聊天。
已完成:每当收到聊天消息或用户请求名册中的新聊天时,都会打开新窗口。这工作得很好,当用户尚未打开聊天时仅打开一个窗口。那里美好又快乐。
问题:我不需要窗户。好吧,我确实想要一个窗口,但是,我不想要大量单独的窗口。例如,我们的客户服务团队可能同时有大约 10 个活动 IM 窗口,我不希望他们必须将 10 个窗口平铺在那里,哈哈。我宁愿他们有一个私人 IM 窗口,并且所有 10 个选项卡都停靠在该窗口内。
逻辑:这是我的逻辑,可能有缺陷,我深表歉意:
- OnMessage:如果尚不存在,则打开新的聊天窗口;如果存在,请将其作为当前聊天窗口中的选项卡打开。
- SendMessage:^^ 同上 ^^
代码示例:
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;
}
上述注释:Util。函数只是跟踪哈希表中打开的窗口,这样,当消息进入时,它们会路由到正确的窗口。这是用
Util.ChatForms.Add(m_Jid.Bare.ToLower(), this);
frmChat() 形式的命令添加的。
正在使用的库:agsxmpp,来自:http://www. ag-software.de/agsxmpp-sdk/download/
问题: 我如何转换此代码以在选项卡内部打开,而不是在窗口中打开?有人可以给我一些想法并提供帮助吗?我似乎无法理解这个概念。
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:
- Create Form with a blank TabControl on it, no pages created.
- Create a CustomuserControl (Add -> user Control), with my controls on it.
- 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 TabControl
Use TabControl