Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 2005 > C# 2005
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
C# 2005 For discussion of Visual C# 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 2005 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #11 (permalink)  
Old March 21st, 2008, 02:58 AM
Authorized User
 
Join Date: Jul 2006
Location: Schiedam, zuid holland, Netherlands.
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi rob.

Im not using the fontdialog because in can only assign a font to a textbox. I only need the fontname. If i convert the font name to a string it will give me all font information. text height, format and so on. Plus the form thats is being displayed has to much information on it. Thats why i wanted to create my one form.

Greetz Mac

Reply With Quote
  #12 (permalink)  
Old March 21st, 2008, 04:54 AM
Friend of Wrox
 
Join Date: Mar 2007
Location: Hampshire, United Kingdom.
Posts: 432
Thanks: 0
Thanked 1 Time in 1 Post
Default

OK - This still begs the question as to why you dont just populate the ComboBox on your form with the font names and get the user to select it from there?

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>
Reply With Quote
  #13 (permalink)  
Old March 21st, 2008, 05:27 AM
Authorized User
 
Join Date: Jul 2006
Location: Schiedam, zuid holland, Netherlands.
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It's not my dicision.

The functional design of the program forces me to use sub forms like in the main program.

Reply With Quote
  #14 (permalink)  
Old March 21st, 2008, 05:47 AM
Friend of Wrox
 
Join Date: Mar 2007
Location: Hampshire, United Kingdom.
Posts: 432
Thanks: 0
Thanked 1 Time in 1 Post
Default

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>
Reply With Quote
  #15 (permalink)  
Old March 21st, 2008, 07:10 AM
Authorized User
 
Join Date: Jul 2006
Location: Schiedam, zuid holland, Netherlands.
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Rob

Thank you very much for your help. The community needs more people like you. Now i have seen the code. It helped me verry much.

Thanks again.

Greetz

MacDevv

Reply With Quote
  #16 (permalink)  
Old March 21st, 2008, 07:48 AM
Friend of Wrox
 
Join Date: Mar 2007
Location: Hampshire, United Kingdom.
Posts: 432
Thanks: 0
Thanked 1 Time in 1 Post
Default

MacDevv,

Your very welcome, happy to help.

Enjoy your Easter :)

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>
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting all listbox items Lucy_H85 C# 2005 2 December 1st, 2009 04:36 AM
unselecting items in a listbox Durkee VB.NET 2002/2003 Basics 9 October 8th, 2007 03:01 PM
UNSelect Items in ListBox mmcdonal Access VBA 7 June 21st, 2007 08:09 AM
Unhighlight Listbox Items selevanm Access VBA 1 March 7th, 2007 12:39 PM
Saving Listbox Items antonducabre VB.NET 2002/2003 Basics 1 July 16th, 2003 12:46 PM



All times are GMT -4. The time now is 03:25 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.