cdoverlaw Posted July 31, 2004 Posted July 31, 2004 I want to change some text on a already open form using another form I tried declaring the form by using Dim frmBrowser As frmBrowser Private Sub cmdUpdateBmk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdUpdateBmk.Click If txtSiteName1.Text = "Site Name" Then Else frmBrowser.bookmark1.Text = txtSiteName1.Text End If If txtSiteName2.Text = "Site Name" Then Else frmBrowser.Bookmark2.Text = txtSiteName2.Text End If If txtSiteName3.Text = "Site Name" Then Else frmBrowser.Bookmark3.Text = txtSiteName3.Text End If If txtSiteName4.Text = "Site Name" Then Else frmBrowser.Bookmark4.Text = txtSiteName4.Text End If If txtSiteName5.Text = "Site Name" Then Else frmBrowser.Bookmark5.Text = txtSiteName5.Text End If End Sub This is the buttons click event which updates the bookmarks listed on the other form, (this is on frmBookmarks) This is the current error: An unhandled exception of type 'System.NullReferenceException' occurred in WebHost Toolbox 2.00.exe Additional information: Object reference not set to an instance of an object. Quote
Joe Mamma Posted July 31, 2004 Posted July 31, 2004 thre are a few ways to skin this cat. . . c# code here Given your design, pass the browser form to the bookmark form on contruction: c# code here class FormBookmarks: Form { FormBrowser _browser; // Constructor Takes a FormBrowser parameter public FormBookmarks(FormBrowser browser): this() { _browser = browser; } private cmdUpdateBmk_Click(object sender, EventArgs e) { If ( txtSiteName1.Text != "Site Name") _browser.bookmark1.Text = txtSiteName1.Text; If ( txtSiteName2.Text != "Site Name") _browser.bookmark2.Text = txtSiteName2.Text; If ( txtSiteName3.Text != "Site Name") _browser.bookmark3.Text = txtSiteName3.Text; If ( txtSiteName4.Text != "Site Name") _browser.bookmark4.Text = txtSiteName4.Text; If ( txtSiteName5.Text != "Site Name") _browser.bookmark5.Text = txtSiteName5.Text; } } in you browser form, create the bookmark form passing the browser form in the constuctor: FormBookmark frm = new FormBookmark(this); What is a bookmark? Description and URL? If so, could they be stored in a DictionaryEntry? Can your List of bookmarks be a DictionaryList? Quote Joe Mamma Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized. Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.
cdoverlaw Posted August 1, 2004 Author Posted August 1, 2004 ok how do i do this in visual basic .net Quote
Joe Mamma Posted August 1, 2004 Posted August 1, 2004 Class FormBookmarks Inherits Form Dim _browser As FormBrowser ' Constructor Takes a FormBrowser parameter Public Sub New(ByVal browser As FormBrowser) : Me() _browser = browser End Sub Private Function cmdUpdateBmk_Click(ByVal sender As Object, ByVal e As EventArgs) As Private If (txtSiteName1.Text <> "Site Name") then _browser.bookmark1.Text = txtSiteName1.Text end if If (txtSiteName2.Text <> "Site Name") then _browser.bookmark2.Text = txtSiteName2.Text end if If (txtSiteName3.Text <> "Site Name") then _browser.bookmark3.Text = txtSiteName3.Text end if If (txtSiteName4.Text <> "Site Name") then _browser.bookmark4.Text = txtSiteName4.Text end if If (txtSiteName5.Text <> "Site Name") then _browser.bookmark5.Text = txtSiteName5.Text end if End Function End Class see how much nicer the C# code looks???? Quote Joe Mamma Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized. Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.
Denaes Posted August 1, 2004 Posted August 1, 2004 ok how do i do this in visual basic .net C# to VB VB to C# These are gold. They let you convert code from C# to VB and reverse. This lets you convert any C# code to VB, so you can ask for help in any fashion and not need to rely on others to translate it to them. Quote
sjn78 Posted August 2, 2004 Posted August 2, 2004 Im trying to do a similar thing, but the above won't work for me. I have frmMain & frmSplash On frmSplash there is a lblLoading label In frmMain I have a loading routine that loads the interface and sets up the menus while the splash screen is being shown. void startup() { Form fSplash = new frmSplash(); fSplash.Show(); fSplash.BringToFront(); Application.DoEvents(); if (connectionGood() == false) { MessageBox.Show("Database not present"); } causeWait(); // Causes a short delay fSplash.Dispose(); } I want to use the label on the splash form as a progress indicator showing what it is loading etc. Now in vb, you could just say fSplash.lblLoading.Text = Whatever and I find in C#, this is not available. I have tried setting the label to public and I still can't access it. So, how to do this?? Thanks Quote
ilya2 Posted August 3, 2004 Posted August 3, 2004 Try to declare form like this: frmSplash fSplash = new frmSplash(); You must leave the label public, however, I would recommend you not using controls on another form directly. Instead, create public properties in splash form that modify the contents of its controls. Quote Ilya
sjn78 Posted August 3, 2004 Posted August 3, 2004 Yeh thanks. I figured it out a while ago, but didnt get back to posting. Pretty obvious mistake, declaring it as a Form, so the label wasn't there, but declaring it as frmSplash and the label shows!! Thanks anyway 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.