0

when I load form inside panel using code

With Form_brand
    .TopLevel = False
    Panel2.Controls.Add(Form_brand)
    .BringToFront()
    .Show()
End With

textbox inside form does not show its default behaviour like when i click inside textbox cursor show at starting of the text instead of place where I click the mouse. Another problem is that when I move mouse pointer with clicking mouse button text should be selected but this does not happen.

If I open form simply using code

Form_Brand.show()

textbox shows it default behaviour. What should I do?

Olivier Jacot-Descombes
  • 104,806
  • 13
  • 138
  • 188
  • Does this answer your question? [Winforms - Embedding form inside a form or container causes form controls to behave differently](https://stackoverflow.com/questions/3481068/winforms-embedding-form-inside-a-form-or-container-causes-form-controls-to-beh) – T.S. Nov 15 '22 at 17:57
  • 1
    Create a UserControl instead of a Form. You can design it visually in the designer exactly like a Form. – Olivier Jacot-Descombes Nov 15 '22 at 18:00
  • Can you post sample code hoe to open a usercontrol within panel using button. Sorry as I am new in vb.net. – RUSHI HARDWARE Nov 15 '22 at 19:23

2 Answers2

0

Create a UserControl instead of a Form. You can design it visually in the designer exactly like a Form.

Example of adding a UserControl to a panel

Dim uc = New MyUserControl() ' But please, give it a better name!
Panel2.Controls.Add(uc)

Note that you don't have to set a TopLevel property nor to call BringToFront() or Show().

Olivier Jacot-Descombes
  • 104,806
  • 13
  • 138
  • 188
0

Maybe you can use this:

Private Sub TextBox1_MouseDown(sender As Object, e As MouseEventArgs) Handles TextBox1.MouseDown
    TextBox1.SelectionLength = 0
    TextBox1.SelectionStart = TextBox1.GetCharIndexFromPosition(e.Location)
End Sub

Private Sub TextBox1_MouseMove(sender As Object, e As MouseEventArgs) Handles TextBox1.MouseMove
    If e.Button = MouseButtons.Left Then
        TextBox1.SelectionLength = TextBox1.GetCharIndexFromPosition(e.Location) - TextBox1.SelectionStart + 1
    End If
End Sub
Hans
  • 56
  • 4