wz2jrz Posted April 25, 2003 Posted April 25, 2003 Hi, I have MDIform as well as form2 in my project. From MDI, i am opening child form-form2 and populating a richtextbox with a text file content. Also i am populating a listbox on that form. unfortunately i am getting 'Object Reference not set' error on richtextbox loadfile line... ---menu code that opens form2 and populate richtextbox Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem2.Click StatusBar1.Text = "Ready" OpenFileDialog1.Filter = "WDL files (*.wdl)|*.txt|All files (*.*)|*.*" OpenFileDialog1.ShowDialog() Class1.f2.richtextbox1.LoadFile(OpenFileDialog1.FileName, RichTextBoxStreamType.PlainText)) Class1.f2.Show() StatusBar1.Text = OpenFileDialog1.FileName & " file opened." End Sub ----------------------------------- Also how do i add values to the listbox on form2 from mdiform? I tried- Class1.f2.varlist.Items.Add("test") unsuccessfull.... ----my startup is sub_main which shares two forms---- Public Class Class1 Public Shared f1 As Form1 = Form1.ActiveForm Public Shared f2 As Form2 Public Shared Sub Main() f1 = New Form1() f2 = New Form2() f1.Show() Application.Run() End Sub End Class ---------------------------------------------------------------------- thanks in advance for any help... Quote
ailzaj Posted May 3, 2003 Posted May 3, 2003 You may have already got your RichTextBox working, but just in case you are still having problems I thought I'd let you know what happened when I played around with your code. The code on the MDI Parent Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load f1 = Me End Sub Private Sub mnuForm2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuForm2.Click StatusBar1.Text = "Ready" OpenFileDialog1.Filter = "WDL files (*.wdl)|*.txt|All files (*.*)|*.*" OpenFileDialog1.ShowDialog() f2.rtbTest.LoadFile(OpenFileDialog1.FileName, RichTextBoxStreamType.PlainText) f2.Show() f2.MdiParent = Me StatusBar1.Text = OpenFileDialog1.FileName & " file opened." End Sub Private Sub mnuExit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuExit.Click End End Sub I also put the Public f1 As Form1 Public f2 As New Form2() into a module instead of a class. If you had got it to work a different way please let me know. ailzaj Quote
wz2jrz Posted May 3, 2003 Author Posted May 3, 2003 Thanks ailzag for your response. the code is working now..i did use mdiparent property..did the same way as you have mentioned.. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.