Panel control stuck on visible=false - vb.net

Im using vb2008 express edition.
I have a form with panel control set to visible=false( i add it for copy it properties).
I tried to add panels dynamically but when i do it, i cant see it on the form.
I even set code line for panel.visble=true but when i run the watch window it stuck on visible =false
Sub addPlayer(ByVal p As Form2.player)
' Timer1.Enabled = False
Dim gap As Integer = 20
Dim pan123 As New Panel
Dim nick As New Label, colorFrame As New Label
pan123.Size = New Size(100, 100)
pan123.BackColor = Color.AliceBlue
pan123.ForeColor = Color.Aquamarine
pan123.Location = New Point(200, 200)
'pan.Size = Panel1.Size
'pan.Location = Panel1.Location
'pan.Top = Panel1.Top + Panel1.Height * playersNum + gap * playersNum
nick.Text = p.nick
nick.Size = Label2.Size
nick.Location = Label2.Location
nick.Font = Label2.Font
nick.AutoSize = True
colorFrame.AutoSize = False
colorFrame.Size = Label3.Size
colorFrame.Location = Label3.Location
colorFrame.BackColor = p.colorP
pan123.Visible = True
'pan.Controls.Add(nick)
'pan.Controls.Add(colorFrame)
Me.Controls.Add(pan123)
'nick.Visible = True
playersNum = playersNum + 1
End Sub

Related

Rotate / Scroll picture boxes

I have a row of PictureBoxes created at run time which occupy more of the form's visible width. I want them to scroll at certain intervals so the user sees all of them if he waits.
I believe I must code to a Timer.
But what is the code for that? (The Form is set scrollable, but I do not want the user to interact with it. Just click the PB he likes)
Code for PB creation
'' In Form_Load:
Dim allSeries As IEnumerable(Of String) =
Directory.EnumerateFiles(root, "*.jpg", SearchOption.AllDirectories)
For i = 0 To allSeries.Count - 1
pb(i) = New PictureBox With {
.Name = "pb" + i.ToString,
.BackColor = Color.Transparent,
.Size = New Point(250, 300),
.BorderStyle = BorderStyle.None,
.SizeMode = PictureBoxSizeMode.Zoom,
.Top = 10,
.Left = pbLeft,
.Cursor = Cursors.Hand,
.Image = Image.FromFile(allSeries(i).ToString), 'Get the Image from the Directory
.Tag = Path.GetDirectoryName(allSeries(i)) 'Store Direcyory path
}
Controls.Add(pb(i))
pbLeft = pbLeft + 300 'position next to previous
'Next
Next
Thanks!

Positioning similar type objects on form programmatically in vb.net

I have a from which contains some PictureBoxes. They can be from one to many.
I create them at run-time depending on the existence of specific folders.
I create them and place them the one next to each other. This means that with a scrollable form I can view all of them easy.
My question is this: How do I position them in "rows"? For a specific form size, there can be 5 labels next to each other and infinite rows of them
How do I achieve this?
My (working) code:
Public allSeries As IEnumerable(Of String) = System.IO.Directory.EnumerateDirectories(root)
For i As Integer = 1 To allSeries.Count
Dim pb As New Windows.Forms.PictureBox With {
.Name = "pb" & i.ToString,
.Size = New Drawing.Size(500, 500),
.Location = New Point(5, 5),
.BorderStyle = BorderStyle.FixedSingle,
.SizeMode = PictureBoxSizeMode.Zoom,
.Image = Image.FromFile(allSeries(i - 1).ToString + "\sImage.jpg"),
.Tag = traveldestination, 'Store Directory path
.Cursor = Cursors.Hand}
Me.Controls.Add(pb)
For i As Integer = 2 To allSeries.Count
With Me
.Controls.Item("pb" + i.ToString).Left = .Controls.Item("pb" + (i - 1).ToString).Left + 520
End With
Next
My (bad) and (not workng) code:
Dim pbsOnForm As Integer = 13 'total PictureBoxes on Form /for this instance
Dim pbsOnRow As Integer = 5 'PictureBoxes that "fit" in a row /for this intance)
For i As Integer = 1 To pbsOnForm
If i <= pbsOnRow Then
Me.Controls.Item("pb" + i.ToString).Top = Me.Controls.Item("pb" + i.ToString).Top
End If
If i > pbsOnRow And i <= 10 Then
Me.Controls.Item("pb" + i.ToString).Top = Me.Controls.Item("pb" + (i - pbsOnRow).ToString).Top
End If
Works, but when the PcrureBoxes will be more than 10, I do not know......
While using the TableLayoutPanel would fulfill most cases for this and is probably the best way to achieve this, here is some code to align the PictureBox's in row / column.
First we want to setup a method to handle the positioning. We need some variables scoped to the Form.
Dim counter As Integer = 0
Dim xPos As Integer = 5
Dim yPos As Integer = 5
Now we use these variables in a method that sets the location.
Private Sub PositionPictureBox(pb As PictureBox, Optional imgPerRow As Integer = 5)
pb.Location = New Point(xPos, yPos)
counter += 1
If counter = imgPerRow Then
counter = 0
xPos = 5
yPos = pb.Location.Y + pb.Height + 5
Else
xPos = pb.Location.X + pb.Width + 5
End If
End Sub
Finally we call the method when the PictureBox is instantiated.
For i As Integer = 1 To allSeries.Count
Dim pb As New Windows.Forms.PictureBox
With pb
.Name = "pb" & i.ToString()
.Size = New Drawing.Size(50, 50)
.Location = New Point(5, 5)
.BorderStyle = BorderStyle.FixedSingle
.SizeMode = PictureBoxSizeMode.Zoom
.Image = Image.FromFile("...")
.Tag = allSeries(i)
.Cursor = Cursors.Hand
End With
PositionPictureBox(pb)
Me.Controls.Add(pb)
Next

Unexpected TableLayoutPanel Behavour

Hi having some issues with some nested tablelayoutpanels in a custom control
I have a tablelayoutpanel in a tablelayoutpanel in a tablelayoutpanel Crazy i know but it keeps it uniform and ordered
The custom control consists of 2 tablelayoutpanels that is placed in a table layout panel on a form and in a preview area of my main form.
Having them set at design time works fine but dynamically adding / removing the topmost ones with 1 row 2 columns into the one below it that has 1 column and x rows only Seems to break the autosizing behavior I'm chasing.
So I want the cells & rows to resize automatically based on the contents in this case labels but still remain in a neat ordered layout
There's no docking anywhere in the hierarchy of controls just anchors here and there
Here's my code to add the tablelayoutpanels below
"https://i.stack.imgur.com/vRfhE.png"
Private Sub AddControl(ByRef Counter As Counter)
Dim Gpanel As New TableLayoutPanel
Dim tlabel As New Label
Dim clabel As New Label
Dim pad As Integer = Counter.Cpad
TLPanel.AutoSizeMode = AutoSizeMode.GrowAndShrink
Gpanel.AutoSizeMode = AutoSizeMode.GrowAndShrink
Gpanel.AutoSize = True
Gpanel.GrowStyle = TableLayoutPanelGrowStyle.AddRows
Gpanel.BorderStyle = BorderStyle.FixedSingle
Gpanel.CellBorderStyle = TableLayoutPanelCellBorderStyle.Inset
TLPanel.BorderStyle = BorderStyle.FixedSingle
Gpanel.Dock = DockStyle.None
Gpanel.Padding = New Padding(0)
Gpanel.Anchor = AnchorStyles.Top Or AnchorStyles.Left
Gpanel.BackColor = Color.Transparent
Gpanel.RowCount = 1
Gpanel.ColumnCount = 2
Gpanel.RowStyles.Add(New RowStyle(SizeType.AutoSize))
Gpanel.ColumnStyles.Add(New ColumnStyle(SizeType.AutoSize))
Gpanel.ColumnStyles.Add(New ColumnStyle(SizeType.AutoSize))
tlabel.Dock = DockStyle.None
clabel.Dock = DockStyle.None
tlabel.GetPreferredSize(Size.Empty)
clabel.GetPreferredSize(Size.Empty)
tlabel.Text = Counter.Clabel
clabel.Text = Counter.Ccount.ToString
tlabel.Padding = New Padding(pad)
clabel.Padding = New Padding(pad)
tlabel.Anchor = AnchorStyles.None
clabel.Anchor = AnchorStyles.None
tlabel.ForeColor = Color.FromName(Counter.Clcolor)
clabel.ForeColor = Color.FromName(Counter.Ccolor)
Dim fontstyle As New FontStyle
fontstyle = Counter.ClfontStyle
tlabel.Font = New Font(Counter.Clfont, Counter.Clfontsize, fontstyle)
fontstyle = Counter.CcfontStyle
clabel.Font = New Font(Counter.Ccfont, Counter.Ccfontsize, fontstyle)
Gpanel.Controls.Add(tlabel, 0, 0)
Gpanel.Controls.Add(clabel, 1, 0)
TLPanel.Controls.Add(Gpanel, 0, Counter.ID)
TLPanel.RowCount += 1
TLPanel.RowStyles.Add(New RowStyle(SizeType.AutoSize))
Dim Styles As TableLayoutRowStyleCollection = TLPanel.RowStyles
Dim Cstyles As TableLayoutColumnStyleCollection = Gpanel.ColumnStyles
Gpanel.RowStyles.Item(0) = New RowStyle(SizeType.AutoSize)
TLPanel.ColumnStyles.Item(0) = New ColumnStyle(SizeType.AutoSize)
For i = 0 To Cstyles.Count - 1
Cstyles.Item(i) = New ColumnStyle(SizeType.AutoSize)
Next
For i = 0 To Styles.Count - 1
Styles.Item(i) = New RowStyle(SizeType.AutoSize)
Next
TLPanel.CellBorderStyle = TableLayoutPanelCellBorderStyle.Inset
AutoSize = True
AutoSizeMode = AutoSizeMode.GrowAndShrink
End Sub
'

VB.net Adding Picturebox with Label and Scrollbar dynamically

So basically what I wish to accomplish is that I set total of Pictureboxes to add and each picturebox has its own according label and if we reach 6 images we allow the scrollbar to go down.
Example:
http://i.imgur.com/5xWu5Y1.png
As you can see pictures are added accordingly with label.
How can I do this in code?
Currently I got something like this:
' Total PictureBoxes/Labels to Generate
Dim wTotalPictures = 1
' Original PictureBox Starting Point
Dim wOriginalLocation = New System.Drawing.Point(40, 54)
' Assigned Label Title
Dim wImageTitle As String = "PictureTitle"
Dim wNewImage As New PictureBox
Dim wImageSize = New Size(122, 173)
With wNewImage
.SizeMode = PictureBoxSizeMode.StretchImage
.Image = Image.FromFile("C:\Users\Jason\Pictures\newImage.jpg")
.Location = wOriginalLocation
.Size = wImageSize
End With
So any help would be greatly appreciated!
EDIT:
I've now managed to change it into this, this works way better but still not 100% automatic like I want it.
' Total PictureBoxes/Labels to Generate
Dim i As Integer = 0
Dim wTotalPictures = 5
' Original PictureBox Starting Point
Dim wOriginalLocation = New System.Drawing.Point(40, 54)
' Assigned Label Title
Dim wImageTitle As String = "PictureTitle"
Dim wImageSize = New Size(122, 173)
Dim wNewLocation As Integer = 0
Do Until i = wTotalPictures
' Setup
Dim wNewImage(i) As PictureBox
wNewImage(i) = New PictureBox
' Execute
wNewImage(i).SizeMode = PictureBoxSizeMode.StretchImage
wNewImage(i).Image = Image.FromFile("C:\Users\Jason\Pictures\newImage.jpg")
wNewImage(i).Size = wImageSize
If wNewLocation < 480 Then
wNewImage(i).Location = New System.Drawing.Point(40 + wNewLocation, 54)
ElseIf wNewLocation = 480 Then
wNewImage(i).Location = New System.Drawing.Point(40, 258)
wNewLocation = 0
End If
' Add to Form
MyTab.Controls.Add(wNewImage(i))
wNewImage(i).BringToFront()
wNewLocation = wNewLocation + 160
i += 1
Loop
Please help, thanks!

How to get the value of a textbox from sa MDI form Groupbox?

I'm new to vb.net and always searching for solution. My forms involved are MainMenu, poCustom, and rdlcForm. All are working well until I got a new look with MDI Forms.
My "New" MainMenu are now containing the poCustom into a Groupbox. Which I searched the code as
For Each f As Form In Application.OpenForms
If TypeOf f Is poCustom Then
f.Activate()
Return
End If
Next
Dim ch As New poCustom
ch.TopLevel = False
ch.Visible = True
ch.StartPosition = FormStartPosition.Manual
Dim leftStart As Integer = 1220 - (ch.Width + (SystemInformation.Border3DSize.Width * 2))
Dim topStart As Integer = 670 - (ch.Height + (SystemInformation.Border3DSize.Height * 2))
ch.Location = New Point(leftStart, topStart)
GroupBox1.Controls.Add(ch)
Problem: The rdlcForm(report) cannot get the value of textboxes in poCustom form. Code below:
Private Sub rptPOView2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim rptParam1(11) As Microsoft.Reporting.WinForms.ReportParameter
rptParam1(0) = New Microsoft.Reporting.WinForms.ReportParameter("rptDate", poCustom.Label1.Text)
rptParam1(1) = New Microsoft.Reporting.WinForms.ReportParameter("rptREF", poCustom.Label5.Text)
rptParam1(2) = New Microsoft.Reporting.WinForms.ReportParameter("rptCompany", poCustom.CompanyName.Text)
rptParam1(3) = New Microsoft.Reporting.WinForms.ReportParameter("rptQTY", poCustom.txBoxQTY.Text)
rptParam1(4) = New Microsoft.Reporting.WinForms.ReportParameter("rptUOM", poCustom.txBoxUOM.Text)
rptParam1(5) = New Microsoft.Reporting.WinForms.ReportParameter("rptDesciption", poCustom.txBoxDesc.Text)
rptParam1(6) = New Microsoft.Reporting.WinForms.ReportParameter("rptUnit", poCustom.txBoxUnit.Text)
rptParam1(7) = New Microsoft.Reporting.WinForms.ReportParameter("rptTotal", poCustom.txBoxTotal.Text)
rptParam1(8) = New Microsoft.Reporting.WinForms.ReportParameter("rptSubTotal", poCustom.Label25.Text)
rptParam1(9) = New Microsoft.Reporting.WinForms.ReportParameter("rptVAT", poCustom.Label26.Text)
rptParam1(10) = New Microsoft.Reporting.WinForms.ReportParameter("rptTotalAmount", poCustom.Label27.Text)
rptParam1(11) = New Microsoft.Reporting.WinForms.ReportParameter("rptRequest", poCustom.Label30.Text)
ReportViewer1.LocalReport.SetParameters(rptParam1)
Me.ReportViewer1.RefreshReport()
TextBox1.Text = poCustom.CompanyName.Text
End Sub
Which happens to work without using MDI Forms. I would like to know the cause of the problem for future use. Thank you in advance!
You are using two different instances of poCustom. ch is the first, and you populate its textboxes. But on the rptPOView2_Load event, you are using the other instance, which contains textboxes that has no value yet. One way to fix the problem is to use poCustom itself and not ch.
poCustom.TopLevel = False
poCustom.Visible = True
poCustom.StartPosition = FormStartPosition.Manual
Dim leftStart As Integer = 1220 - (ch.Width + (SystemInformation.Border3DSize.Width * 2))
Dim topStart As Integer = 670 - (ch.Height + (SystemInformation.Border3DSize.Height * 2))
poCustom.Location = New Point(leftStart, topStart)
GroupBox1.Controls.Add(poCustom)