create form object in class2.vb

S

Supra

i have :
mainform
form2 had 2 textbox
class1.vb
class2.vb
how do i create form2 into class2.vb?
i couldn't do better. this is what i do.

in class2.vb
public class class2
public frm2 as form2

sub new()
MyBase.GetType()
frm2 = new form2
frm2.mdiparent !! <===== i wanted frm2 to be mdichild
end sub

Private Sub _Connection_onSeverMessage(ByVal szText As String) Handles
_Connection.onSeverMessage
DisplayMessage(frm2.text= szText.ToString)
End Sub

but i got error problem. it is comming from form2.
An unhandled exception of type 'System.NullReferenceException' occurred
in system.windows.forms.dll
Additional information: Object reference not set to an instance of an
object.

in class1.vb. i called from class2
Select Case C(1).Trim
Case "001" To "014", "251" To "272", "372" To "377",
"401", "422", "462", "468", "503"
Dim intA As Integer = CLi.IndexOf(Nick, 0)
RaiseEvent onSeverMessage(CLi.Substring(intA +
Nick.Length).ToString())

regards
 
H

Herfried K. Wagner [MVP]

Supra said:
i have :
mainform
form2 had 2 textbox
class1.vb
class2.vb
how do i create form2 into class2.vb?
i couldn't do better. this is what i do.

in class2.vb
public class class2
public frm2 as form2

sub new()
MyBase.GetType()
frm2 = new form2
frm2.mdiparent !! <===== i wanted frm2 to be mdichild
end sub

Private Sub _Connection_onSeverMessage(ByVal szText As String) Handles
_Connection.onSeverMessage
DisplayMessage(frm2.text= szText.ToString)
End Sub

but i got error problem. it is comming from form2.
An unhandled exception of type 'System.NullReferenceException' occurred in
system.windows.forms.dll
Additional information: Object reference not set to an instance of an
object.


You will have to make a reference to your MDI container available to your
'Class2', for example in a method parameter or a property:

\\\
Private m_MdiParent As Form

Public Sub New(ByVal MdiParent As Form)
m_MdiParent = MdiParent
End Sub

Public Sub ConnectionServerMessage(...) Handles...
Dim f As New Form2()
f.MdiParent = m_MdiParent
f.Show()
End Sub
///

Usage (in MDI container):

\\\
Dim c As New Class2(Me)
....
///
 
S

Supra

i
to herfried:
how will i do in class1 from class 2
Select Case C(1).Trim
Case "001" To "014", "251" To "272", "372" To "377",
"401", "422", "462", "468", "503"
Dim intA As Integer = CLi.IndexOf(Nick, 0)
RaiseEvent onSeverMessage(CLi.Substring(intA +
Nick.Length).ToString()) <===this data would not dispaly

regards,
 
S

Supra

if i added this...the datas will blanked

Public Sub ConnectionServerMessage(...) Handles...
Dim f As New Form2() <=== added
f.MdiParent = m_MdiParent<===added
DisplayMessage(nStatus.rtbStatus, szText.ToString)
' f.Show()<= rem this
End Sub

regards
 
S

Supra

yes. i removed this

Dim c As New Class2(Me)
regards
ur example code is working... i can only do like this
Display ( frm.textbox1, "bla bla bla bla ",sztext)
but not in this:

Select Case C(1).Trim
Case "001" To "014", "251" To "272", "372" To "377","401", "422", "462", "468", "503"
Dim intA As Integer = CLi.IndexOf(Nick, 0)
RaiseEvent onSeverMessage(CLi.Substring(intA + Nick.Length).ToString())<===this data would not dispaly

regards
 

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

Similar Threads


Top