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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:35:12+00:00 2026-06-17T19:35:12+00:00

I am new to Visual Basic. I have installed Microsoft Visual Studio 2010. Created

  • 0

I am new to Visual Basic. I have installed Microsoft Visual Studio 2010. Created a new Windows Form Application. As an example, I made a simple program which will ask the end user to input 2 numbers and allow them to either add them or subtract the second number from the first one and display the output in a Textbox.

Now, I added another Subroutine which would be executed automatically when the Windows Form loads. This would calculate the width of the output Textbox and the Form Width and display at the bottom.

This is how the code looks like right now:

Public Class Form1

    ' Run this Subroutine initially to display the Form and Text box width
    Private Sub Form_Load()
        Label5.Text = TextBox3.Width
        Label7.Text = Me.Width
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim a As Integer
        Dim b As Integer
        a = TextBox1.Text
        b = TextBox2.Text
        TextBox3.Text = a + b
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim a As Integer
        Dim b As Integer
        a = TextBox1.Text
        b = TextBox2.Text
        TextBox3.Text = a - b
    End Sub
End Class

While everything works correctly for the addition and subtraction, it does not display the Form and output Textbox width in the Windows Form.

I think, Form_Load() is not executing properly.

I also tried, Form_Activate() but that did not work either.

Once I am able to do this, I would like to extend this concept to resize the output Textbox along with the Form resize. However, for the purpose of understanding I wanted to see if I can execute Form_Load() successfully.

Thanks.

  • 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-17T19:35:14+00:00Added an answer on June 17, 2026 at 7:35 pm

    Form_Load doesn’t execute. For now, it’s just any other method. In order to tell VB to make this method handle the Load event, you need to tell it so:

    Private Sub Form_Load(sender As Object, e As EventArgs) Handles MyBase.Loasd
        Label5.Text = TextBox3.Width
        Label7.Text = Me.Width
    End Sub
    

    (And add the required parameters for the event.)

    A few other remarks:

    • Ensure that Option Strict On is enabled in your project options at all times. This will make the compiler much stricter with your code and flag more errors. This is a good thing since these errors are potential bugs. In particular, your code is very lax with conversions between different data types, these should be made explicit.

    • Initialise variables when you declare them, don’t assign a value in a separate statement. That is, write this:

      Dim a As Integer = Integer.Parse(TextBox1.Text)
      

      (Explicit conversion added as well.)

    • If you want to make a control fill the form, you can just set its Dock property appropriately in the forms editor, instead of having to program this manually.

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

Sidebar

Related Questions

I have created an application in VB.NET (using Microsoft Visual Basic 2010 Express) with
I have just installed Visual Studio 2010. when I attempt to create a new
I have Visual Studio 2010 with SP1 installed. I want to create a simple
I have a basic ASP.Net project created in Visual Studio 2008 on Windows Server
I am using Visual Studio 2008. I have created a visual basic form that
I am very new to Installshield 2010. I have created a basic MSI setup
I'm fairly new to Visual Studio (specifically Visual Basic .NET) but have been programming
I am new to creating an installer for Visual Studio 2010 and I have
I am using Microsoft Visual Basic 2010 Express. I have a WPF-based project. I
I have installed GLUT and Visual Studio 2010 and found some tutorials on OpenGL

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.