Tabpage is empty after adding user control to vb.net tabpage - vb.net

I am trying to display an usercontrol(has several panels one on top of the other panel) on tabpage. I am using below code to achieve this.
Dim ctrl As TechniciansControl = New TechniciansControl
TabControl1.TabPages(2).Controls.Add(ctrl)
The problem is that the control doesn't show anything. I verified the control is created correctly. The tabpage is empty. It works for other usercontrol which has only one panel.
Appreciate any ideas to fix this issue.

Make sure that the control is visible and, also, make sure that it's location is within the viewable client area of the tab control.

Related

How to add existing winform to multiple tabpages

I want to add the same Form in project to five tabpages in TabControl.
This is what i have tried
For i As Integer = 0 To 4
'XtraTabPage instance (DevXpress)
Dim page As New XtraTabPage()
'ExamsTab is the existing form that i want to add tho the page
Dim fm As New ExamsTab
fm.TopLevel = False
fm.Dock = DockStyle.Fill
page.Controls.Add(fm)
fm.BringToFront()
fm.Show()
'Adding the page to the TabControl in Exams_Class
Exams_Class.ExamsTabControl.TabPages.Add(page)
Next
This only adds the form to the last tabpage but doesn't add to others.
If that didn't work I'd try page.Controls.AddRange(fm.Controls) but I'm not in a position to test it.
In the past when I've wanted to keep my code better organized into one form per tab I've:
made a new form
put a tabcontrol on it with a single page, call the control TheTabControl for example
put all the controls into the tab page, put all the events etc in the form code
put a line of code that retrieves the tab:
Public Function GetTab() As TabPage
Return Me.TheTabControl.TabPages(0)
End Function
on the main form, with the one tabcontrol that should contain all the other tab pages, have a code like:
MainTabCobtrol.TabPages.Add(New SomeOtherForm().GetTab())
This way all the controls and their event handlers stay in one form (a good thing) but you can combine them together into one Tab Control on another form. Putting them inside a tab means you can get an idea of how to size it, and you can specify in the designer other things like the tab name etc
From a code organising perspective, it's something the designer can more easily cope with than having all the TabPages in one. Control and all the event handlers etc (makes for a fairly monster form code behind and it doesn't respond well to being split into partial classes)
If you want to add a tab control to the existing form the Document Outline window might be helpful for moving the controls into it with drag and drop. You could also cut all the controls, add a tab and paste, but check the eventbhabdlers are all still wired up afterwards- I find that sometimes this makes them go missing

Is there a way to hide all panels in windows forms using vb.net?

i was wondering if it was possible to hide everything at once in windows forms, i was planning to use a drop down which made things appear and disappear but i wanted everything hidden at the beginning for simplicity.
Thanks!
On the form, add a Panel control (found in the Containers section of the toolbox).
Set the Visible value of the Panel to be False.
Add all controls inside this panel. You can then make the panel visible and hidden via code. (no need to cycle through all controls on the form)

How can a ContextMenuToolStripItem be displayed, without doing it programmatically?

I've taken over a project, which contains some UltraWinGrid controls on some of the forms.
On one of the original forms which has been there since before I took on the project, there is a ContextMenuStrip, which has just one ContextMenuToolstripItem on it, captioned 'Default for Column'.
This ContextMenuStrip is hidden by default, however, when the user right-clicks on the UltraGrid, the ContextMenuStripItem is displayed on the grid (rather than at the top of them form where the ContextMenuStrip is).
I'm trying to replicate this behaviour in a new form that I've added myself, however, after adding the ContextMenuToolstripItem in, I cannot get it to display when right-clicking my grid.
I've put a breakpoint on every subroutine in the in the older forms class, and none of them are triggered when right-clicking it.
Additionally I have also searched the class for DefaultForColumnToolstripMenuItem, and the only place it appears is in the Click event of the ContextMenuToolStripItem itself.
So, how else is it possible to show it when right-clicking the grid? I've copy and pasted the ContextMenuStrip from the old form onto the new form and still nothing occurred.
I'm assuming it's in a property somewhere that I'm missing?
Check for a ContextMenuStrip property on the UltraWinGrid. You can set it in the designer and your context menu will appear on right click without having to deal with the MouseClick handler, checking the mousebutton used, etc.

Multiple Views One Form

I'm looking to have a navigation pane on the left side of my form which will change the right side of the form accordingly. I could always use panels and store the controls on the panels but is there a better way to do this? A tab control would be nice but I wouldn't want to see the actual tabs ...
Is there a way to do this?
Edit after seeing the answer:
Dim uc As New UserControl1
Form1.Controls.Add(uc)
Will add everything in the user control to the form1. Alternatively, if I had a Panel, I could do:
Panel1.controls.add(uc)
That would add it to the panel.
You can use panels, but you could also have your panes as UserControls and load them into a single panel instance, or even directly into the form.
Putting them into UserControls also means your form's generated class won't be cluttered with control members.
I would have to agree with #Dai Here is a great thread on it. It explains how to setup the panels in the ide.

VB.Net UI is missing

I'm using Visual Studio 2012 to make a Vb.Net application.
In short, I added DotNetBar RibbonControl with some RibbonItems on it as my menu.
What happened is one of my tab is suddenly missing along with all the buttons in it.
I have searched for it on my Document Outline still no luck.
But what even more odd is, when I tried to recreate it with the same name, it shows an Alert "Property value is not valid" with message "The name AppPOButton is already in use by another component".
When I checked it on the form's Designer I do found this lines:
Me.AppPOButton = New DevComponents.DotNetBar.ButtonItem()
and
'AppPOButton
'
Me.AppPOButton.ButtonStyle = DevComponents.DotNetBar.eButtonStyle.ImageAndText
Me.AppPOButton.Image = Global.ProjectBMT.My.Resources.Resources.approval
Me.AppPOButton.ImageFixedSize = New System.Drawing.Size(40, 40)
Me.AppPOButton.ImagePosition = DevComponents.DotNetBar.eImagePosition.Top
Me.AppPOButton.Name = "AppPOButton"
Me.AppPOButton.SubItemsExpandWidth = 14
Me.AppPOButton.Text = "Approve"
Me.AppPOButton.Visible = False
and
Friend WithEvents AppPOButton As DevComponents.DotNetBar.ButtonItem
Is there anyone can explain why this is happening?
Thank you
This behavior is weird itself, but it's not a problem actually, All the Ribbon style works on "Containers", if you check your ribbon control and click the left-upper button will see these little arrows that move four containers, these objects hold the buttons, images and other controls. Within your design window in the right panel (Properties) you can still see the names of the controls you "lost" when you deleted your tab, wich is also a container.
Steps:
Add a container within your design view and Dock it into the Ribbon control Form.
Click on the uppper right boton (Right Arrow) and select "Layout Ribbon", this will adjust the lenght and hight of the controls conatained.
Add the tab that will contain all the controls you have.
The fact that they are still in the designer form is the prove that they still exist, This behavior is just a glitch in the position and order of the controls set above your form ;-)