组合框或列表框?
我很好奇我是否应该使用列表框或组合框来查找仓库部件号,然后点击它时触发事件。我希望能够单击该号码,然后从串行端口发送特定命令。我目前使用一些超链接来做这个,但现在有很多,下拉列表将有助于选择和激发相同的命令,就像它是超链接一样。
这是我的代码,当单击HC1_101部件的超链接时...我可以用列表框替换它来发送相同的命令吗?我可以将链接添加到下拉列表吗?
I was curious if I should use a listbox or combobox to look up warehouse part numbers and then fire an event if it is clicked. I want to be able to click that number and then send a specific command out a serial port. I currently use a selection of hyperlinks to do this but there are now to many and a dropdown list would be helpful to select from and fire the same command as if it was the hyperlink.
Here is my code for when a hyperlink is clicked for part HC1_101... could I replace this with a listbox to send the same command? Can I just add the links to the dropdown list?
private void linkLabel_HC1_101_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
if (serialPort1.IsOpen)
{
var content = new List<byte>();
content.Add(2);
content.AddRange(Encoding.ASCII.GetBytes("01P00101##"));
content.Add(3);
byte[] buffer = content.ToArray();
serialPort1.Write(buffer, 0, buffer.Length);
}
}
哪个更好?是一个我们很难给出正确和准确答案的问题。我们对您的项目一无所知。
以下是一些指向Windows窗体版控件的MSDN链接:
ComboBox类 [ ^ ]
ListBox类 [ ^ ]
在事件列表中,您将找到必须使用的代理(事件处理程序)。
"Which is better?" is a question we can hardly give a correct and precise answer. We don't know anything of your project.
Here are some MSDN links to the Windows Forms version of the controls:
ComboBox class[^]
ListBox class[^]
In their event lists, you will find which delegate (event handler) you will have to use.
选择完全取决于你想要什么。ComboBox
在顶部添加文本框输入。你打算用这部分控制做什么?如果你想在其中输入内容(即使是为了类似搜索的选择样式),你需要ComboBox
。如果您希望能够输入列表中未显示的某些文本,还需要ComboBox
。顺便说一下,列表部分的一个可能的应用是将历史存储在文本框部分的输入中。在所有其他情况下,它是ListBox
。
就这么简单。-SA
The choice depends solely on what you want.ComboBox
adds a text box input on top. What are you going to do with this part of control? If you want to input something in it (even for the purpose of search-like selection style), you needComboBox
. If you want to be able to input some text not shown in the list, you also needComboBox
. By the way, one possible application of the list part would be storing the history in input in text box part. In all other cases, it'sListBox
.
As simple as that.—SA