![]() |
Languages »
C# »
Beginners
Intermediate
License: The Code Project Open License (CPOL)
Using Windows Components in Visual StudioBy Coder24.comUsing some Windows components from the toolbox |
C#WinXP, VistaVS2005, Architect
|
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||
We are going to discuss and test to use some of the Windows® components.
The performance counter is a Windows® component which is communicating with the Windows® own performance counter (See Figure A).
The performance counter helps users to get total performance information about their computer.
Let’s test the performance counter component in Visual Studio® 2005.
Add a performanceCounter component.
Set your PerformanceCounter properties as follows (See Figure B).

Add a GroupBox, a Label, a timer and a progressbar.
Double-click on the timer and add the following code:
progressBar1.Value = (int)(performanceCounter1.NextValue());
label1.Text = "CPU-Usage: " +
progressBar1.Value.ToString()+ "%";
Now build the project and test run it. The application must look like (See Figure C):

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:Add an errorprovider from the components in the toolbox.
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):

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, "");
}
Now debug and compile it.

You could use other codes like:
if(textbox1.text.trim().Length == 0)
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:
Add the helpProvider component.
Right-click on the form1 and select properties.
Change MaximizeBox to false and MinimizeBox to false.
Change the HelpButton to true.
Change Add a button with the following text: Click on the helpbutton and point the help cursor on me.
Right-click on button1 and navigate to the end of its properties panel, change the ShowHelp on HelpProvider to true.
Next, enter some custom help text in the HelpString on helpProvider.
Before we compile and build the application, please check if the application looks like (See Figure F):

Now build and run it.

HelpButton, if we want to test our help provider, we need the HelpButton available.We hope you might learn something.
| You must Sign In to use this message board. | ||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 23 Jul 2008 Editor: Sean Ewington |
Copyright 2008 by Coder24.com Everything else Copyright © CodeProject, 1999-2009 Web22 | Advertise on the Code Project |