|
 Here is a complete sample to do what you need:
Imports System.Text
Imports System.Windows.Forms
Imports System.Drawing
Module FormMain
Public Sub Main()
Application.EnableVisualStyles()
Application.SetCompatibleTextRenderingDefault(False)
Application.Run(New LbForm)
End Sub
End Module
Public Class LbForm
Inherits System.Windows.Forms.Form
Private Sub InitializeComponent()
ListBox1 = New System.Windows.Forms.ListBox()
TextBox1 = New System.Windows.Forms.TextBox()
CopyBtn = New System.Windows.Forms.Button()
SuspendLayout()
ListBox1.Name = "ListBox1"
ListBox1.Location = New System.Drawing.Point(33, 44)
ListBox1.Size = New System.Drawing.Size(200, 200)
ListBox1.TabIndex = 0
ListBox1.FormattingEnabled = True
ListBox1.ItemHeight = 16
ListBox1.SelectionMode = System.Windows.Forms.SelectionMode.MultiSimple
ListBox1.Sorted = True
ListBox1.BorderStyle = BorderStyle.FixedSingle
ListBox1.DrawMode = DrawMode.OwnerDrawVariable
ListBox1.ClearSelected()
TextBox1.Name = "TextBox1"
TextBox1.Location = New System.Drawing.Point(253, 44)
TextBox1.Size = New System.Drawing.Size(200, 200)
TextBox1.TabIndex = 2
TextBox1.Multiline = True
CopyBtn.Name = "CopyBtn"
CopyBtn.Location = New System.Drawing.Point(206, 272)
CopyBtn.Size = New System.Drawing.Size(75, 23)
CopyBtn.TabIndex = 1
CopyBtn.Text = "Copy"
CopyBtn.UseVisualStyleBackColor = True
AutoScaleDimensions = New System.Drawing.SizeF(8.0!, 16.0!)
Font = New System.Drawing.Font("Calibri", 10.0)
AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Name = "LbForm"
ClientSize = New System.Drawing.Size(486, 314)
Controls.Add(ListBox1)
Controls.Add(TextBox1)
Controls.Add(CopyBtn)
Text = "ListBox Sample"
ResumeLayout(False)
PerformLayout()
End Sub
Private WithEvents ListBox1 As ListBox
Private WithEvents TextBox1 As TextBox
Private WithEvents CopyBtn As Button
Public Sub New()
InitializeComponent()
GetFileNames()
End Sub
Private Sub GetFileNames()
Dim openFileDialog1 As New OpenFileDialog()
openFileDialog1.InitialDirectory = ".\"
openFileDialog1.Filter = "VB.NET Files (*.vb)|*.vb|All files (*.*)|*.*"
openFileDialog1.FilterIndex = 1
openFileDialog1.Multiselect = True
If openFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
For Each fname in openFileDialog1.SafeFileNames
ListBox1.Items.Add(fname)
Next
End If
End Sub
Private Sub CopyBtn_Click(sender As Object, e As EventArgs) Handles CopyBtn.Click
Dim lblist As StringBuilder
lblist = New StringBuilder
For Each name As String In ListBox1.SelectedItems
lblist.AppendLine(name)
Next
ListBox1.ClearSelected()
TextBox1.Text = lblist.ToString()
End Sub
Private Sub ListBox1_DrawItem(ByVal sender As Object, _
ByVal e As DrawItemEventArgs) Handles ListBox1.DrawItem
If ((e.State And DrawItemState.Selected) = DrawItemState.Selected) Then
e.Graphics.FillRectangle(Brushes.Yellow, e.Bounds)
Else
e.Graphics.FillRectangle(Brushes.Beige, e.Bounds)
End If
e.Graphics.DrawRectangle(Pens.Blue, e.Bounds)
e.Graphics.DrawString(ListBox1.Items(e.Index), Me.Font, _
Brushes.Black, e.Bounds.X, e.Bounds.Y)
e.DrawFocusRectangle()
End Sub
Private Sub ListBox1_MeasureItem(ByVal sender As Object, _
ByVal e As MeasureItemEventArgs) Handles ListBox1.MeasureItem
e.ItemHeight += 5
End Sub
End Class
I took some of the code from the link to the MSDN documentation that I provided in an earlier message. The basic idea is that it gets a list of filenames and populates the ListBox with them. You can then test the selection of individual items, and how to process the resulting set.
|
|
|
|
|
~well...theres a lot of code here i do not need...i guess im gonna quit this highlight thing..i cannot make it work..Thanks anyway!
|
|
|
|
|
All you need to do is copy the code for the ListBox1_DrawItem subroutine, since that will work for any ListBox. But more importantly you should work on actually understanding the code, rather than just using Copy and Paste, as I already suggested.
|
|
|
|
|
so..i used the code for draw item and it returns this error
System.ArgumentOutOfRangeException:
Nome do parâmetro: index
in this line
e.Graphics.DrawString(ListBox1.Items(e.Index), Me.Font, _
Brushes.Black, e.Bounds.X, e.Bounds.Y)
like i said i think is because im using an empty listbox...it does not finds the index
|
|
|
|
|
OK, I did not code for that. Just add the following at the beginning of the DrawItem subroutine:
If (e.Index < 0)
Exit Sub
End If
Just another example of why you need to understand the basics and not just rely on blindly using Copy & Paste.
|
|
|
|
|
It worked.. thanks..i now apply the same code to the combobox but the button for dropdown list seems to be different...is there a way to customize it?
|
|
|
|
|
Sorry, I don't understand what you mean.
|
|
|
|
|
The combobox dropdown button changes style when i set the draw mode to ownerdrawfixed/variable....i wish to know if there is a way to change its style or color? Thanks....
I do not remember these properties in Visual Basic 6...but i do not code since 2004
|
|
|
|
|
I don't know I am afraid. Maybe the documentation will help.
|
|
|
|
|
Ok thanks...is already good as it is
|
|
|
|
|
I would like to show you my app...but the forums do not allow images nor videos much less links to exe files....
|
|
|
|
|
Member Alienoiz wrote: but the forums do not allow images nor videos And for very good reasons. There is already far too much spam dumped here.
|
|
|
|
|
Well...i think the thing is complete...its an mp3 tagger..loads and saves the most common tags in mp3s..it has save and clear tags features...you can choose which tag you want to write...it also has a mass edit option and i added file operations like rename, copy, move and delete file!!
|
|
|
|
|
im using gray for my forecolor...but it seems it only displays gray color when i click the list item..is like they were hidden..if i click an item then the forecolor will be gray and the back highlight color red...else the items do not show gray color..
|
|
|
|
|
We have seen the suggestion of Richard ...
I would suggest that you now show us the code from your Listbox_DrawItem-Method and how it is called ...
|
|
|
|
|
Hi...i would like to implement the following code into all files of my listbox.
this is what im using but is not working...
Dim items = ListBox1.SelectedItems()
For Each items In ListBox1.SelectedItems()
If CheckBox1.Checked = True Then
myMp3.ID3v2Tag.Title = TextBox1.Text
myMp3.Write()
End If
Next
|
|
|
|
|
"It's not working" is the most useless problem description ever. It does not describe a problem whatsoever.
Without the code around what you posted, anyone giving an answer is just guessing at the cause.
So, here's a guess. You're not opening each MP3 file to write information to. You're just writing to the same object over and over again.
|
|
|
|
|
Well...the code does not returns any error...it just writes the properties into the first selected item of the listbox. if i select the 3 last items of the listbox...only the top one is changed..
|
|
|
|
|
this is the full code im using for this...
<pre> Dim items = ListBox1.SelectedItem()
For Each items In ListBox1.SelectedItems()
If CheckBox1.Checked = True Then
myMp3.ID3v2Tag.Title = TextBox1.Text
myMp3.Write()
End If
If CheckBox2.Checked = True Then
myMp3.ID3v2Tag.Artist = TextBox2.Text
myMp3.Write()
End If
If CheckBox3.Checked = True Then
myMp3.ID3v2Tag.Album = TextBox3.Text
myMp3.Write()
End If
If CheckBox4.Checked = True And TextBox4.Text <> "" Then
On Error Resume Next
myMp3.ID3v2Tag.Year = Short.Parse(TextBox4.Text)
myMp3.Write()
On Error Resume Next
End If
If CheckBox5.Checked = True And TextBox5.Text <> "" Then
myMp3.ID3v2Tag.TrackNum = Short.Parse(TextBox5.Text)
myMp3.Write()
On Error Resume Next
End If
If CheckBox6.Checked = True Then
myMp3.ID3v2Tag.Comments = TextBox6.Text
myMp3.Write()
End If
If CheckBox7.Checked = True Then
If ComboBox1.Text = "01 - User" Then
myMp3.ID3v2Tag.Genre = TextBox7.Text
myMp3.Write()
Else
myMp3.ID3v2Tag.Genre = ComboBox1.Text
myMp3.Write()
End If
End If
Next
|
|
|
|
|
If the ListBox contains your MP3 filepaths, you have to loop through the selected items in the ListBox.
For Each item in ListBox1.SelectedItems
Next
|
|
|
|
|
what do you mean by :
Create your MP3 object for the selected file here...
Sorry..im dumb..i might quit this project 
|
|
|
|
|
Member Alienoiz wrote: i might quit this project I suggest you do. There are far too many gaps in your understanding of the basics to make this a viable and successful project. What I would suggest is that you get yourself some good training materials on Visual Basic and the .NET framework; and I mean books or written tutorials, not Youtube videos.
|
|
|
|
|
Yes im going to quit just because i cannot make mass edit on my listbox and because you do not want to provide a code snippet to help me...lol...sure
|
|
|
|
|
We have all tried to help you. But the main problem is that you do not even understand the code you have, so whatever we have suggested you are still lost. That is why I gave you the suggestion in my previous message. If you do not understand the basics of any programming language, then posting questions here will largely be a waste of your time.
|
|
|
|
|
 Hey..i know im lame..but i have (and sorry for the exctensive code) written all this just using internet snippets and my own knowledge without asking for help to anyone...but...yes...i cannot solve the listbox mass edit..
anyway..thanks for replying...
<pre>Imports System.IO
Imports System.Net.Security
Imports System.Net.WebRequestMethods
Imports System.Runtime
Imports System.Security.Cryptography
Imports System.Windows.Forms.VisualStyles.VisualStyleElement
Imports HundredMilesSoftware.UltraID3Lib
Public Class Form1
Dim myMp3 As New UltraID3()
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If FolderBrowserDialog1.ShowDialog() = DialogResult.OK Then
ListBox1.Items.Clear()
Dim fileNames = My.Computer.FileSystem.GetFiles(FolderBrowserDialog1.SelectedPath, FileIO.SearchOption.SearchTopLevelOnly, "*.mp3")
For Each fileName As String In fileNames
Dim result As String = Path.GetFileName(fileName)
ListBox1.Items.Add(result)
Next
End If
Label1.Text = "Title :"
Label2.Text = "Artist :"
Label3.Text = "Album :"
Label4.Text = "Year :"
Label5.Text = "Track :"
Label6.Text = "Comment :"
Label7.Text = "Genre : "
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
ListBox1.Items.Clear()
If FolderBrowserDialog1.SelectedPath = "" Then
Dim r8 As DialogResult = MessageBox.Show(Me, "You need to load a folder.",
"Load Files", MessageBoxButtons.OK)
Else
Dim fileNames = My.Computer.FileSystem.GetFiles(FolderBrowserDialog1.SelectedPath, FileIO.SearchOption.SearchTopLevelOnly, "*.mp3")
For Each fileName As String In fileNames
Dim result As String = Path.GetFileName(fileName)
ListBox1.Items.Add(result)
Next
End If
Label1.Text = "Title :"
Label2.Text = "Artist :"
Label3.Text = "Album :"
Label4.Text = "Year :"
Label5.Text = "Track :"
Label6.Text = "Comment :"
Label7.Text = "Genre : "
End Sub
Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged
If ListBox1.SelectedItem = "" Then
On Error Resume Next
Else
myMp3.Read(FolderBrowserDialog1.SelectedPath & "\" & ListBox1.SelectedItem)
Label1.Text = "Title : " & myMp3.ID3v2Tag.Title
Label2.Text = "Artist : " & myMp3.ID3v2Tag.Artist
Label3.Text = "Album : " & myMp3.ID3v2Tag.Album
Label4.Text = "Year : " & myMp3.ID3v2Tag.Year.ToString
Label5.Text = "Track : " & myMp3.ID3v2Tag.TrackNum.ToString
Label6.Text = "Comment : " & myMp3.ID3v2Tag.Comments
Label7.Text = "Genre : " & myMp3.ID3v2Tag.Genre
On Error Resume Next
Dim pics = myMp3.ID3v2Tag.Frames.GetFrames(CommonMultipleInstanceID3v2FrameTypes.Picture)
PictureBox1.Image = CType(pics(0), ID3v2PictureFrame).Picture
End If
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
If ListBox1.SelectedItem = "" Then
Dim r8 As DialogResult = MessageBox.Show(Me, "No File Selected!",
"Select Files", MessageBoxButtons.OK)
Else
If CheckBox1.Checked = False And CheckBox2.Checked = False And CheckBox3.Checked = False And CheckBox4.Checked = False And CheckBox5.Checked = False And CheckBox6.Checked = False And CheckBox7.Checked = False And CheckBox8.Checked = False Then
Dim r8 As DialogResult = MessageBox.Show(Me, "Select a tag to enter!",
"Select Tags", MessageBoxButtons.OK)
Else
If CheckBox1.Checked = True Then
myMp3.ID3v2Tag.Title = TextBox1.Text
myMp3.Write()
End If
If CheckBox2.Checked = True Then
myMp3.ID3v2Tag.Artist = TextBox2.Text
myMp3.Write()
End If
If CheckBox3.Checked = True Then
myMp3.ID3v2Tag.Album = TextBox3.Text
myMp3.Write()
End If
If CheckBox4.Checked = True And TextBox4.Text <> "" Then
On Error Resume Next
myMp3.ID3v2Tag.Year = Short.Parse(TextBox4.Text)
myMp3.Write()
End If
If CheckBox5.Checked = True And TextBox5.Text <> "" Then
On Error Resume Next
myMp3.ID3v2Tag.TrackNum = Short.Parse(TextBox5.Text)
myMp3.Write()
End If
If CheckBox6.Checked = True Then
myMp3.ID3v2Tag.Comments = TextBox6.Text
myMp3.Write()
End If
If CheckBox7.Checked = True Then
If ComboBox1.Text = "01 - User" Then
myMp3.ID3v2Tag.Genre = TextBox7.Text
myMp3.Write()
Else
myMp3.ID3v2Tag.Genre = ComboBox1.Text
myMp3.Write()
End If
If CheckBox8.Checked = True Then
Dim AlbumArt As ID3v2PictureFrame = New ID3v23PictureFrame(System.Drawing.Bitmap.FromFile("E:\teste\img.jpg"), PictureTypes.CoverFront, "Attached picture", TextEncodingTypes.ISO88591)
AlbumArt.Picture = PictureBox1.Image
myMp3.ID3v2Tag.Frames.Add(AlbumArt)
myMp3.Write()
End If
End If
End If
Dim r9 As DialogResult = MessageBox.Show(Me, "Operation Complete!",
"Tagged Files!", MessageBoxButtons.OK)
End If
End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
ListBox1.Items.Clear()
End Sub
Private Sub TextBox5_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TextBox5.KeyPress
Dim ch As Char = e.KeyChar
If Not Char.IsDigit(ch) AndAlso Asc(ch) <> 8 Then
e.Handled = True
End If
End Sub
Private Sub TextBox4_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TextBox4.KeyPress
Dim ch As Char = e.KeyChar
If Not Char.IsDigit(ch) AndAlso Asc(ch) <> 8 Then
e.Handled = True
End If
End Sub
Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
On Error Resume Next
My.Computer.FileSystem.RenameFile(FolderBrowserDialog1.SelectedPath & "\" & ListBox1.SelectedItem, TextBox8.Text & ".mp3")
ListBox1.Items.Clear()
Dim Fils = My.Computer.FileSystem.GetFiles(FolderBrowserDialog1.SelectedPath, FileIO.SearchOption.SearchTopLevelOnly, "*.mp3")
For Each fil As String In Fils
Dim result As String = Path.GetFileName(fil)
ListBox1.Items.Add(result)
Next
End Sub
Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
On Error Resume Next
Dim FileName = ListBox1.SelectedItem
Dim FilePath = TextBox9.Text & "\" & FileName
If System.IO.File.Exists(FilePath) Then
Dim r9 As DialogResult = MessageBox.Show(Me, "File Exists!",
"Duplicated Files!", MessageBoxButtons.OK)
Else
My.Computer.FileSystem.MoveFile(FolderBrowserDialog1.SelectedPath & "\" & ListBox1.SelectedItem, TextBox9.Text & "\" & ListBox1.SelectedItem)
ListBox1.Items.Clear()
Dim fils2 = My.Computer.FileSystem.GetFiles(FolderBrowserDialog1.SelectedPath, FileIO.SearchOption.SearchTopLevelOnly, "*.mp3")
For Each fil3 As String In fils2
Dim result As String = Path.GetFileName(fil3)
ListBox1.Items.Add(result)
Next
End If
End Sub
Private Sub Button9_Click(sender As Object, e As EventArgs) Handles Button9.Click
If FolderBrowserDialog2.ShowDialog() = DialogResult.OK Then
TextBox9.Text = FolderBrowserDialog2.SelectedPath
End If
End Sub
Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
On Error Resume Next
Dim FileName = ListBox1.SelectedItem
Dim FilePath = TextBox10.Text & "\" & FileName
If System.IO.File.Exists(FilePath) Then
Dim r9 As DialogResult = MessageBox.Show(Me, "File Exists!",
"Duplicated Files!", MessageBoxButtons.OK)
Else
My.Computer.FileSystem.CopyFile(FolderBrowserDialog1.SelectedPath & "\" & ListBox1.SelectedItem, TextBox10.Text & "\" & ListBox1.SelectedItem, overwrite:=False)
ListBox1.Items.Clear()
Dim fils4 = My.Computer.FileSystem.GetFiles(FolderBrowserDialog1.SelectedPath, FileIO.SearchOption.SearchTopLevelOnly, "*.mp3")
For Each fil4 As String In fils4
Dim result As String = Path.GetFileName(fil4)
ListBox1.Items.Add(result)
Next
End If
End Sub
Private Sub Button10_Click(sender As Object, e As EventArgs) Handles Button10.Click
If FolderBrowserDialog3.ShowDialog() = DialogResult.OK Then
TextBox10.Text = FolderBrowserDialog3.SelectedPath
End If
End Sub
Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click
On Error Resume Next
My.Computer.FileSystem.DeleteFile(FolderBrowserDialog1.SelectedPath & "\" & ListBox1.SelectedItem)
ListBox1.Items.Clear()
Dim fils5 = My.Computer.FileSystem.GetFiles(FolderBrowserDialog1.SelectedPath, FileIO.SearchOption.SearchTopLevelOnly, "*.mp3")
For Each fil5 As String In fils5
Dim result As String = Path.GetFileName(fil5)
ListBox1.Items.Add(result)
Next
End Sub
Private Sub Button11_Click(sender As Object, e As EventArgs) Handles Button11.Click
Dim ofd As New OpenFileDialog
If ofd.ShowDialog = DialogResult.OK Then
If ofd.FileName <> String.Empty Then
Me.PictureBox1.Image = Bitmap.FromFile(ofd.FileName)
End If
End If
End Sub
Private Sub Button12_Click(sender As Object, e As EventArgs) Handles Button12.Click
For i As Integer = 0 To ListBox1.SelectedIndices.Count - 1
ListBox1.Items.RemoveAt(ListBox1.SelectedIndex)
Next
End Sub
Private Sub TextBox11_TextChanged(sender As Object, e As EventArgs) Handles TextBox11.TextChanged
If TextBox11.Text = "" Then
ListBox1.Items.Clear()
Dim fileNames = My.Computer.FileSystem.GetFiles(FolderBrowserDialog1.SelectedPath, FileIO.SearchOption.SearchTopLevelOnly, "*.mp3")
For Each fileName As String In fileNames
Dim result As String = Path.GetFileName(fileName)
ListBox1.Items.Add(result)
Next
Else
Dim items = From it In ListBox1.Items.Cast(Of Object)()
Where it.ToString().IndexOf(TextBox11.Text, StringComparison.CurrentCultureIgnoreCase) >= 0
Dim matchingItemList As List(Of Object) = items.ToList()
ListBox1.BeginUpdate()
ListBox1.Items.Clear()
For Each item In matchingItemList
ListBox1.Items.Add(item)
Next
ListBox1.EndUpdate()
End If
End Sub
Private Sub Button13_Click(sender As Object, e As EventArgs) Handles Button13.Click
If Button13.Text = "Mass Edit" Then
Button13.Text = "Single Edit"
Else
Button13.Text = "Mass Edit"
End If
If Button5.Enabled = True Then
Button5.Enabled = False
Else
Button5.Enabled = True
End If
If Button6.Enabled = True Then
Button6.Enabled = False
Else
Button6.Enabled = True
End If
If Button7.Enabled = True Then
Button7.Enabled = False
Else
Button7.Enabled = True
End If
If Button8.Enabled = True Then
Button8.Enabled = False
Else
Button8.Enabled = True
End If
If ListBox1.SelectionMode = SelectionMode.One Then
ListBox1.SelectionMode = SelectionMode.MultiExtended
Else
ListBox1.SelectionMode = SelectionMode.One
End If
End Sub
End Class
|
|
|
|
|