Click here to Skip to main content
Licence CPOL
First Posted 21 Jun 2008
Views 25,354
Bookmarked 59 times

Using Windows Components in Visual Studio

By Coder24.com | 23 Jul 2008
Using some Windows components from the toolbox
1 vote, 5.9%
1

2
1 vote, 5.9%
3
2 votes, 11.8%
4
13 votes, 76.5%
5
4.60/5 - 17 votes
1 removed
μ 4.30, σa 1.92 [?]

Introduction

We are going to discuss and test to use some of the Windows® components.

Performance Counter

The performance counter is a Windows® component which is communicating with the Windows® own performance counter (See Figure A).

Click to enlarge

Figure A: The Windows® Vista Reliability and Performance Monitor have a Performance counter.

The performance counter helps users to get total performance information about their computer.

Let’s test the performance counter component in Visual Studio® 2005.

  1. Add a performanceCounter component.

  2. Set your PerformanceCounter properties as follows (See Figure B).

    23.jpg

    Figure B: Your settings or properties of the performance counter must look as they are in the image above.
  3. Add a GroupBox, a Label, a timer and a progressbar.

  4. Double-click on the timer and add the following code:

     progressBar1.Value = (int)(performanceCounter1.NextValue());
                label1.Text = "CPU-Usage: " +
                    progressBar1.Value.ToString()+ "%";
  5. Now build the project and test run it. The application must look like (See Figure C):

    24.gif

    Figure C: The simple CPU usage monitor application, using Windows® performance counter.

ErrorProvider

The error provider is used in user information fill forms, for example: we have a registration form and we have about five empty textboxes and two buttons, one with the text register and the other one with the text cancel. OK, now the user wants to register and he enters name, nick-name, e-mail, password and re-confirms his/her password. Now the user clicks on the register button and the button validates the information. Suddenly the nick-name which was entered is used by another user, and an error provider icon will popup and tell the user that he/she needs to enter another nick-name. So the error provider could be used to validate information.

Let’s add an error provider and test the functions:
  1. Add an errorprovider from the components in the toolbox.

  2. Next add four textboxes, one groupbox, four labels and one button and go to the textbox3 and textbox4, set the UseSystemPasswordChar to true. Your form must look like this (See Figure D):

    25.gif

    Figure D: Add these controls from the toolbox.
  3. Double–click on the button and add the following code:

    if (textBox1.Text == "")
                {
                    errorProvider1.SetError(textBox1, 
    			"You need to enter a nick-name");
                    
                }
                else
                {
                    errorProvider1.SetError(textBox1, "");
                }
                if (textBox2.Text == "")
                {
                    errorProvider1.SetError(textBox2, 
    			"You need to enter your real name");
                }
                else
                {
                        errorProvider1.SetError(textBox2, "");
                }
                if (textBox3.Text == "")
                {
                     errorProvider1.SetError
    		(textBox3, "Enter a valid password");
                }
                else
                {
                            errorProvider1.SetError(textBox3, "");
                }
                if (textBox4.Text == "")
                {
                    errorProvider1.SetError
    		(textBox4, "Re-enter a valid password");
                }
                else
                {
                    errorProvider1.SetError(textBox4, "");    
                }
  4. Now debug and compile it.

    26.gif

    Figure E: As we can see, I've just tested to enter a nick-name and password and I clicked on register and I've got the error provider information.

    You could use other codes like:

    if(textbox1.text.trim().Length == 0)

HelpProvider

The help provider is used to help the user. How does the help provider help the user? The help provider is helping the user like this. You could enter some lines of code and then compile and run the application. Next you could hit F1 and the helpprovider would display help information for that session.

Let’s test the help provider:

  1. Add the helpProvider component.

  2. Right-click on the form1 and select properties.

  3. Change MaximizeBox to false and MinimizeBox to false.

  4. Change the HelpButton to true.

  5. Change Add a button with the following text: Click on the helpbutton and point the help cursor on me.

  6. Right-click on button1 and navigate to the end of its properties panel, change the ShowHelp on HelpProvider to true.

  7. Next, enter some custom help text in the HelpString on helpProvider.

  8. Before we compile and build the application, please check if the application looks like (See Figure F):

    27.gif

    Figure F: Your form must look like this.
  9. Now build and run it.

    28.gif

    Figure G: You could very quickly see and understand why I've added the HelpButton, if we want to test our help provider, we need the HelpButton available.

We hope you might learn something.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Coder24.com

Architect
none
Sweden Sweden

Member
My name is Fisnik. I like programming and I am the owner of
the website http://www.coder24.com.
 
You can find me on MSDN Forums as well.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralMy vote of 5 Pinmemberpolczym7:19 5 Sep '10  
AnswerRe: My vote of 5 PinmemberCoder24.com23:24 27 Jan '11  
GeneralTnx! PinmemberYGeorge8:44 4 Feb '10  
GeneralRe: Tnx! PinmemberCoder24.com9:04 22 Aug '10  
GeneralVery helpful. Pinmemberthompsons14:25 22 Jun '08  
AnswerRe: Very helpful. PinmemberCode24.com23:11 22 Jun '08  
Great Thank you!!
 
Part 5 I hade submitted it but they deleted it because they didn't like it.
 
www.Coder24.com
QuestionYour comments are welcome PinmemberCode24.com23:43 21 Jun '08  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120210.1 | Last Updated 24 Jul 2008
Article Copyright 2008 by Coder24.com
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid