[英]C# ComboBox for IP addresses
I need a custom combo box that holds IP addresses.我需要一个包含 IP 地址的自定义组合框。 I have a custom control that holds an IP address(that actually is a panel with 4 textboxes).
我有一个自定义控件,其中包含一个 IP 地址(实际上是一个带有 4 个文本框的面板)。 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.我对此的第一个想法是扩展 ComboBox 控制。 What would you suggest?
你有什么建议?
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.
换句话说,不要试图扩展组合框,尝试基于相似的组件重新构造一个相似的控件。
It's not too difficult to override the ComboBox
so I suppose you could create a custom ComboBox
to show your own control that would be a container showing multiple of your IP Address controls.覆盖
ComboBox
并不难,所以我想您可以创建一个自定义ComboBox
来显示您自己的控件,该控件将是一个显示多个 IP 地址控件的容器。
Here's a blog article by JaredPar showing how to get started, just replace the m_form with your own custom container control.这是JaredPar的 一篇博客文章,展示了如何开始,只需将 m_form 替换为您自己的自定义容器控件即可。
You can hold the ip-addresses in a listbox, even in a combobox or what ever you want.您可以将 IP 地址保存在列表框中,甚至在 combobox 或任何您想要的东西中。 Do not forget how your coding is, if you have an oop based tcp-socket program than no cross thread exception will be thrown.
不要忘记你的编码是怎样的,如果你有一个基于 oop 的 tcp-socket 程序,那么不会抛出跨线程异常。 the codes shall be like ListBox.Items.Add(ipaddress) or ComboBox.Items.Add(ipaddress)...
代码应类似于 ListBox.Items.Add(ipaddress) 或 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.在控件中,您可能只保存 IP 地址,如果您想存储套接字对象,请使用 Dictionary ...您的答案不清楚,所以我已经回答了可能的情况。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.