For Programmers: Free Programming Magazines  


Home > Archive > Visual Studio > March 2005 > simple ListBox1









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author simple ListBox1
Henni Laurila

2005-03-19, 8:57 pm

could someone point the way and tell me what I'm missing here (first
project, ever)

1.setup vs2005 enterprise
2.new vb windows application project
3.added a listbox1 and added this code which compiles fine, no errors but
nothing displays in listbox1

Public Class Form1

Sub SetUpListBox()
ListBox1.DrawMode = DrawMode.OwnerDrawVariable
For Each aFont As FontFamily In
FontFamily.GetFamilies(Me.CreateGraphics)
ListBox1.Items.Add(aFont.Name)
Next
End Sub


End Class


Steve Easton

2005-03-20, 3:58 am

Any particular reason you aren't using a FontDialog??

--
Steve Easton
Microsoft MVP FrontPage
95isalive
This site is best viewed............
........................with a computer

"Henni Laurila" <hlaur@extremetech.com> wrote in message news:3a3g27F66vlm2U1@individual.net...
> could someone point the way and tell me what I'm missing here (first
> project, ever)
>
> 1.setup vs2005 enterprise
> 2.new vb windows application project
> 3.added a listbox1 and added this code which compiles fine, no errors but
> nothing displays in listbox1
>
> Public Class Form1
>
> Sub SetUpListBox()
> ListBox1.DrawMode = DrawMode.OwnerDrawVariable
> For Each aFont As FontFamily In
> FontFamily.GetFamilies(Me.CreateGraphics)
> ListBox1.Items.Add(aFont.Name)
> Next
> End Sub
>
>
> End Class
>
>



Henni Laurila

2005-03-20, 8:57 pm

Steve Easton wrote:
> Any particular reason you aren't using a FontDialog??


I don't know how to respond as I don't understand your question
All I wanted to do, as my 1st project was to display some data in a listbox
Steve Easton

2005-03-21, 3:57 am

I'm not sure what you are trying to load / display in your listbox.

--
Steve Easton
Microsoft MVP FrontPage
95isalive
This site is best viewed............
........................with a computer

"Henni Laurila" <hlaur@extremetech.com> wrote in message news:3a68tuF67ll84U1@individual.net...
> Steve Easton wrote:
>
> I don't know how to respond as I don't understand your question
> All I wanted to do, as my 1st project was to display some data in a listbox



Henni Laurila

2005-03-21, 3:57 am

Steve Easton wrote:
> I'm not sure what you are trying to load / display in your listbox.


well, yes, I certainly understand the entire 6 lines are overwhelming in complexity


the sample I posted simply adds a list of font names, yet, once the form shows the
listbox is empty
perhaps there is a method to invoke "Call SetUpListBox()" ?


Steve Easton

2005-03-21, 8:58 pm

Since the six lines don't reference any kind of datasource or databinding it's a little difficult to
relate listing a set of fonts into a "Listbox."

Do these six lines make sense to you??

Dim OFD3 As New OpenFileDialog
OFD3.Title = "Click once on the file to Unlock, then click Open"
OFD3.InitialDirectory = "%UserProfile%\Desktop"
OFD3.Filter = "Encrypted files (*.asc)|*.asc|All files (*.*)|*.*"
OFD3.RestoreDirectory = True
Dim result3 As DialogResult = OFD3.ShowDialog()


That said, if you want to list the fonts on the machine there is a built in "dialog" in VS called a
FontDialog which is designed to do exactly what you want.

Assuming you have created a "form" as the start of your project, mouse over the Toolbox and look for
FontDialog. If found click it and then add it to your form. ( It will actually move below your
form, as it is called as a seperate Dialog when used )

If not listed, right click the Windows Forms portion of the ToolBox and select Add/Remove items and
then Add "FontDialog" to the list.

You can also program it as a button event when a button is clicked.
But you need to create a Button control, a TextBox control, and a FontDialog component by
dimensioning varibles and then using them in the button event.

Have you tried searching MSDN for "FontDialog" ??

--
Steve Easton
Microsoft MVP FrontPage
95isalive
This site is best viewed............
........................with a computer

"Henni Laurila" <hlaur@extremetech.com> wrote in message news:3a74e4F6a076sU1@individual.net...
> Steve Easton wrote:
>
> well, yes, I certainly understand the entire 6 lines are overwhelming in complexity
>
>
> the sample I posted simply adds a list of font names, yet, once the form shows the
> listbox is empty
> perhaps there is a method to invoke "Call SetUpListBox()" ?
>
>



Mythran

2005-03-21, 8:58 pm


"Henni Laurila" <hlaur@extremetech.com> wrote in message
news:3a3g27F66vlm2U1@individual.net...
> could someone point the way and tell me what I'm missing here (first
> project, ever)
>
> 1.setup vs2005 enterprise
> 2.new vb windows application project
> 3.added a listbox1 and added this code which compiles fine, no errors but
> nothing displays in listbox1
>
> Public Class Form1
>
> Sub SetUpListBox()
> ListBox1.DrawMode = DrawMode.OwnerDrawVariable
> For Each aFont As FontFamily In
> FontFamily.GetFamilies(Me.CreateGraphics)
> ListBox1.Items.Add(aFont.Name)
> Next
> End Sub
>
>
> End Class
>
>


Public Class Form1
Sub SetUpListBox()
ListBox1.DrawMode = DrawMode.OwnerDrawVariable
For Each aFont As FontFamily In
FontFamily.GetFamilies(Me.CreateGraphics)
ListBox1.Items.Add(aFont.Name)
Next
End Sub

Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
Handles MyBase.Load
SetUpListBox()
End Sub
End Class


Hope this helps :)

Mythran


Henni Laurila

2005-03-22, 4:00 pm

Steve Easton wrote:
> Since the six lines don't reference any kind of datasource or databinding it's a
> little difficult to relate listing a set of fonts into a "Listbox."


ok, your example is way to complicated - let me attempt to simplify

all I wanted to do is to add to the default "windows application (vb project)" a
simple listbox and add some lines to it

so, in a pseudocode way of explaining it, I would be happy to just see
For x=1 to 10
Listbox1.Additem x
Next

...and when the form loads, see a list from 1 to 10

to make it even simpler, how about something like this (this compiles but shows
nothing in listbox)

Public Class Form1
Sub SetUpListBox()
ListBox1.Items.Add(1)
ListBox1.Items.Add(2)
End Sub
End Class


Henni Laurila

2005-03-22, 4:00 pm

Mythran wrote:
> Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
> Handles MyBase.Load
> SetUpListBox()
> End Sub
> End Class
> Hope this helps :)


yes, that was precisely what I wanted to know - you see I could not find anything in
the MSDN help about how to invoke the SetupListbox

thanks


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com