Unable to dynamically load a control into a SplitContainer panel - vb.net

I have placed a SplitContainer control onto a form. I have a custom control inside panel 1. This custom control is the container for another user-control.
There is a TreeView control inside this user-control. I am trying to load another user-control onto panel 2 upon selection of a node in the tree view. But its not getting loaded. Am i missing something?
The code for loading the control is given below:
Dim ucImportExcel1 As New ucImportExcel()
frmMain.SplitContainer1.Panel2.Controls.Add(ucImportExcel1)
ucImportExcel1.Dock = DockStyle.Fill
An addition to the above: In the same treeview selection event
For the code below it sets the form text:
me.parentform.text = "Sample Text 1"
Whereas if use this code, nothing happens:
frmmain.text = "Sample Text 2"

When referred by a Directcast, it solved the problem:
DirectCast(Me.ParentForm.Controls.Item("SplitContainer1"), System.Windows.Forms.SplitContainer).Panel2.Controls.Add(ucImportExcel1)

Related

How to open a winform at same location and with same size of its parent in vb.net? Parent may be Winform or UserControl

Dim popCus As New PopCustomer()
popCus.StartPosition = FormStartPosition.Manual
popCus.Location = New Point(ctrList.Location)
popCus.Size = New Size(ctrList.Size)
popCus.ShowDialog()
Here ctrList is a UserControl's object and PopCustomer if a Winform.
I want open PopCustomer at same location and same size of ctrList.
The problem there is that the Location of the UserControl is relative to its own parent while for the form it's relative to the screen.
If you change this:
popCus.Location = New Point(ctrList.Location)
to this:
popCus.Location = ctrList.PointToScreen(Point.Empty)
then you'll get the effect you want. You can actually use the same code for a form so that means that you can write a single method with a Control parameter and then use that parameter to set the Location and Size of the new form. You can then call that method and pass either a form or a user control as an argument.

VB.net how to get the value from my user control textbox

I do have a project for daily monitoring, and I have a problem getting the text from my textbox wherein my textbox is in my usercontrol.
the scenario would be, if I click the show button, the userControl.vb would be called in my panel and I dont have a problem putting up userControl.vb to my panel, if I click save button which will check if all fields are fill-up before saving the data. I would save as normal and wont check my panel where I load up my userControl.vb
this my snippet project tree:
DXApplication
|_My Porject
|_User Control <folder>
|_userControl.vb <user control form>
|_frmMainActivity <winForm>
here is my code for loading the userControl in my Panel
Friend ctrlUser As UserControl
ctrlUser = New userControlx
ctrlUser.Dock = DockStyle.Top
pnlActivity.Controls.Clear()
pnlActivity.Controls.Add(ctrlUser)
here is code for calling the textbox from userControl from another sub to check if the code can get the text.
*edited the userControl should be userControlx*
Dim uc As New userControlx
Msgbox(uc.txtLatitude.text)
when i hit the trigger button to show what text i put on my textbox i would return msgbox with empty string.
Any suggestion? where did I go wrong on calling the value of the textbox?
I've tried using:
Dim uc As New userControlx
uc.txtLongitude.text = "Test Text"
msgbox(ux.txtLongitude.txt)
It will return the Test Text, But in my UI the textbox that is loaded is empty.
in the trigger button you create a new instance of userControl, thats why the content of your textbox is emtpy
instead use
Msgbox(ctrlUser.txtLatitude.text)

VB.NET - form inside a panel resize

I can't figure this out! I've researched docking, anchoring etc. but I'm yet to get it to correctly resize when the parent form resizes.
Edit:
Quick Overview:
I have a main form with a menustrip docked to the top and a panel set to fill. I have links within the menustrip which open forms within the panel. See code below. I am struggling to get the form within the panel to resize with the panel.
I've set the panel background to black and my form inside the panel to white. I can see the panel resizing with the form correctly. The form within the panel stays in its original position. If i start my app in maximized, then click on my menustrip sure enough the form within the panel resizes correctly. However, once it is maximized it doesn't shrink with the form like the panel container does.
I've deleted everything on my whole form, added 1 panel to it and set to fill then on form load do the following:
Dim f As New Contactdetails With {.TopLevel = False, .AutoSize = True}
f.Dock = DockStyle.Fill
Me.Panel2.Controls.Add(f)
f.Show()
This still doesn't work. When i maximize my main form, the form inside the panel does not resize but the panel does as i've changed it's background to monitor its change in size
Turn AutoSize off:
Dim f As New Contactdetails With {.TopLevel = False, .AutoSize = False}
f.Dock = DockStyle.Fill
Me.Panel2.Controls.Add(f)
f.Show()
If the previous form in the panel isn't being used anymore, then you should first dispose of it:
While Me.Panel2.Controls.Count > 0
Me.Panel2.Controls(0).Dispose()
End While
Set the WindowState to Normal in properties of the child form
and
Me.Dock = DockStyle.
Fill in the Load sub of the child form

Visual Basic PictureBox Panel Flicker

I am making a simple game that (for the main part) consists of a Panel with a grid of 32 PictureBoxes inside, each with a BackgroundImage. You click on a "tile" and it flips revealing a picture. My problem is that when the Form Loads, I can see it drawing. I see the Panel .. then empty PictureBoxes, then finally it fills in the PictureBoxes with the BackgroundImages.
I've turned DoubleBuffer to True for the Form, and I've also added the following:
Private Sub UseDoubleBuffer()
Me.SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.UserPaint Or ControlStyles.DoubleBuffer, True)
Me.UpdateStyles()
End Sub
Which I call when the Form Loads. I'm not sure what else I can do? I want it to just 'pop' onto the screen. Why isn't the DoubleBuffer working? Do I need to code the panel manually? I was trying to avoid that as it's obviously easier to just drag and drop into the Form, but if I need to, I will.
I can't post screenshots apparently, as my rep isn't high enough yet, but believe me, it looks hideous, and I do want to make this as sleek as I possible can. Any ideas?
Try creating flicker free custom panel controls:
Here are the steps to use this control:
1. Add new class "NonFlickerPanel" to your C# application.
2. Replace autogenerated class code with C# code shown below.
3. Use NonFlickerPanel object instead of Panel object in your application.
public partial class NonFlickerPanel : Panel
{
public NonFlickerPanel() : base()
{
this.SetStyle(ControlStyles.AllPaintingInWmPaint,
ControlStyles.UserPaint
ControlStyles.OptimizedDoubleBuffer,
true);
}
}
Try making the picture boxes invisible (.visible = false) until they're all loaded, then set visible to true for all of them.

vb.net tabpage using a form for tabpanels issues

I have a simple vb.net form a tabpanel strip, and then a seperate form which is loaded for the tabpage.
Here is the code for the button that dynamically creates new tabs:
Dim tempTab As New TabPage
initTab(tempTab)
xt.TabPages.Add(tempTab)
xt.SelectedIndex = xt.TabCount - 1
Here is the code for the "initTab":
Dim tmpTab As New MainTab
tmpTab.Dock = DockStyle.Fill
tmpTab.Panel1.Dock = DockStyle.Fill
tab.Controls.Add(tmpTab)
tab.Text = "Untitled"
tab.Name = " "
I can easily set the focus of any tab by entering following which sets the focus for example to the last tab:
xt.SelectedIndex = xt.TabCount - 1
Now the issue is, how can I set the focus to a textbox on the custom form (in my example labeled "MainTab")? I've tried virtually everything I can google and I can't seem to find any example of how to setfocus or even set/get anything from the MainTab form.
Anyone can help me?
Erm, turning a form into a child control takes some surgery. You have to set its TopLevel property to false, hide the border, make it visible. I don't see it in the code snippet, is MainTab actually a form?
Anyhoo, you cannot use the Focus() method on a control until it is visible. Odds are good that it isn't visible yet in your code snippet. Use the Select() method instead. Say:
tmpTab.TextBox1.Select()
Or just set the TabIndex property of the first control that should get the focus to 0 in the designer.
xt.Controls(xt.SelectedIndex).Controls("TEXTBOXNAME").Focus()
Just make sure that you set the Name property of the textbox you want to have focus (in this case the name would be TEXTBOXNAME) if you do it like this.