Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8531297
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:27:08+00:00 2026-06-11T09:27:08+00:00

I have two forms in my application, one form is to create new connections,

  • 0

I have two forms in my application, one form is to create new connections, the other is the main form which holds the menu that will carry the connection names.

enter image description here

When i create a new connection under frmNewConnection form and try to click on the menu item that’s generated, it wont display the Test message like it does when i reopen the program.

In the main form i have the following public sub.

frmMain which is the main form

Public Sub Connect_SubMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs)
  Messagebox.Show("Test")
End Sub

That code never gets executed unless i restart my application then it works fine when i click on the newly generated menu item. But if i was to load the application and click on the “New Connection” Menu item and create the new connection then try to click it under the “Connections” menu then nothing happens, i don’t get the “Test” Message box.

I have the following code under the frmNewConnection Accept button, which saves the name of the connection to the “Connections” menu.

frmMain.menuConnections.DropDownItems.Add(ConnectionName, Nothing, AddressOf frmMain.Connect_SubMenuItem_Click) ' save to menu

I also have a version of that code that executes on frmMain_load():

menuConnections.DropDownItems.Add(finalData(1).ToString, Nothing, AddressOf Connect_SubMenuItem_Click) ' save to menu

My Question here is, why won’t the Test message appear when a new menu item is generated while in the program but it does show when i close the program and i re-open it..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T09:27:08+00:00Added an answer on June 11, 2026 at 9:27 am

    If you are modifying the controls of one form from another form then you are probably going about the whole thing wrong.

    First thing you need to do is take control of your program startup. VB hides this sometimes. This will allow you to capture your form variable. Then, consider refactoring a bit.

    Some VB.NET psuedo-code (I apologize for any C# that leaks in here):

    Class Program
    
       Private _appCtx As AppContext
    
       Sub Main()
    
          _appCtx = New AppContext()
    
          'perform whatever bootstrap logic you needed here, typically
          ' configuring and installing behaviors into the app context
          '
          '
    
          ' one single instace of your main form
          _appCtx.RootForm = New frmMain(); 'or better still, pass AppContext into the ctor 
    
          Application.Run(_appCtx.RootForm)
    
       End Sub
    
       'if you want to cheat a bit, include this getter to provide access to everyone
       'otherwise, pass the app context to those classes that require it
       Public Shared AppCtx() As AppContext
          Get
             return _appCtx
          End Get
       End Property
    
    
    End Class
    
    Public Class AppContext
    
       Public Property RootForm As Form
    
       Public Property Connections As Connections
    
       'other application-wide subsystems or data
    
    End Class
    
    Public Class Connections
    
       Public Event Changed As EventHandler
    
       Public Property Count As Integer
    
       'other properties including a getter for the child connection objects...
    
       Public Sub Add(newConn As Connection)
          'add to internal list then...
          If Changed IsNot Nothing Then
             Changed(this, EventArgs.Empty)
          End If
       End Sub
    
    End Class
    
    Public Class frmMain
    
    
       Sub Form_Load() 
    
          AddHandler AppCtx.Connections.Changed AddressOf(Connections_Changed)
    
       End Sub
    
       Sub Connections_Changed()
          'iterate the connections and refresh the menu
          'the menu gets refreshed without breaking encapsulation!
       End Sub
    
    End Class
    
    Public Class frmNewConnection 
    
    
       private sub Accept_Click()
    
          'do stuff to create a connection object
    
          'add to the current set of connections, this will broadcast to anyone who needs to know      
          AppCtx.Connection.Add(newConn)
    
       End Sub 
    
    End Class
    

    If you don’t want to use the domain-object events for updates that is up to you, but the first part of the sample shows how to capture the startup form into a variable that you can then use in your program code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application that consists of two forms. One form displays data returned
I have created two forms in my Windows Application. One Form acts as a
I have encountered a problem in my application. I have two forms, one that
I have two window form applications written in C, one holds a struct consisting
I have application in VB.net that have two different form (Form1 and Form2). Now
Imagine that I have a form in a flash application with two fields, input1
In my application I have one windows form application and two windows services. Currently
In my application I have a Form that for one of the top level
I have two versions of a Windows Forms Application and can't figure for the
Scenario I have a windows forms application. I want to use two different WCF

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.