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 669411
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:08:54+00:00 2026-05-14T00:08:54+00:00

vb.net windows forms question. I’ve got 3 forms that have exactly the same functions,

  • 0

vb.net windows forms question.
I’ve got 3 forms that have exactly the same functions, so I decided to create an interface.

public Interface IExample

    public sub Add()

    Public sub Edit()

    Public sub View()

End Interface

Then I created the 3 forms, and added the ‘implements interface IExample’ to each.

   public class frmExample1

        implements Interface IExample

Same for frmExample2, frmExample3

Finally, in code, I declare a variable of the interface type ..
Dim objfrmExample as IExample

then …

objFrmExample = frmExample2

At this point, objfrmExample is now instantiated, even though I’ve not done a “objfrmExpample = new [what-goes-here?] ” and I’m curious as to why.

I could possibly guess that because you cannot instantiate an interface variable, then vb.net automatically creates an instance. But thats just a guess. The question is , what is meant by declaring a variable of type Interface, and how does it work?

Anyway, just curious 🙂

  • 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-05-14T00:08:54+00:00Added an answer on May 14, 2026 at 12:08 am

    At this point, objfrmExample is now instantiated, even though I’ve not done a “objfrmExpample = new [what-goes-here?] ” and I’m curious as to why.

    This has nothing to do with interfaces. You can always treat a form class name in VB as though it were an instance. The reason is that the VB compiler creates properties of all your forms inside My.Forms. Now you can access a “default” instance of each form by accessing My.Forms.<FormName>.

    Now comes the ugly part: you can also omit My.Forms.. In other words, whenever you write just FormName and from the context it’s unambiguous that you need an instance rather than the class name, VB will act as though you’d written My.Forms.<FormName>.

    Luckily, this only works for forms, not for any other classes. VB creates each default instance when you first access it. So as long as you don’t access a default instance, it’s not created. Once you access it for the first time, VB creates it and invokes its constructor.

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

Sidebar

Related Questions

I have written a small .net Windows Forms application. And now I decided to
I'm inexperienced with windows forms (vb.net), and I have a rather silly question. I'm
I come from Windows .Net forms development. This is a pretty basic/fundamental question. I'm
I have a .NET windows forms application compiled as x86 – it needs to
Can a VB.NET Windows Forms Application be configured so that when run from the
I'm working on a .NET Windows Forms application. I have an event handler procedure
How can you write a VB.NET Windows Forms Application via CodeDom? I have tried
I have been experimenting with sending messages from two .NET Windows Forms applications using
I have previously written user interfaces using .NET and Windows Forms. I'm about to
Note: Using Windows Forms preferably C# .NET Question: Best method for implementing a drag-over-window

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.