Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 4.0 aka C# 2010 > BOOK: Stephens' C# Programming with Visual Studio 2010 24-Hour Trainer
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Stephens' C# Programming with Visual Studio 2010 24-Hour Trainer
This is the forum to discuss the Wrox book Stephens' C# Programming with Visual Studio 2010 24-Hour Trainer by Rod Stephens; ISBN: 9780470596906
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Stephens' C# Programming with Visual Studio 2010 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
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 22nd, 2012, 08:10 PM
Authorized User
Points: 130, Level: 2
Points: 130, Level: 2 Points: 130, Level: 2 Points: 130, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2012
Location: Australia
Posts: 32
Thanks: 1
Thanked 0 Times in 0 Posts
Post How do I use .Checked with 3 items (Lesson 6/2)

In Lesson 6 exercise 2 I have to add code for the menu bar, context menu and toolbar buttons and I want to make them check on and off no matter which one is clicked.

Previously in Lesson 5 Ex 5 I had to make it so the bullet item checked and unchecked. I got that working ok as below:

Code:
private void bulletToolStripMenuItem_Click(object sender, EventArgs e)
{
bulletContextMenu.Checked = bulletToolStripMenuItem.Checked;
}
and

Code:
private void bulletContextMenu_Click(object sender, EventArgs e)
{
bulletToolStripMenuItem.Checked = bulletContextMenu.Checked;
                     
}
Now that i am adding a third item, bulletButton, how do I make that work?

Do i add the new item within the existing code like:
Code:
bulletToolStripMenuItem.Checked = bulletButton.checked = bulletContextMenu.Checked;
or like this with the item clicked last:

Code:
bulletToolStripMenuItem.Checked = bulletContextMenu.Checked;
bulletButton.Checked = bulletContextMenu.Checked;
Or is it something else entirely?
__________________
"These pretzels are making me thirsty"
  #2 (permalink)  
Old October 23rd, 2012, 02:32 AM
Authorized User
Points: 130, Level: 2
Points: 130, Level: 2 Points: 130, Level: 2 Points: 130, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2012
Location: Australia
Posts: 32
Thanks: 1
Thanked 0 Times in 0 Posts
Default Further Information

I have tried using the following code for the menubar item and context menu item. When i click either in the menu or context menu, all items including the toolbar button (bulletButton) are checked. I can check and uncheck with the menu and context menu selection, but not the toolbar button.

Code:
private void bulletToolStripMenuItem_Click(object sender, EventArgs e)
        {
                   
            bulletButton.Checked = bulletContextMenu.Checked = bulletToolStripMenuItem.Checked;
                       
        }
And

Code:
private void bulletContextMenu_Click(object sender, EventArgs e)
        {
           
            bulletButton.Checked = bulletToolStripMenuItem.Checked = bulletContextMenu.Checked;
            
        }
When i add the following code to the bulletButton click, it does nothing. It wont check the button on the toolbar, menu or context menu.

Code:
private void bulletButton_Click(object sender, EventArgs e)
        {
           
           bulletContextMenu.Checked = bulletToolStripMenuItem.Checked = bulletButton.Checked;
           
        }
The code is effectively the same, but it doesnt work. Clicking the toolbar button wont check anything. Not sure whats up
__________________
"These pretzels are making me thirsty"
  #3 (permalink)  
Old October 23rd, 2012, 11:41 AM
Rod Stephens's Avatar
Wrox Author
Points: 3,166, Level: 23
Points: 3,166, Level: 23 Points: 3,166, Level: 23 Points: 3,166, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2006
Location: , , .
Posts: 647
Thanks: 2
Thanked 96 Times in 95 Posts
Default

Code:
bulletButton.Checked = bulletContextMenu.Checked = bulletToolStripMenuItem.Checked;
This code probably isn't doing what you think it is doing. The Checked property is a Boolean so it can take the values True and False.

What this code is doing is setting bulletButton.Checked equal to True if bulletContextMenu.Checked = bulletToolStripMenuItem.Checked is true, i.e. if bulletContextMenu.Checked and bulletToolStripMenuItem.Checked have the same value.

Here's the way I handled this:

Code:
    Private Sub mnuFormatBullet_Click() Handles mnuFormatBullet.Click
        ctxBullet.Checked = mnuFormatBullet.Checked
        btnBullet.Checked = mnuFormatBullet.Checked

        MessageBox.Show("Bullet")
    End Sub
    Private Sub ctxBullet_Click() Handles ctxBullet.Click
        mnuFormatBullet.Checked = ctxBullet.Checked
        btnBullet.Checked = ctxBullet.Checked

        MessageBox.Show("Context Bullet")
    End Sub
When you click the Format menu's Bullet command, that menu item automatically checks or unchecks itself (because its CheckOnClick property is True). Its event handler makes the ContextMenu and Toolbar button's Checked properties match the menu item's Checked property so they all show the same value.

The ContextMenu's Bullet item works similarly. When you click it, it automatically checks or unchecks. Its event handler then sets the menu item's and toolbar button's Checked property to match the ContextMenu item's Checked property.

Post a followup and let me know if you need more help. (You can also download the sample code to see how I handled other requirements in the exercises.)
__________________
Rod

Rod Stephens, Microsoft MVP

Essential Algorithms: A Practical Approach to Computer Algorithms

(Please post reviews at Amazon or wherever you shop!)
  #4 (permalink)  
Old October 23rd, 2012, 08:07 PM
Authorized User
Points: 130, Level: 2
Points: 130, Level: 2 Points: 130, Level: 2 Points: 130, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2012
Location: Australia
Posts: 32
Thanks: 1
Thanked 0 Times in 0 Posts
Default Almost

Thanks for your help. I had tried this code earlier and it partially worked.

When i click the bullets in the format menu, it checks the button, menu and context menu.

When i click the bullets in the context menu, it checks the button, menu and context menu.

However, when i add the code for the toolbar button, nothing is checked.

Code:
private void bulletToolStripMenuItem_Click(object sender, EventArgs e)
        {
                                 
            bulletContextMenu.Checked = bulletToolStripMenuItem.Checked;
            bulletButton.Checked = bulletToolStripMenuItem.Checked;
           
        }

        private void bulletContextMenu_Click(object sender, EventArgs e)
        {
            

            bulletToolStripMenuItem.Checked = bulletContextMenu.Checked;
            bulletButton.Checked = bulletContextMenu.Checked;
            
        }

        private void bulletButton_Click(object sender, EventArgs e)
        {
            //DOESNT WORK - wont check or uncheck when clicked. Wont check others when clicked.

            bulletToolStripMenuItem.Checked = bulletButton.Checked;
            bulletContextMenu.Checked = bulletButton.Checked;

        }
I did look at L8 ex1 and the only difference i saw was the code below in the format menu bullet code.

Code:
contentRichTextBox.SelectionBullet = bulletButton.Checked;
I am starting on Lesson 7 about using richtext boxes today so I will see if it makes the difference after that.
__________________
"These pretzels are making me thirsty"
  #5 (permalink)  
Old October 24th, 2012, 11:53 AM
Rod Stephens's Avatar
Wrox Author
Points: 3,166, Level: 23
Points: 3,166, Level: 23 Points: 3,166, Level: 23 Points: 3,166, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2006
Location: , , .
Posts: 647
Thanks: 2
Thanked 96 Times in 95 Posts
Default

Quote:
I did look at L8 ex1 and the only difference i saw was the code below in the format menu bullet code.
Any time you compare someone else's code to yours and you don't see a significant difference, but you see a difference in result, then you should suspect that there's a property set on the form at design time that is different. You wouldn't see that in the code.

(This is a tricky issue when writing a book. I don't want to make a table listing every tiny little change I made in the Windows Form Designer because it takes up a huge amount of space and doesn't give you all that much information, although I've seen books that do this. But then you risk missing that one critical thing like setting a ContextMenu property or an event handler.)

Quote:
However, when i add the code for the toolbar button, nothing is checked.
Try using the Properties window's Events display to verify that the toolbar button's Click event is wired up to the event handler. If that's not the issue, let me know.
__________________
Rod

Rod Stephens, Microsoft MVP

Essential Algorithms: A Practical Approach to Computer Algorithms

(Please post reviews at Amazon or wherever you shop!)
  #6 (permalink)  
Old October 24th, 2012, 07:19 PM
Authorized User
Points: 130, Level: 2
Points: 130, Level: 2 Points: 130, Level: 2 Points: 130, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2012
Location: Australia
Posts: 32
Thanks: 1
Thanked 0 Times in 0 Posts
Default Working now

Thanks for your replies.

I tried publishing the program and the toolbar button now turns on when the other ones are selected.

It doesnt turn off though, but i suspect this might be covered in a later topic.

Thanks
__________________
"These pretzels are making me thirsty"
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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
Checkbox checked all mateenmohd Javascript 1 January 2nd, 2007 06:19 AM
Checkbox checked? ninel ASP.NET 2.0 Professional 1 April 12th, 2006 10:50 PM
how to view the checked items after navigating madhusrp C# 1 January 24th, 2006 03:28 PM
allow only one checkbox to be checked! morpheus HTML Code Clinic 5 April 15th, 2004 10:59 AM
displaying 6 items only having 20 items Lakshmi KS VB Components 1 February 17th, 2004 10:34 AM



All times are GMT -4. The time now is 12:00 PM.


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