用于聊天框的表单控件 (.net)

发布于 2024-07-14 13:46:23 字数 162 浏览 3 评论 0原文

当我在 vb.net(Windows 形式)中做一个小型聊天应用程序时,我在聊天框的设计上遇到了问题。 我希望文本消息是可选择的,以便用户可以复制(ctrl+v)它,但不能复制显示发送消息的用户名。 我应该使用哪些表单控件来实现此目的以及要更改哪些属性? 谢谢。 另请记住,用户名及其消息必须正确对齐。

as I am doing a small chat application in vb.net (windows form), I'm having problem for the design of my chatbox. I would like text messages to be selectable so user can copy(ctrl+v) it but not usernames which displays who sent the message. What form controls should I use in order to accomplish this and what properties to change from it? Thank you. Also keep in mind usernames and their messages must be correctly aligned.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

酒绊 2024-07-21 13:46:23

抓住 ctrl+c 并解析用户名的选定文本并删除它们

(也许你可以制作用户名图像,这将阻止标准文本复制粘贴)

catch the ctrl+c and parse the selected text for username and delete them

(maybe you can make the usernames images what will prevent standard text copy paste)

孤独难免 2024-07-21 13:46:23

您是否考虑过使用 DataGridView 控件?

您可以为用户名和消息设置单独的列,并且只允许从消息列进行复制。

如今,DataGridView 控件非常强大,并且允许您根据需要自定义外观(例如隐藏网格线以使其看起来更像文本框)。

到处都有技巧和提示,但此页面 展示如何更改网格线颜色。

Have you thought about using a DataGridView control?

You could have separate columns for the usernames and the messages and only allow copying from the message column.

The DataGridView control is extremely powerful these days and would allow you to customize the appearance however you want (hiding gridlines to make it look more like a textbox for example).

There are tips and hints all over the place, but this page shows how to change gridline colours.

十秒萌定你 2024-07-21 13:46:23

嗯,这是一个很酷的想法,但我对您的要求了解不够,不知道它是否适合您。 我首先想到的是,如果我使用聊天应用程序,我想只需单击一条消息并将其复制到剪贴板中。 毕竟,我想不出还有什么需要我点击消息来实现。 因此,如果将鼠标悬停在消息上可以使其突出显示,并且单击可以使其被复制,那就太好了。

如果这适合您的情况,那么问题是如何实现这一目标。 我认为您可以使用标签来显示发送消息的用户名,并使用只读文本框来显示消息本身。 每次将新消息添加到聊天中时,您都会插入新标签和新文本框(通过将这些控件添加到页面的控件集合中)。 可能应该将标签和文本框包装在一个 div 中,这样您就可以在它们悬停时突出显示整个 div。

现在,如何通过单击将消息文本复制到剪贴板? 这需要一些 JavaScript。 如果您正在使用 JavaScript 库,请查看它提供的功能。 如果没有,这里有一些链接。 Javascript 代码只需要获取文本框的内容,它可以通过查找正确的 css 类或正确的 id 来实现。 然后,按照以下链接所述将该文本复制到剪贴板:

用于复制到剪贴板的 Javascript< /a>

关于复制到剪贴板的 Javascript 的第二个链接

关于复制到剪贴板的 Javascript 的第三个链接

关于复制到剪贴板的 Javascript 的第四个链接

顺便说一句,也许你有要求用户应该能够选择许多消息的文本。 在这种情况下,也许单击一条消息会“选择”它,并且您可以选择多个消息。 然后,有一个“复制所有选定消息”按钮。 它唯一不能处理的是选择消息文本的一部分。 所以它可能适合也可能不适合您的需求。

Well, here's a pretty cool idea, but I don't know enough about your requirements to know if it will work for you or not. I am thinking first of all that, if I were using a chat application, I would like to simply click on a message and have it be copied into the clipboard. After all, I can't think of anything else I'd need to click on a message for. So, it would be great if hovering over a message caused it to be highlighted, and clicking caused it to be copied.

If that works for your situation, then the question is how to achieve that. I am thinking that you could use a Label to show the username who sent the message, and a readonly textbox to show the message itself. Every time a new message is added to the chat, you insert a new label and a new textbox (by adding these controls to the controls collection of the page). Probably should wrap the label and textbox in a div, so you can highlight the entire div when they hover.

Now, how do you make clicking cause the text of the message to be copied to the clipboard? It will take some JavaScript. If you're using a JavaScript library, see what it offers. If not, here are some links. The Javascript code would need to get only the contents of the textbox, which it can do by looking for the right css class or the right id's. And then, copy that text to the clipboard as described in these links:

Javascript for copying to clipboard

A 2nd link about Javascript for copying to clipboard

A 3rd link about Javascript for copying to clipboard

A 4th link about Javascript for copying to clipboard

By the way, maybe you have the requirement that users should be able to select the text of many messages. In that case, perhaps clicking on a message "selects" it, and you can have multiples selected. Then, there's a button for "Copy All Selected Messages". The only thing this doesn't handle is selecting part of the text of a message. So it may or may not be right for your needs.

仙气飘飘 2024-07-21 13:46:23

通过选择两个文本框并验证两个不同用户的用户名和密码,并使用列表框查看消息,在代码中打开一个套接字连接以在用户之间聊天。

By selecting the two text boxes and validating the username and password for two different users and take the list boxes for seeing the messages, in code open a socket connection to chat between the users.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文