Form control within Groupbox control - vb.net

I have multiple form application in vb.net
Now i rose to a condition where i want to display one Form in the Groupbox/Panel control of other form.
Is there any way to achieve that???
Any help is appreciated..

If you must, you can do that. Here is an example:
Dim f As New Form
f.TopLevel = False
f.FormBorderStyle = FormBorderStyle.None
f.Dock = DockStyle.Fill
f.Visible = True
Panel1.Controls.Add(f)
The TopLevel = False is a requirement. Setting the FormBorderStyle and Dock style are optional, but probably what you are looking to do.

You cannot put Form on another Form - use User Control for that.
see
User Control vs. Windows Form

Related

Is it possible to change the text of a label in another form without using .Show() or .ShowDialog

I have a problem on Vb.net
My question is if it is possible to change the text of a Label without using frm.Show () or .ShowDialog().
Example :
frmMain As frmMain = New frmMain
frmMain.lblText.Text = "Hello please help"
without using a .Show() since it is already shown in a panel :
Yes, it is possible.
What Plutonix said in the comment, I guess is use the label in another form which already exists instead of making a new one.
For example, add a label1 in NewForm1 while designing the form.
Then, in Form1, you can do this:
NewForm1.label1.text = "Your text here"
Otherwise, if you don't want to put a label already in the design time,
you can add it like this:
Dim NewLabel1 As New Label
With NewLabel1
'add properties here
.Text = "your text"
.Parent = Me 'set the parent of the label as new form
.Location = New Point(1, 1)
'other properties here
End With

Set a group of controls visible with one line of code?

Is it possible to clump a group of controls together and be able to set it visible with one line rather than having to do each individual control's .visible property? I know it doesn't hurt anything but would like to keep it looking neat and not clump up a function with a page full of .visible control calls.
Just group your controls in a List(Of Control) or an array and set the Visible property using either the ForEach-method or a simple For Each-loop.
e.g.:
Dim toToggle = {OkButton, CancelButton, ControlPanel, SelectionComboBox}
For Each ctrl in toToggle
ctrl.Visible = False
Next
or
Dim toToggle = {OkButton, CancelButton, ControlPanel}.ToList()
toToggle.ForEach(Sub(c) c.Visible = False)
I like Dominic's solution. Another approach (and this depends on how your Winform is laid out) would be to group the controls into a panel:
For Each ctrl as Control in MyPanel.Controls
c.Visible = False
Next
Really all this approach does is keeps you from having to create a new list, but maybe that would be better so you can choose precisely which controls to add.

Disable all controls in 'details' section of a MS Access form

I am looking for some command which will disable all controls present in the 'details' section of an MS Access Form. One way is to disable each and every control independently. I am looking for a control-independent way which would disable all the controls present in the details section of MS Access Form.
This feature might be useful, if the form is to be enabled based on some login credentials and the fields for entering credentials is placed in the header section of the form. So, as soon as user does login, all the controls in that form are enabled. Uplon logout, they shall be disabled.
I tried searching for it but it seems the same is not supported. Or no one had such a requirement before.
Please help me if anyone knows.
A form has various properties that match this requirement: Allow Edits, Allow Additions and Allow Deletions. Allow Edits works for unbound controls, it even works on unbound forms.
If you have a requirement to disable certain controls, you can set the tab property for these controls to a string and then iterate through the form's control collection to disable those controls.
Dim frm As Form
Dim ctl As Control
Set frm = Forms!MyOpenForm
For Each ctl In frm.Controls
If ctl.ControlType <> acLabel And ctl.ControlType <> acTabCtl Then
If ctl.Tag = "AdminHide" Then
If varWho = "Authorized" Then
ctl.Visible = True
Else
ctl.Visible = False
End If
End If
End If
Next
You can disable all of the controls in the detail section directly without having to bother with tags:
Dim ctrl As Control
For Each ctrl In Detail.Controls
If (TypeOf ctrl Is TextBox Or TypeOf ctrl Is ComboBox)
ctrl.Enabled = False
End If
Next
Similarly, you can get at the controls in the header and footer using FormHeader.Controls and FormFooter.Controls.
I usually prefer to use ctrl.Locked = True instead of ctrl.Enabled = False since users can still copy text from locked controls and use text filters on them, but that's up to you.

Properties not passing to from in VB.NET custom control

I have a custom VB.NET control that I created that is working correctly in one program but not in another. The control has one button and one form. The form displays some data based on the settings in the control.
This is the use in both test projects:
With Me.MyControl1
'.Connection = gConn
.Server = "servername"
.DBName = "dbname"
.TableName = "table"
.FieldString = "list of fields"
.ReturnColumn = 0
.AllowMultiSelect = True
End With
This is how I am passing the settings to my form.
...this form is a part of the control
Public Sub New(ByVal cmsl As MyCustomControl)
' This call is required by the Windows Form Designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
Me.Connection = cmsl.Connection
Me.ConnectionString = cmsl.ConnectionString
Me.Server = cmsl.Server
Me.DBname = cmsl.DBName
Me.TableName = cmsl.TableName
Me.FieldString = cmsl.FieldString
Me.FilterString = cmsl.FilterString
Me.AllowMultiSelect = cmsl.AllowMultiSelect
Me.AutoPopulate = cmsl.AutoPopulate
Me.ReturnColumn = cmsl.ReturnColumn
Me.SelectTop = cmsl.SelectTop
End Sub
In TestProject1 - the control is working as expected
In TestProject2 - the control is not sending any of the settings I set to the form
My control works fine when I debug with the UserControl TestContainer.
I am using VB.NET on VS2005.
This is all done on the same machine. Why would this work in one project and not another?
Seems like a reference error. please show us how the UserControl is integrated. The problem must come from there.
And are you talking about a custom control, or a UserControl ? (Not the same thing for me)
Try some breakpoints in the props, and also, try checking the references :). You might be working with a second usercontrol overlapping on the first one or something like that :).
In winforms the Designer sometimes goes weird.

VB.Net WebBrowser Navigate Only Working Once

Hoping someone can help me with this. I have two separate but related Forms, one of which contains a WebBrowser control. The user fills out some information on Form 1 and clicks a button with the following code:
If Form2Shown = False Then
Dim memoscreen As New Form2
Form2Ref = memoscreen
memoscreen.show()
Form2Shown = True
memoscreen.TopMost = OptionOnTop
Else
Dim memoscreen As Form2
memoscreen = Form2Ref
memoscreen.TopMost = OptionOnTop
memoscreen.QuickRefresh()
End If
The QuickRefresh sub in Form2 is the method that navigates. It is called both when the form is loaded as well as manually in the code above:
Public Sub QuickRefresh()
Dim HM As Form1
HM = Form1Ref
Me.Text = "retrieving information..."
Me.AxWebBrowser1.Navigate("SomeValidURL")
HM.Focus()
HM.SetHugoFocus()
End Sub
The problem I'm having is that the first time QuickRefresh is called (i.e. when Form2 is loaded) the navigation is successful and the page displays fine. If I then click the button on Form1 again, the page does not change. The Text attribute and window focus does change however, so I know the method is firing.
Some things I've tried/checked:
AllowNavigation is set to True on the WebBrowser control
Have tried looping while the browser is busy while calling Application.DoEvents()
Any suggestions would be appreciated. Thanks.
From your "Internet Options dialog > General Tab > Settings Button > Check for newer version of stored page" change that option to *Every Time I visit the webpage". That setting impacts how the webbrowser control deals with the refreshing.
Use the method refresh.
browser.Navigate("http://www.google.com") : browser.Refresh()