将参数传递给用户控件

编程入门 行业动态 更新时间:2024-10-03 17:15:17
本文介绍了将参数传递给用户控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有用户控件接受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 = &quot;Company Name&quot; Dim CompanyAddress = &quot;Company Address&quot; Dim CompanyPhone = &quot;Company Phone&quot; 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() &#39; This call is required by the Windows Form Designer. InitializeComponent() &#39; Add any initialization after the InitializeComponent() call. End Sub Public Sub New(ByVal _CompanyName As String, ByVal _CompanyAdresse As String, ByVal _CompanyPhone As String) &#39; 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.

更多推荐

将参数传递给用户控件

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

发布评论

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

>www.elefans.com

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