用于 IP 地址的 C# 组合框
我需要一个保存 IP 地址的自定义组合框。我有一个保存 IP 地址的自定义控件(实际上是一个带有 4 个文本框的面板)。我已经尝试将其他控件添加到普通组合框,例如按钮和文本框。我没有例外,但我希望在下拉列表中看到该项目,而不是每个项目都有一个空行。
我对此的第一个想法是扩展 ComboBox 控件。你有什么建议?
I need a custom combo box that holds IP addresses. I have a custom control that holds an IP address(that actually is a panel with 4 textboxes). I already tried adding other controls to a normal combo box, such as a button and a textbox. I get no exceptions but I would expect to see the item in the drop-down list, instead i get a blank line for each item.
My first thoughts about this would be to extend the ComboBox control. What would you suggest?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
为了方便起见,组合框基本上是一个文本框和一个(通常)按钮激活的列表框的组合。如果不方便,您可以实现自己的下拉功能。在显示列表框的文本框旁边放置一个按钮,当从列表框中选择某个项目时,将值放入相应的文本框中。换句话说,不要尝试扩展组合框,而是尝试基于类似的组件重新构建类似的控件。
A combo box is basically a textbox and a (usually) button-activated listbox combined for convenience. If it's not convenient you could implement your own dropdown functionality. Put a button next to your textboxes that display a listbox and when an item is selected from the listbox, put the values in the appropriate textboxes. In other words, don't try to extend the combo box, try to re-construct a similar control based on similar components.
覆盖
ComboBox
并不太困难,因此我想您可以创建一个自定义ComboBox
来显示您自己的控件,该控件将是一个显示多个 IP 地址控件的容器。这是 博客文章,作者 < a href="https://stackoverflow.com/users/23283/jaredpar">JaredPar 显示了如何开始,只需将 m_form 替换为您自己的自定义容器控件即可。
It's not too difficult to override the
ComboBox
so I suppose you could create a customComboBox
to show your own control that would be a container showing multiple of your IP Address controls.Here's a blog article by JaredPar showing how to get started, just replace the m_form with your own custom container control.
您可以将 IP 地址保存在列表框中,甚至可以保存在组合框或您想要的任何内容中。不要忘记你的编码是如何的,如果你有一个基于 oop 的 tcp-socket 程序,那么不会抛出跨线程异常。代码应类似于 ListBox.Items.Add(ipaddress) 或 ComboBox.Items.Add(ipaddress) ...
在控件中,您可以只保存 ip 地址,如果您想存储套接字对象,请使用 Dictionary ...您的答案不清楚,所以我已经回答了可能的情况。
You can hold the ip-addresses in a listbox, even in a combobox or what ever you want. Do not forget how your coding is, if you have an oop based tcp-socket program than no cross thread exception will be thrown. the codes shall be like ListBox.Items.Add(ipaddress) or ComboBox.Items.Add(ipaddress) ...
In controls you may hold only the ip-addresses, if you want to store the socket objects use Dictionary ... Your answer is not clear, so i've answered on possibly situations.