Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Stephens' Visual Basic Programming 24-Hour Trainer
This is the forum to discuss the Wrox book Stephens' Visual Basic Programming 24-Hour Trainer by Rod Stephens; ISBN: 978-0-470-94335-9
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Stephens' Visual Basic Programming 24-Hour Trainer 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
  #1 (permalink)  
Old January 16th, 2013, 07:21 PM
Registered User
Points: 18, Level: 1
Points: 18, Level: 1 Points: 18, Level: 1 Points: 18, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2013
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Lesson 5 Try it

In the step-by-step explanation, for step 2 of the "create the main menu structure" paragraph, when I try to set the font sizes to 6, 9, 20 in the properties window, it changes the font size on the menu item itself. That is, the text on the Format->Font->Small menu item itself will immediately have a 6 pt font. This happens with the Color attribute if I try to set the ForeColor property (as in step 3) as well; however, if I code the ForeColor and the BackgroungColor in the handelers it works fine. Any idea as to what I might be doing wrong?


Edit: After downloading the code, I guess thats what its supposed to do. However, that begs the question: can it be coded so that the Small, Normal, and Large (Font) menu items are all the same size?

Last edited by TheMysticRuler; January 16th, 2013 at 07:51 PM.
Reply With Quote
  #2 (permalink)  
Old January 17th, 2013, 12:50 PM
Rod Stephens's Avatar
Wrox Author
Points: 2,999, Level: 22
Points: 2,999, Level: 22 Points: 2,999, Level: 22 Points: 2,999, Level: 22
Activity: 22%
Activity: 22% Activity: 22% Activity: 22%
 
Join Date: Jan 2006
Location: , , .
Posts: 601
Thanks: 1
Thanked 84 Times in 83 Posts
Default

Yes, that's what it's supposed to do. The idea is to give the user a sort of preview of what the fonts will look like if you pick a particular menu item.

Quote:
However, that begs the question: can it be coded so that the Small, Normal, and Large (Font) menu items are all the same size?
Just don't set the font size properties in the form designer. By default they'll all have the same size.

But later on page 63 in step 5 it uses the menu's font to set the TextBox's font so it displays the correct font. If you don't set the font in the menu items, then you need to get it from somewhere else.

You could put some other control on the form, perhaps a Label, set its font the way you want it, and then set its Visible property to False so the user doesn't see it. Then you can set the TextBox's font to that control's font as in:

Code:
txtContents.Font = lblSmallFont.Font
Most programmers would regard that as a sneaky trick. A more straightforward method would be to create a font in the menu's Click event handler like this:

Code:
txtContents.Font = New Font("Microsoft Sans Serif", 6)
This is the approach most programmers would take, although I think it uses techniques that haven't been covered in the book yet.

If you want, you can experiment with other parameters to the Font constructor like bold or other font names to see what happens.
__________________
Rod

Rod Stephens, Microsoft MVP

Essential Algorithms: A Practical Approach to Computer Algorithms

(Please post reviews at Amazon or wherever you shop!)
Reply With Quote
  #3 (permalink)  
Old January 17th, 2013, 10:15 PM
Registered User
Points: 18, Level: 1
Points: 18, Level: 1 Points: 18, Level: 1 Points: 18, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2013
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Step 5 of the Excercise section says "Make the Format->Bullet menu item and the Bullet context menu item check and uncheck each other.

The code given in the downloaded example is as follows:

Code:
       Private Sub mnuFormatBullet_Click() Handles mnuFormatBullet.Click
           ctxBullet.Checked = mnuFormatBullet.Checked
           MessageBox.Show("Bullet")
       End Sub

       Private Sub ctxBullet_Click() Handles ctxBullet.Click
            mnuFormatBullet.Checked = ctxBullet.Checked
            MessageBox.Show("Context Bullet")
       End Sub
I understand that were trying to have these items check and uncheck each other (have the same state), but where do they get "initialized"? That is, doesnt there have to be an initial state set such as
Code:
ctxBullet.Checked = True
before we can assign one value to another?

Last edited by TheMysticRuler; January 17th, 2013 at 10:18 PM.
Reply With Quote
  #4 (permalink)  
Old January 18th, 2013, 01:25 PM
Rod Stephens's Avatar
Wrox Author
Points: 2,999, Level: 22
Points: 2,999, Level: 22 Points: 2,999, Level: 22 Points: 2,999, Level: 22
Activity: 22%
Activity: 22% Activity: 22% Activity: 22%
 
Join Date: Jan 2006
Location: , , .
Posts: 601
Thanks: 1
Thanked 84 Times in 83 Posts
Default

Excellent question! It has to start somewhere!

In that program the Bullet menu items' CheckOnClick properties are true so then the user clicks one of them it automatically toggles its checked state. The Click event handler sees that change already made so it just updates the other menu item's Checked state to match.

For example, if neither is checked and the user selects the one in the main menu, here's the sequence of events:
  1. User selects mnuFormatBullet.
  2. mnuFormatBullet automatically checks itself.
  3. mnuFormatBullet's Click event handler fires and sets the ctxBullet's Checked property.

I hope that helps.
__________________
Rod

Rod Stephens, Microsoft MVP

Essential Algorithms: A Practical Approach to Computer Algorithms

(Please post reviews at Amazon or wherever you shop!)
Reply With Quote
  #5 (permalink)  
Old January 19th, 2013, 09:39 PM
Registered User
Points: 18, Level: 1
Points: 18, Level: 1 Points: 18, Level: 1 Points: 18, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2013
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by Rod Stephens View Post
Excellent question! It has to start somewhere!

In that program the Bullet menu items' CheckOnClick properties are true so then the user clicks one of them it automatically toggles its checked state. The Click event handler sees that change already made so it just updates the other menu item's Checked state to match.

For example, if neither is checked and the user selects the one in the main menu, here's the sequence of events:
  1. User selects mnuFormatBullet.
  2. mnuFormatBullet automatically checks itself.
  3. mnuFormatBullet's Click event handler fires and sets the ctxBullet's Checked property.

I hope that helps.
Both the mnuBullet and ctxBullet items (and from what I can see all of the menu items) Check On Click properties were set to false when I created them. Were they supposed to be set to true automatically upon creation, or is this something that I should change manually in their properties list?

Thank you kindly for all of your help
Reply With Quote
  #6 (permalink)  
Old January 20th, 2013, 09:48 AM
Rod Stephens's Avatar
Wrox Author
Points: 2,999, Level: 22
Points: 2,999, Level: 22 Points: 2,999, Level: 22 Points: 2,999, Level: 22
Activity: 22%
Activity: 22% Activity: 22% Activity: 22%
 
Join Date: Jan 2006
Location: , , .
Posts: 601
Thanks: 1
Thanked 84 Times in 83 Posts
Default

Yes, when you create a menu item its CheckOnClick property is off by default so you need to set it to true.

(I thought that was in the instructions for an earlier version of the program and then you copy that version to make this one, but I could be wrong. If so, sorry about that!)
__________________
Rod

Rod Stephens, Microsoft MVP

Essential Algorithms: A Practical Approach to Computer Algorithms

(Please post reviews at Amazon or wherever you shop!)
Reply With Quote
  #7 (permalink)  
Old January 20th, 2013, 03:52 PM
Registered User
Points: 18, Level: 1
Points: 18, Level: 1 Points: 18, Level: 1 Points: 18, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2013
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by Rod Stephens View Post
Yes, when you create a menu item its CheckOnClick property is off by default so you need to set it to true.

(I thought that was in the instructions for an earlier version of the program and then you copy that version to make this one, but I could be wrong. If so, sorry about that!)
Thanks Rod, as always your help is greatly appreciated.

Youre also 100% correct when you say that those instructions
were in fact in the book (top of page 66), so the mistake was
all mine. I must have missed that somehow...my apologies.
Reply With Quote
  #8 (permalink)  
Old January 20th, 2013, 07:16 PM
Rod Stephens's Avatar
Wrox Author
Points: 2,999, Level: 22
Points: 2,999, Level: 22 Points: 2,999, Level: 22 Points: 2,999, Level: 22
Activity: 22%
Activity: 22% Activity: 22% Activity: 22%
 
Join Date: Jan 2006
Location: , , .
Posts: 601
Thanks: 1
Thanked 84 Times in 83 Posts
Default

It's always a problem when you have an example that builds on itself for a long time. If you miss one instruction, you may get bit by it later. But long-building examples make the most interesting examples.

I guess the best strategy is if something isn't working like it should, post a note and I'll try to get you back on track as quickly as possible.
__________________
Rod

Rod Stephens, Microsoft MVP

Essential Algorithms: A Practical Approach to Computer Algorithms

(Please post reviews at Amazon or wherever you shop!)
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
Lesson 8 - Try It Femi Sonuga BOOK: Knight's Microsoft Business Intelligence 24-Hour Trainer 4 February 12th, 2012 07:44 AM
Lesson 7 Joakim BOOK: Stephens' C# Programming with Visual Studio 2010 24-Hour Trainer 1 November 30th, 2011 10:16 AM
Lesson 4 Femi Sonuga BOOK: Knight's Microsoft Business Intelligence 24-Hour Trainer 0 November 25th, 2011 09:25 AM
Lesson 9 MTMike BOOK: Knight's Microsoft Business Intelligence 24-Hour Trainer 3 November 3rd, 2011 01:51 PM
Lesson 8 sergeySE BOOK: Java Programming 24-Hour Trainer by Yakov Fain 1 June 29th, 2011 09:49 AM



All times are GMT -4. The time now is 02:29 PM.


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