How to reference a control from another vb.net form?

J

JenHu

Hi all,

I have a checkbox cboxProcessRet in my VB.NET windows application's
main.vb as following, so how can I use reference this checkbox in
moduleA.vb?

I want to use it in a function in the module, it said cboxProcessRet
is not declared
(If cboxProcessRet.Checked = True )
------------------------------------------------------------------------

Public Class frmMain
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Private components As System.ComponentModel.IContainer
Friend WithEvents cboxProcessRet As System.Windows.Forms.CheckBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
Me.cboxProcessRet = New System.Windows.Forms.CheckBox

*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*
 
L

Lucas Tam

(e-mail address removed)-spam.invalid (JenHu) wrote in [email protected]:
I have a checkbox cboxProcessRet in my VB.NET windows application's
main.vb as following, so how can I use reference this checkbox in
moduleA.vb?

Is the control declared as public? If it is, you can access it directly.

Rather than create a public control, create a property to change the value
of the control.
 
S

smith

Your post is titled "Form" to Form" and the text says "Module" which is it?

Here's form to form

FormA:

Private Sub butshowotherform_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) _
Handles butShowOtherForm.Click

Dim fb As New FormB
fb.ShowDialog()
MsgBox(fb.ThisIsTheCheckBox.Checked.ToString)
fb.Dispose()
fb = Nothing
End Sub


public readonly property ThisIsMyCheckBox() as checkbox

FormB:

Friend ReadOnly Property ThisIsTheCheckBox() As CheckBox
Get
Return chkMyBox
End Get
End Property

That passes the checkbox. You could also just expose a BoxIsChecked
property thaqt returns a bool.

Hope that helps

smith
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top