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
Related
I have set a Panel to AutoScroll = True.
I host a button in this panel.
When I set the button to a new location outside the panel's visible area...
.Location = New Point(2000, 0)
... this doesn't make the scrollbars appear.
How could I force the panel to invalidate / check again if the scrollbars should be shown?
I got it:
I need to set the button's parent to something else, then add it to the panel again which raises the ControlAdded event.
I'm currently working on a Windows Forms Application that is essentially a bunch of forms laid on top of each other. Right now, I have this...
MainForm - MDI Parent
ChildForm - Dock set to 'Fill' in MainForm
Sidebar1 - Dock set to 'Left' in MainForm
Sidebar2 - Dock set to 'Right' in MainForm - able to be resized
ChildChildform - Dock set to 'fill' in MainForm, overtop of Childform
So here's my issue - since Sidebar2 is able to be resized widthwise, I figured it would work fine to throw a button on that does the resize for me - push a button, it slides in, push a button, it slides out - kind of like a slide out on screen keyboard. However, when I slide this out while ChildChildForm is up, ChildChildform dissappears and it goes back to displaying Childform.
My best guess is that since ChildForm and Sidebar1 are both set to MDIParent = MainForm, it's displaying on ChildForm First, since ChildChildForm is set to MDIParent = Mainform, but it's the second one...
Anyone have any tips on how to roll the sidebar in to the topmost form if that topmost form is an MDIChild?
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)
I am developing a Windows Application in VB.Net. In that, there is one case where there is one form, and in that form there is a Panel, and within the Panel there is a rich text box.
So my requirement is to get a scrollbar in the Panel. So when the user does scroll on the panel, the rich text box can scroll accordingly like MS Office functionality..
Can any one give me an idea how to do it?
Set Panel.AutoScroll = True and scrollbars will automatically appear whenever any controls in the panel fall outside its boundaries.
Set the .Dock property to FILL and the .WordWrap property to FALSE for the richtextbox.
Also set the Panel's .Dock property to FILL.
In order to use panel autoscroll property I do that:
panel.AutoScroll = true
panel.VerticalScroll.Visible = False or panel.HorizontalScroll.Visible = False
In order to know the dimensions of the scroolbars use
SystemInformation.HorizontalScrollBarHeight
SystemInformation.VerticalScrollBarWidth
So you can change the dimension of the panel when the scroolbar is shown.
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.