Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

Posted

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?

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.

Posted

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????

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.

Posted
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.

Posted

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

Posted

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.

Ilya
Posted

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...