从其他形式的 VB.NET 访问控制

编程入门 行业动态 更新时间:2024-10-27 00:26:22
本文介绍了从其他形式的 VB.NET 访问控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我正在 VS 2012 中处理一个具有多种形式的 vb 项目.可以说,我有一个带有 ListView 的 Form1,我从 Form1 调用了一个 From2.我将此代码添加到 Form2 的 Load 事件中:

I am working on a vb project in VS 2012 that has multiple forms. I have, lets say, Form1 with a ListView and I call a From2 from Form1. I add this code to the Load event of Form2:

Form1.ListViewTest.Items.Add("test")

Visual Studio 没有抛出任何错误,但实际上 Form1 中的 ListView 控件没有任何反应.我尝试将修饰符从 Friend 更改为 public,但没有成功.还有什么我想念的吗?

The visual studio throws no errors but in fact nothing happens in the ListView control in Form1. I tried to change Modifiers from Friend to public with no success. Is there something else that I miss?

推荐答案

您必须访问 form1 的实例,而不是 form 1 对象本身.逐步浏览所有打开的表单,并获得您想要的表单.我个人使用表单的 .Tag 对象,并在其中添加一个字符串来识别它.

You have to access the instance of form1, not the form 1 object itself. Step through all open forms, and get the one you want. I personally use the .Tag object of a form, and just add a string in there to identify it.

    For Each f As Form In My.Application.OpenForms

        If Not f.InvokeRequired Then
            ' Can access the form directly.
            'Get main form , use main form
            If f.Tag = "main" Then
                Dim fcast As New form_form1 '<< whatever your form name
                fcast = f
                Dim xitem As New ListViewItem
                xitem.Text = "blah"
                xitem.SubItems.Add("sub blah")

                fcast.listview1.Items.Add(xitem) '<< use listview name
            End If

        End If

    Next

这篇关于从其他形式的 VB.NET 访问控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-25 11:11:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1115336.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:访问控制   形式   VB   NET

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!