Vb listbox display in multiply forms?

和自甴很熟 提交于 2020-02-07 05:29:05

问题


I'm using VB.Net and Visual Studio 2012.

I need to display the same list box in two different forms.

The Scenario

I'm creating a program that allows its users to create orders in a cafe. When the user has completed their order they press the button "save/ complete". When they press this button their order is added to a listbox on the side of the new order form.

On the other form (summary), there will be the same listbox displayed.

So my question is how to display the same listbox on multiple forms?


回答1:


This code will add ComboBox1 to a second form:

 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim frm2 As New Form2
    frm2.Controls.Add(ComboBox1)
    frm2.Show()
End Sub



回答2:


You can do this maybe by saving the combo items to a textfile, that the other form can read the same file? I think it's not that professional, but it is an option :)

Example creating a .txt file - http://www.homeandlearn.co.uk/NET/nets8p4.html

Example reading a .txt file into a control - https://msdn.microsoft.com/en-us/library/db5x7c0d(v=vs.110).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-1

The reading of the text file and placing it in the control need to be in the MyBase.Load event.

Hopefully I helped you a little bit!



来源:https://stackoverflow.com/questions/29474037/vb-listbox-display-in-multiply-forms

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!