How to change controls from another form in visual basic

José Carlos 886 Reputation points
2023-10-08T14:50:01.8833333+00:00

Hi friends,

I have a main form that has a panel with Dock = left and another panel in the same form with Dock = Fill.

On the left panel I have buttons as an options menu.

When I click on a button, I call another form within the Dock=fill panel of the main form.

What am I not able to do? When I click on the menu button I call a form, which is loading perfectly, and I would like to activate a textbox and a picturebox in the called form.

I've already made several attempts using ChatGpt, which has already provided me with two different codes, but none of them worked.

How to do this? Was I clear?

Developer technologies | VB
Developer technologies | Visual Studio | Other
Developer technologies | Visual Studio | Other
A family of Microsoft suites of integrated development tools for building applications for Windows, the web, mobile devices and many other platforms. Miscellaneous topics that do not fit into specific categories.
{count} votes

Answer accepted by question author
  1. KOZ6.0 6,735 Reputation points
    2023-10-08T17:31:22.1633333+00:00

    Is this what you want to do?

    Public Class MainForm
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim f As New SubForm()
            'Required
            f.TopLevel = False
    
            'if necessary
            f.Dock = DockStyle.Fill
            f.Text = String.Empty
            f.ControlBox = False
    
            ' Add form to panel
            FillPanel.Controls.Add(f)
            f.Show()
            f.TextBox1.Focus()
        End Sub
    
    End Class
    
    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.