以其他形式阅读字典 [英] Reading dictionaries in other forms

查看:132
本文介绍了以其他形式阅读字典的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

新手VB用户在这里。希望我过去一天没有盯着眼睛的答案,但是我在...中写了一个字典,在 Form1 中,我想读到一个列表框上另一种形式完全是希望能够使用按钮添加和删除条目。最好的方法是什么?真的来了这里。



使用Visual Basic 2015与Windows窗体应用程序。



提前感谢! / p>

这是我想在另一种形式的列表框上阅读的提到的字典。

公共类Form1 
Dim userLog As New Dictionary(Of String,String)

私有子Form1_Load(发件人作为对象,e作为EventArgs)处理MyBase.Load
userLog(one)=aaa
userLog(two)=aaa
userLog(three)=aaa

End Sub


解决方案

创建公共属性而不是私有变量



 公共属性userLog作为新字典(String,String)

您可以使用 Form1.userLog



在此 MSDN文章中阅读更多内容


Novice VB user here. Hope I haven't been staring the answer in the eye for the past day or so but I have a made a dictionary in Form1 that I would like to read onto a listbox on another form entirely with the hopes of being able to add and remove the entries with buttons. What is the best method to go about this? Have really come stuck here.

Using Visual Basic 2015 with Windows Form Application.

Thanks in advance!

This is the mentioned dictionary I would like to read on a listbox on the other form.

Public Class Form1
Dim userLog As New Dictionary(Of String, String)

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    userLog("one") = "aaa"
    userLog("two") = "aaa"
    userLog("three") = "aaa"

End Sub

解决方案

Create a public property instead of a private variable

Public Property userLog As New Dictionary(Of String, String)

You can access it from other forms using Form1.userLog

Read more in this MSDN Article

这篇关于以其他形式阅读字典的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆