Dim cont = 0
If ListBox1.Items.Count > 0 Then
For i =1 To ListBox1.Items.Count
Dim botao3 As New Button
botao3.Text = CStr(ListBox2.Items(cont)) 'table.Item(i).text &
botao3.BringToFront()
botao3.Top = top
botao3.Left = 40
botao3.Width = 300
Me.Controls.Add(botao3)
top = top + 30
cont = cont + 1
Next
End If
ps. my listbox has the sorted propriety set to true
this its my code but it will only give it the name of the last inserted value on the listbox .
how can i make this so that when ever i click the button it deletes the old set of buttons and add a new set of button the one i have just inserted.
and please give me a hand :$
You put 0 instead of the current loop value
botao3.Text = CStr(ListBox2.Items(0))
should be
botao3.Text = CStr(ListBox2.Items(i))
For the other part, I am not sure what you want to achieve but you can have Me.Controls.Clear() before your loop.
try that:
If ListBox1.Items.Count > 0 Then
For i =0 To ListBox1.Items.Count
Dim botao3 As New Button
botao3.Text = CStr(ListBox1.Items(i)) 'table.Item(i).text &
botao3.BringToFront()
botao3.Top = top
botao3.Left = 40
botao3.Width = 300
Me.Controls.Add(botao3)
top = top + 30
Next
End If
use this:
Dim btn As Button() = New Button(ListBox1.Items.Count - 1) {}
For i As Integer = 0 To ListBox1.Items.Count - 1
btn(i) = New Button()
btn(i).Text = ListBox1.Items(i).ToString()
If i > 0 Then
btn(i).Left = btn(i - 1).Right
End If
Me.Controls.Add(btn(i))
Next
result:
Related
I have a folder called
App.Path & "\Images"
Inside of it I have 5 Images and in my Form I have also 5 Pictureboxes. Now my question is, How can I display them all one PictureBox per Image at a time? heres is my code so far
Picture1.Picture = LoadPicture("Path")
Heres what I've done so far
Dim c As Control
Dim ImageLink As String
With vs1
For Each c In Form1
For i = 1 To .Rows - 1
If Len(ImageLink) > 0 Then ImageLink = ImageLink
Debug.Print c.Picture
Debug.Print .TextMatrix(i, .ColIndex("Image"))
MsgBox .TextMatrix(i, .ColIndex("Image"))
c.Picture = LoadPicture("C:\Users\paul\Desktop\Gondola Monitoring System\Image\" & .TextMatrix(i, .ColIndex("Image")))
Next
Next
End With
Form1.Show
I try to write the filename in flexgrid and call it in each control.
TYSM for help
Picture1.Picture = LoadPicture(App.Path & "\Images\file1.jpg")
Picture2.Picture = LoadPicture(App.Path & "\Images\file2.jpg")
Picture3.Picture = LoadPicture(App.Path & "\Images\file3.jpg")
Picture4.Picture = LoadPicture(App.Path & "\Images\file4.jpg")
Picture5.Picture = LoadPicture(App.Path & "\Images\file5.jpg")
If this doesn't provide you with what you need, please provide more details on your requirements.
EDIT
Your code isn't going to work. You are looping over all the controls, which will include any buttons, labels, etc, in addition to your picture controls, and for each control you are looping through all the rows of your grid. One better approach would be to define the picture controls as an array (starting index from 1 to match your grid for loop), then the for index is used so that the grid rows and picture indexes match. Something like this:
With vs1
For i = 1 To .Rows - 1
Picture1(i).Picture = LoadPicture("C:\Users\paul\Desktop\Gondola Monitoring System\Image\" & .TextMatrix(i, .ColIndex("Image")))
Next
End With
I need to have a graphics window that displays a message over and over again as a user clicks a button. I have looked all over the internet for instructions on how to not make it overlap. This is most likely a quick fix but idk. Plz help here is my code. I am trying to make a clicker game but haulted as this issue happened.
GraphicsWindow.Height = 420
GraphicsWindow.Width = 720
GraphicsWindow.CanResize = "1"
button = Controls.AddButton("Click for eggs",200,200)
Controls.SetSize(button,100,100)
eggs = 0
Controls.ButtonClicked = buttonClicked
Sub buttonClicked
lastButtonClicked = Controls.LastClickedButton
If lastButtonClicked = button Then
eggs = eggs + 1
GraphicsWindow.DrawText(0,0,"You have " + eggs + " eggs")
ElseIf eggs >= 1 Then
GraphicsWindow.BackgroundColor = "White"
GraphicsWindow.DrawText(0,0,"You have " + eggs + " eggs")
EndIf
EndSub
As far as I know, this exact effect isn't possible in Small Basic, because things drawn to the GraphicsWindow can't be edited or removed without clearing the entire window.
Instead, I would use a TextBox from Controls, which can be edited after they've been created. Because the TextBox can normally be edited by the user, I've also added code to prevent the content from being edited.
See my comments in the code for more about how this works.
GraphicsWindow.Height = 420
GraphicsWindow.Width = 720
GraphicsWindow.CanResize = "1"
button = Controls.AddButton("Click for eggs",200,200)
Controls.SetSize(button,100,100)
eggs = 0
Controls.ButtonClicked = buttonClicked
' Create a text box to show the egg count
myTextBox = Controls.AddTextBox(0, 0)
' Ensure the user can't edit its contents by resetting the text if it changes
Controls.TextTyped = updateEggs
Sub updateEggs
' Change the text of myTextBox
Controls.SetTextBoxText(myTextBox, "You have " + eggs + " eggs")
EndSub
Sub buttonClicked
lastButtonClicked = Controls.LastClickedButton
If lastButtonClicked = button Then
eggs = eggs + 1
updateEggs()
ElseIf eggs >= 1 Then
GraphicsWindow.BackgroundColor = "White"
updateEggs()
EndIf
EndSub
This GIF demonstrates how the TextBox looks and works, as well as how the text cannot be changed:
All you have to do is use Shapes.AddText. This will create a text shape that can be modified with Shapes.SetText
Example:
GraphicsWindow.Height = 420
GraphicsWindow.Width = 720
GraphicsWindow.CanResize = "1"
Text = Shapes.AddText("You have 0 eggs")
button = Controls.AddButton("Click for eggs",200,200)
Controls.SetSize(button,100,100)
eggs = 0
Controls.ButtonClicked = buttonClicked
Sub buttonClicked
lastButtonClicked = Controls.LastClickedButton
If lastButtonClicked = button Then
eggs = eggs + 1
Shapes.SetText(Text,"You have " + eggs + " eggs")
EndIf
EndSub
Refering to Change background color of listview in vb6
I tried this example and does not work as in I see no coloured rows.
I have a command button on my form that loads listview items then once that is finished I call the routine to setup the colour.
I made my picture box visible to see the expected outcome and it is as expected. So effectively setting the ListView's Picture property to the PictureBox's Image property is doing nothing for me.
Anyhow this is my code:
'pbxBG.Visible = True
If lsvPersonalisation.ListItems.Count <> 0 Then
pbxBG.Width = lsvPersonalisation.Width
pbxBG.Height = lsvPersonalisation.ListItems(1).Height * (lsvPersonalisation.ListItems.Count)
pbxBG.ScaleHeight = lsvPersonalisation.ListItems.Count
pbxBG.ScaleWidth = 1
pbxBG.DrawWidth = 1
pbxBG.Cls
Dim i As Integer
For i = 1 To lsvPersonalisation.ListItems.Count
If lsvPersonalisation.ListItems(i).Tag = "1" Then
pbxBG.Line (0, i - 1)-(1, i), &H80FFFF, BF
Else
pbxBG.Line (0, i - 1)-(1, i), &HFFFFFF, BF
End If
Next i
Else
pbxBG.Cls
End If
lsvPersonalisation.Picture = pbxBG.Image
'pbxBG.Visible = False
When I try to google it for 3 days, I found that there is only 1 picture/image available in 1 picbox. My goal is to display multiple images, and they cannot overlap. If they overlap, there a red colour should be shown.
I'm using VB6. I'm using 1 combobox1, for select image n 1 commandbutoon. but when I select 2nd image in click button, the image on picbox will auto overwrite it. Is it caused by .cls ??
Private Sub Combo1_Click()
Dim pin As String
Dim intx As Integer
If UCase$(Combo1.List(intx)) = UCase$(pin) Then
Combo1.ListIndex = intx
End If
End Sub
Private Sub Command1_Click()
If Combo1.ListIndex = 0 Then
Set mPic = pin8.Image
ElseIf Combo1.ListIndex = 1 Then
Set mPic = pin12.Image
Else
Set mPic = pin16.Image
End If
mPicWidth = Me.ScaleX(mPic.Width, vbHimetric, Picture1.ScaleMode)
mPicHeight = Me.ScaleY(mPic.Height, vbHimetric, Picture1.ScaleMode)
ShowPictureAtPosition mLeft, mTop
End Sub
Thank you.
Best regard,
chan
Look, The only way to do that is to add 2 images as resources in the project then make one is the default picture or leave it blank as you wish.
The process now is when you click on the command button you switch between the two pictures.
Button Code:
if
PictureBox1.Image = My.Resources.<Name_of_res_file>.<Name_of_image1111_resource>
Then
PictureBox1.Image = My.Resources.<Name_of_res_file>.<Name_of_image2222_resource>
Else
PictureBox1.Image = My.Resources.<Name_of_res_file>.<Name_of_image1111_resource>
End If
This will switch between the 2 pictures. Hope this helps you.
I'm having a problem in editing the width of my datagridview. It doesn't changed the width. Here's my source code.
oDotNet.SqlDb.strCommand = "SELECT TOP 1 ItemCode, ItemName FROM [" & oAPP.oSQLDatabase & "]..OITM"
dgMain.DataSource = oDotNet.SqlDb.Ds.Tables(0).DefaultView
Dim oTableStyle As New DataGridTableStyle
oTableStyle.MappingName = oDotNet.SqlDb.Ds.Tables(0).DefaultView.GetType().Name
Dim oTextBoxColumn As New DataGridTextBoxColumn
oTextBoxColumn.Width = 400
oTextBoxColumn.MappingName = "ItemName"
oTextBoxColumn.HeaderText = "ItemName"
oTableStyle.GridColumnStyles.Add(oTextBoxColumn)
dgMain.TableStyles.Clear()
dgMain.TableStyles.Add(oTableStyle)
Regards
Remove below line and execute it works:
oTableStyle.MappingName = oDotNet.SqlDb.Ds.Tables(0).DefaultView.GetType().Name