vb.net UserControl帮助 [英] vb.net UserControl help

查看:89
本文介绍了vb.net UserControl帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这两个具有编码的用户控件,我需要在主窗体上单击按钮后运行.我在按钮上单击时加载了用户控件,这是该代码:

I have these 2 user controls that have coding in them that i need to run on a button click on the main form. I have the user controls load on a button click and here is that code:

If Me.Outlookbar.SelectedPage.Equals(Me.Machine_Tab) Then
    Dim Obj1 As New Machine_Info_Alerts
    Obj1.Dock = DockStyle.Fill
    Me.Panel1.Controls.Clear()
    Me.Panel1.Controls.Add(Obj1)

    Me.Machine_Name_Textbox_Header.Enabled = True
End If



现在在主窗体上,我单击按钮,一旦将文件复制到我的机器上,它将从文件中读取数据,然后将其显示在用户控件中.当我运行代码时,它会复制文件,但不会在用户控件中显示数据.我已经通过在用户控件上创建一个刷新按钮来测试代码,并且它读取数据,因此我知道该方法有效,但是我不明白为什么我可以使主窗体和用户控件一起工作.

这是我在单击按钮时使用的代码:

注意:用户控件名称是CAE,主要形式称为应用程序.我知道这里有一些通用名称,但是我想在命名所有内容之前使代码正常工作.



now on the main form i have a button click that once it copies the files to my machine it reads data from a file and then displays it in the usercontrol. When I run the code it copies the files but it wont show the data in the user control. I have tested the code by creating a refresh button on the user control and it reads the data so i know that works but i dont understand why i can get the main form and the usercontrol to work together.

here is the code i m using on the button click:

note: the user control name is CAE and the main form is called application. I know there are some general names here but i want to get the code working before i go naming everything.

Private Sub CAE_Quert_Aservice_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CAE_Quert_Aservice_Button.Click

        If strComputer = "" Then
            strComputer = "127.0.0.1"
        End If
        CAE.CAE_Listview.Items.Clear()
        '----------------------------------------------------
        Dim FileToDelete As String

        FileToDelete = "C:\Temp\Aservice.EDM"

        If System.IO.File.Exists(FileToDelete) = True Then
            System.IO.File.Delete(FileToDelete)
        End If
        '------------------------------------------------------
        Dim copyTo As String = "C:\temp\ASERVICE.EDM"
        Dim copyFrom As String = "\\" & strComputer & "\C$\Progra~2\Hewlett-Packard\HPCA\Agent\Lib\SYSTEM\RADIA\SOFTSRVC\ASERVICE.EDM"
        File.Copy(copyFrom, copyTo, True)
        '----------------------.--------------------------------

        objsh = CreateObject("WScript.Shell")

        Dim strObject As String = "C:\Temp\ASERVICE.EDM"

        Dim process = GetObject("winmgmts://./root/novadigm:NVD_Agent")
        Dim method = process.Methods_("GetValue")
        Dim inParameters = method.inParameters.SpawnInstance_()
        inParameters.Path = strObject
        Dim outParameters = process.ExecMethod_("NumberOfInstances", inParameters)
        Dim StrHeaps = (outParameters.InstanceCount)
        CAE.CAE_Heap_Count.Text = StrHeaps
        For i = 0 To StrHeaps Step 1

            inParameters.Index = i

            inParameters.Property = "ZOBJNAME"
            outParameters = process.ExecMethod_("GetValue", inParameters)
            Dim Value2 As String = outParameters.Value

            inParameters.Property = "ZAVIS"
            outParameters = process.ExecMethod_("GetValue", inParameters)
            Dim Value3 As String = outParameters.Value

            inParameters.Property = "ZSVCCSTA"
            outParameters = process.ExecMethod_("GetValue", inParameters)
            Dim Value4 As String = outParameters.Value

            inParameters.Property = "NAME"
            outParameters = process.ExecMethod_("GetValue", inParameters)
            Dim Value5 As String = outParameters.Value

            inParameters.Property = "INSTDATE"
            outParameters = process.ExecMethod_("GetValue", inParameters)
            Dim value6 As String = outParameters.Value

            inParameters.Property = "ZVERIFY"
            outParameters = process.ExecMethod_("GetValue", inParameters)
            Dim value8 As String = outParameters.Value

            'Date
            Dim str As String
            Dim strArr() As String
            Dim count As Integer
            Dim value7 As String
            str = value6
            strArr = str.Split("T")
            For count = 0 To strArr.Length - 2
                value7 = (strArr(count))
            Next

            Dim value1 = CAE.CAE_Listview.Items.Count
            Dim item As New ListViewItem(value1)
            item.SubItems.Add(Value2)
            item.SubItems.Add(Value3)
            item.SubItems.Add(Value4)
            item.SubItems.Add(Value5)
            item.SubItems.Add(value7)
            item.SubItems.Add(value8)
            CAE.CAE_Listview.Items.Add(item)
            CAE.CAE_Listview.FullRowSelect = True

        Next
        CAE.CAE_Listview.Items(CAE.CAE_Listview.Items.Count - 1).Remove()
    End Sub

推荐答案

\ Progra〜2 \ Hewlett-Packard \ HPCA \ Agent \ Lib \ SYSTEM \ RADIA \ SOFTSRVC \ ASERVICE.EDM" File.Copy(copyFrom,copyTo,) ' ----------------------.-- ------------------------------ objsh = CreateObject(" ) Dim strObject As 字符串 = " Dim 进程= GetObject(" ) Dim 方法= process.Methods _(" ) Dim inParameters = method.inParameters.SpawnInstance_() inParameters.Path = strObject Dim outParameters = process.ExecMethod _(" span>,inParameter) Dim StrHeaps =(outParameters.InstanceCount) CAE.CAE_Heap_Count.Text = StrHeaps 对于 i = 0 >到 StrHeaps 步骤 1 inParameters.Index = i inParameters.属性 = " outParameters = process.ExecMethod _(" ,inParameters) Dim Value2 As String = outParameters.Value inParameters.属性 = " outParameters = process.ExecMethod _(" ,inParameters) Dim Value3 As String = outParameters.Value inParameters.属性 = " outParameters = process.ExecMethod _(" ,inParameters) Dim Value4 As String = outParameters.Value inParameters.属性 = " outParameters = process.ExecMethod _(" ,inParameters) Dim Value5 As String = outParameters.Value inParameters.属性 = " outParameters = process.ExecMethod _(" ,inParameters) Dim value6 As String = outParameters.Value inParameters.属性 = " outParameters = process.ExecMethod _(" ,inParameters) Dim value8 As String = outParameters.Value ' 日期 Dim str As 字符串 Dim strArr() As 字符串 Dim 计数 As 整数 Dim value7 As 字符串 str =值6 strArr = str.Split(" ) For 计数= 0 To strArr.Length - 2 值7 =(strArr(count)) 下一步 Dim value1 = CAE.CAE_Listview.Items.Count Dim As 新建 ListViewItem(value1) item.SubItems.Add(Value2) item.SubItems.Add(Value3) item.SubItems.Add(Value4) item.SubItems.Add(Value5) item.SubItems.Add(value7) item.SubItems.Add(value8) CAE.CAE_Listview.Items.Add(项目) CAE.CAE_Listview.FullRowSelect = 下一步 CAE.CAE_Listview.Items(CAE.CAE_Listview.Items.Count- 1 ).Remove() 结束
\Progra~2\Hewlett-Packard\HPCA\Agent\Lib\SYSTEM\RADIA\SOFTSRVC\ASERVICE.EDM" File.Copy(copyFrom, copyTo, True) '----------------------.-------------------------------- objsh = CreateObject("WScript.Shell") Dim strObject As String = "C:\Temp\ASERVICE.EDM" Dim process = GetObject("winmgmts://./root/novadigm:NVD_Agent") Dim method = process.Methods_("GetValue") Dim inParameters = method.inParameters.SpawnInstance_() inParameters.Path = strObject Dim outParameters = process.ExecMethod_("NumberOfInstances", inParameters) Dim StrHeaps = (outParameters.InstanceCount) CAE.CAE_Heap_Count.Text = StrHeaps For i = 0 To StrHeaps Step 1 inParameters.Index = i inParameters.Property = "ZOBJNAME" outParameters = process.ExecMethod_("GetValue", inParameters) Dim Value2 As String = outParameters.Value inParameters.Property = "ZAVIS" outParameters = process.ExecMethod_("GetValue", inParameters) Dim Value3 As String = outParameters.Value inParameters.Property = "ZSVCCSTA" outParameters = process.ExecMethod_("GetValue", inParameters) Dim Value4 As String = outParameters.Value inParameters.Property = "NAME" outParameters = process.ExecMethod_("GetValue", inParameters) Dim Value5 As String = outParameters.Value inParameters.Property = "INSTDATE" outParameters = process.ExecMethod_("GetValue", inParameters) Dim value6 As String = outParameters.Value inParameters.Property = "ZVERIFY" outParameters = process.ExecMethod_("GetValue", inParameters) Dim value8 As String = outParameters.Value 'Date Dim str As String Dim strArr() As String Dim count As Integer Dim value7 As String str = value6 strArr = str.Split("T") For count = 0 To strArr.Length - 2 value7 = (strArr(count)) Next Dim value1 = CAE.CAE_Listview.Items.Count Dim item As New ListViewItem(value1) item.SubItems.Add(Value2) item.SubItems.Add(Value3) item.SubItems.Add(Value4) item.SubItems.Add(Value5) item.SubItems.Add(value7) item.SubItems.Add(value8) CAE.CAE_Listview.Items.Add(item) CAE.CAE_Listview.FullRowSelect = True Next CAE.CAE_Listview.Items(CAE.CAE_Listview.Items.Count - 1).Remove() End Sub


史诗失败...我发现该按钮缺少click事件的处理程序.
Epic Fail... I found that the button was missing the handler for the click event.


这篇关于vb.net UserControl帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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