将参数传递给用户控件 [英] passing parameter to user control

查看:50
本文介绍了将参数传递给用户控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有用户控件接受3个字符串并将其设置为3个标签。

加载用户控件时我设置默认值,当我通过参数时,标签将更改它的文本。

但我的问题是标签没有改变它的价值,我检查代码并看到用户控件读取所有值但没有任何反应:(



抱歉我的英文不好



-----------

表格登录

------------

Imports System.Data.OleDb

Imports System.IO

进口系统

进口System.Windows.Forms



公共类别FrmLogin

I have user control that accept 3 String and set it into 3 labels.
on load of the user control i set default value,and when i pass the paremeter the label will change it's text.
but my problem is the lables not changing it's value at all, i check the code and see the user control read all the value but nothing happen :(

Sorry for my bad english

-----------
Form Login
------------
Imports System.Data.OleDb
Imports System.IO
Imports System
Imports System.Windows.Forms

Public Class FrmLogin

Dim mb As New _userCompanyBar()
   



    Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.Close()
    End Sub







    Public Sub New()

        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        Me.Controls.Add(mb)
        ' Add any initialization after the InitializeComponent() call.

    End Sub

    Private Sub _BtnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles _BtnLogin.Click

    End Sub

    Private Sub _BtnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles _BtnCancel.Click
        Me.Close()
    End Sub

    Private Sub LoginForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim _companyBUS As CompanyBUS
        _companyBUS = New CompanyBUS
        Dim _CompanyVO = New CompanyVO()
        _CompanyVO = _companyBUS.getCompany()
        Try

            If Not (_CompanyVO Is Nothing) Then
                '  Dim CompanyBar As New _userCompanyBar
                mb.setData(_CompanyVO.CompanyName, _CompanyVO.CompanyAddress, _CompanyVO.CompanyPhone)




            End If
        Catch ex As Exception
        End Try
    End Sub
End Class







---------------

_userCompanyBar

-------------




---------------
_userCompanyBar
-------------

>_userCompanyBar


Imports System.ComponentModel

Public Class _userCompanyBar
    Dim Company = "Company Name"
    Dim CompanyAddress = "Company Address"
    Dim CompanyPhone = "Company Phone"



    Public Sub CompanyBar_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        _lbCompanyName.Text = Company
        _lbCompanyAddress.Text = CompanyAddress
        _lbCompanyTelp.Text = CompanyPhone

    End Sub

    Private Sub _pnBackgroundColor_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles _pnBackgroundColor.Paint

    End Sub

    Public Sub New()

        ' This call is required by the Windows Form Designer.
        InitializeComponent()
        ' Add any initialization after the InitializeComponent() call.

    End Sub

    Public Sub New(ByVal _CompanyName As String, ByVal _CompanyAdresse As String, ByVal _CompanyPhone As String)

        ' This call is required by the Windows Form Designer.
        InitializeComponent()
        setData(_CompanyName, _CompanyAdresse, _CompanyPhone)


    End Sub
    Public Sub setData(ByVal _CompanyName As String, ByVal _CompanyAdresse As String, ByVal _CompanyPhone As String)

        _lbCompanyName.Text = _CompanyName
        _lbCompanyAddress.Text = _CompanyAdresse
        _lbCompanyTelp.Text = _CompanyPhone
    End Sub

    Private Sub _lbCompanyTelp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles _lbCompanyTelp.Click

    End Sub
End Class</pre>

推荐答案

可能您没有引用正在显示的用户控件的实例。除非您这样做,否则您可以进行所有您喜欢的更改,它不会影响显示一个iota!



检查您调用setDate方法的代码 - 和确保你在正确的实例上调用它,而不是新实例。
Probably, you aren't referencing the instance of your user control that you are displaying. Unless you do, you can make all the changes you like, it won't affect the display one iota!

Check the code where you call the setDate Method - and make sure you are calling it on the correct instance, rather than a new one.


这篇关于将参数传递给用户控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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