Scroll vertical dynamically in tabPage control - vb.net

In my relatively simple project I have a two page tabControl. tabPage2 consists of dynamically created pictureBoxes (thumbnails, pic_XXX). tabPage2 is of fixed size, with AutoScroll enabled.
On tabPage1, among other things, I can search for a given name (pic_XXX). When I switch to tabPage2 I'd like it to be scrolled, so the row in which pic_XXX is, is visible. Manually scrolling in tabPage2 is working.
I'm struggling to dynamically scroll tabPage2 to accomplish this. The following solution throws an exception:
Dim pos As Point = tabPage2.Controls.Item("pic_" & imgNum).Location
tabPage2.VerticalScroll.Value = pos.Y
tabPage2.refresh()
I run out of ideas!?

So how to scroll the specified child control into view on an auto-scroll enabled control?
You should use method .ScrollControlIntoView( [Control] )
tabPage2.ScrollControlIntoView(tabPage2.Controls.Item("pic_" & imgNum) )
Answer for your question:
Dim pos As Point = tabPage2.Controls.Item("pic_" & imgNum).Location
tabPage2.VerticalScroll.Maximum = tabPage2.Height
tabPage2.VerticalScroll.Value = pos.Y
tabPage2.PerformLayout()
You have to call .PerformLayout() to make the scrolling control update.

Related

VB NET What is the good way to find a position of an object inside a scrollable panel?

I have an object inside a scrollable panel, and I want to get the position of the object. Everything is okay until I have create many object inside the panel until the panel needed to be scrolled. Then I notice that the X Position of the object changed after scrolling the panel. Take a look at example image below
X Position inside a scrollable panel
I'm using Position.X to get a X Position of the object, but as you can see in the picture above. It does me no good.
Is there a way to get the actual position even if the panel is scrolled ?
UPDATE:
I have One Panel that have Auto Scroll as True , and on Button inside a Panel, let's just say the button name is Button1 and the Panel is Panel1
The Code i use to get the location of the Button1 is :
Dim msg = Button1.Location.X
msgbox(msg)
You're getting the screen position of the object, I don't know how because you didn't post your code. What you need to do is add the scroll offset, eg.
Position.X + scrollableControl.AutoScrollPosition.X

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

How do I get scrollbar on panel

I have a Form with a Panel. In this Panel, I want to use the vertical scrollbar when I needed.
How do I do this? I've tried setting autoscroll true and set a min scroll height, but the scrollbar never appears.
I've also tried this:
my_panel.ScrollBars = ScrollBars.Vertical
but then I get the error that scrollbar is not a member of my_panel?
Thanks.
Autoscroll property is actually enough to achieve your need. Basically a panel with autoscroll property true will display the scroll bar only when the contents/components inside that panel exceeds over its bound. In other words, Scroll bar appears with controls which have autoscroll property set to true when the particular control's contents are larger than its visible area. I think your panel is having some minimum amount of contents/controls which fits inside that panel's bound.
I know You asked this question more then year ago, but... ;)
Recently, I had same problem (label inside panel, and I need only vertical scrollbar).
If You want only vertical scrollbar of panel with label inside, use code bellow :
Dim pnl As New Panel
pnl.Size = New Size(300, 200)
pnl.AutoSize = True
Dim lbl As New Label
lbl.Location = New Point(0, 0)
lbl.AutoSize = True
lbl.MaximumSize = New Size(pnl.Width - 18, 0)
'18 is approx. width of scroller, and height must be zero.
'even if Label is set to AutoSize, MaximumSize will not allow him to
'expand more then set width.
'Height of zero px will allow Label to expand as much as he need
pnl.Controls.Add(lbl)
Me.Controls.Add(pnl)
I hope this code help You.
btw. sorry for my weak English, I hope You will understand ;) :)

VB.Net Forms - MDI forms not locating correctly

I have a problem with MDI forms and their location. I have a container form within which I open several child forms. Also note that in the container form I have a ToolStrip at the top and it is also docked to the top. In each of the child forms I have set the following properties. I have set them at design time as well but it wasn't working for some reason so I put them in the form_load event as well.
Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
Me.Dock = DockStyle.Fill
ReSizeAndArrange(Me.Width, Me.Height, False)
The function ReSizeAndArrange is called on form_load and form_layout events. The problem I am having is that the child forms do not fill the remaining space correctly or for that matter the entire parent form. When I step through, here are the coordinates I am getting for the child form.
frmContainer.Size {Width = 972 Height = 972} System.Drawing.Size
me.Size {Width = 968 Height = 901} System.Drawing.Size
frmContainer.ToolStripMain.Size {Width = 954 Height = 67} System.Drawing.Size
frmContainer.Location {X = 90 Y = 22} System.Drawing.Point
me.Location {X = -9 Y = -36} System.Drawing.Point
Shouldn't the Me.Location be 0,0? The numbers add up on the sizes I think. The 4 pixel difference can perhaps be explained by the border, however, the location is unexplained. Can anyone decipher this?
OK, I solved the problem myself simply by setting the location of the form to (0,0). It still doesn't answer the question, but it is a workaround.
It's because 0, 0 doesn't put constraints on the form size/layout. It allows it to decide. Any value you put in there forces the form to conform to YOUR specs. 0, 0 isn't a work around, it's the "you decide this yourself form" way of doing it.

Reducing flicker when you change images in a panel

How do I reduce flicker in a vb2005 panel?
Inside the parent panel I have 2 other panels that I'm am using.
The outer most panel contains a background sprite and the two innermost panels are overlays that change to fit the places in the background sprite.
When I change the overlay sprites I would like to reduce the flicker and make it a smooth transition from one sprite to the next.
Here is the code that changes the images in the overlay panels
the overlay panel is not changed if the new value is the same as the old value
Private Sub TrackBar2_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar2.Scroll, TrackBar1.Scroll
If (Panel2.Tag <> TrackBar1.Value) Then
Panel2.Tag = TrackBar1.Value
Panel2.BackgroundImage = tops(TrackBar1.Value) //img array for the top panel
Panel2.Update()
End If
If (Panel3.Tag <> TrackBar2.Value) Then
Panel3.Tag = TrackBar2.Value
If (TrackBar2.Value > 0) Then
Panel3.Location = New Point(182, 210)
Else
Panel3.Location = New Point(182, 209)
End If
Panel3.BackgroundImage = bottoms(TrackBar2.Value)//img array for the bottom panel
Panel3.Update()
End If
You're not going to like this answer. The flicker is caused by the fact that the default .NET panel is not double buffered - so it does all the drawing directly in the visible memory, not a back buffer.
You need to subclass the Panel class and enable double buffering on the new class. This can be done by doing a
SetStyle
call in the constructor with the flags OptimisedDoubleBuffering and DoubleBuffering enabled.
Once you have the new panel class that is double buffered, you can use them in your application instead of the standard Panel.
I told you you wouldn't like the answer ;)
Rein is right, subclassing is the best way. In the meantime though, change that call from Update to Invalidate; that might help a little.