Reputation: 139
I've recently started learning VB.Net in Visual Studio 2010 for a side project, but I've become completely stuck. All I want to do is simply draw a picture, then draw text on top of it.
This is the code that I have so far...
Dim allFolders As String() = Directory.GetDirectories("C:\Project\Test")
For Each item As String In allFolders
Dim newButton As New Button
newButton.Name = item
newButton.Width = folderW
newButton.Width = folderH
newButton.Left = folderX
newButton.Top = folderY
newButton.Image = My.Resources.Resources.grBtn
newButton.Text = newButton.Name.Remove(0, 17)
Me.Controls.Add(newButton)
AddHandler newButton.Click, AddressOf openMyFolder
folderX += folderXS
Next
If I set "Dim newButton As New Button" then it completely ignores the image and draws just the standard button... if I set "Dim newButton As New PictureBox" then it completely ignores the Text and only draws the image...
Surely there's some way that I can have both a picture and text?
Thank you for your time!
Thank you LarsTech! Anyone searching for a similar problem, the code I'm using is:
Dim newButton As New Button
newButton.Name = item
newButton.Width = folderW
newButton.Height = folderH
newButton.Left = folderX
newButton.Top = folderY
newButton.Image = My.Resources.Resources.<Your Image Resource>
newButton.FlatStyle = FlatStyle.Flat
newButton.FlatAppearance.BorderSize = 0
newButton.Text = newButton.Name.Remove(0, 17)
Me.Controls.Add(newButton)
AddHandler newButton.Click, AddressOf openMyFolder
folderX += folderXS
Which will create nice, dynamic picture buttons with no boarder.
Upvotes: 1
Views: 155
Reputation: 81610
Can't duplicate your issue entirely, but you aren't setting the Height property (you have Width twice).
Consider adding the following properties to show the image properly:
newButton.ImageAlign = ContentAlignment.MiddleCenter
newButton.TextAlign = ContentAlignment.MiddleCenter
newButton.TextImageRelation = TextImageRelation.ImageBeforeText
Upvotes: 3