Hi MacDevv,
OK, no problem. I have quickly knocked together some code (in 5 mins - sorry its scruffy!) and uploaded it to my SkyDrive for you, feel free to have a look and do with it what you will.
You can download the source from:
http://cid-47cc559ff82c1069.skydrive...meSelector.zip
Key points to note in the code are:
Main Form (Parent/Calling Form)
Code:
private void SelFontBtn_Click(object sender, EventArgs e)
{
FontSelFrm frm = new FontSelFrm();
frm.ShowDialog();
string selFont = frm.SelectedFont;
// if no item selected, keep the font name the same.
if (selFont != string.Empty)
{
FontSelLbl.Text = selFont;
}
}
Here we are calling the dialog and getting its result. But we only want to apply it if a value was actually selected.
Font Selection Form (FontSelFrm.cs)
Code:
private string GetSelectedFontName()
{
// Get the Value Selected in the List (base 0).
int idx = FontNameList.SelectedIndex;
// Try and use constants for magic numbers...
const int NOT_SELECTED = -1;
// ... Makes this a little more readable.
if (idx == NOT_SELECTED)
{
// No item selected, return string.Empty.
return string.Empty;
}
else
{
// Return the value selected in the list.
return FontNameList.Items[idx].ToString();
}
}
Here we are determining what item is selected in the ListBox. Everything else pretty much revolves around this.
Code:
private void FontNameList_DoubleClick(object sender, EventArgs e)
Code:
{
//snip: comments
string selFont = GetSelectedFontName();
if (selFont != string.Empty)
{
selectedFont = selFont;
this.Close();
}
}
private void FontNameList_SelectedIndexChanged(object sender, EventArgs e)
{
// item has been changed - we can
// enable the "Accept" button now.
AcceptBtn.Enabled = true;
}
Some "usability" enhancements, allow the user to double-click an item to select it, and disabling the "Accept" button until an item is selected.
NOTE: This code was written in Visual Studio 2008 Express
If you are unable to open the solution, then open the respective C# source files and use the code from there!
Hope this helps, as always, any questions, then please ask.
Rob
The Developing Developer
Currently Working Towards:
MCAD C#
My Blog: http://www.robzyc.spaces.live.com
<center>
"Nothing can stop the man with the right mental attitude from achieving his goal;
nothing on earth can help the man with the wrong mental attitude".
Thomas Jefferson</center>