Wrox Programmer Forums
|
BOOK: Beginning C# 3.0 : An Introduction to Object Oriented Programming ISBN: 978-0-470-26129-3
This is the forum to discuss the Wrox book Beginning C# 3.0 : An Introduction to Object Oriented Programming by Jack Purdum; ISBN: 9780470261293
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning C# 3.0 : An Introduction to Object Oriented Programming ISBN: 978-0-470-26129-3 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 25th, 2009, 08:47 PM
Registered User
 
Join Date: Feb 2009
Posts: 4
Thanks: 2
Thanked 0 Times in 0 Posts
Default Efficient code for beginners....

Hi,

Can anyone please help me.

On page 58, the optional exercise is to create a <Clear> button that will clear all textboxes and place the cursor back to the first textbox ready for a new input.


Is there a way to clear the txtResult box/label?.....

...and is the following code the most efficient way of clearing the 2 input boxes and returning the cursor back to the first input box?

Code:
 
privatevoid btnClr_Click(object sender, EventArgs e)
{
txtOperand1.Clear();
txtOperand2.Clear();
txtOperand1.Focus();
 
}
 
Old February 26th, 2009, 03:16 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Hi Steve,
Without seeing the code you should be able to simply make the following calls to clear out the two controls that you noted:

csharp Code:
labelResult.Text = string.Empty;
textBoxResult.Clear();

Labels do not expose a Clear() method so you need to manually remove the text from its Text proprety.

AFAIK, the code provided is the most effecient way to clear our your controls. There are other ways to do it, of course, such as looping through the Form's Control collection, checking the type of control, and then prefrom some logic on it. IMHO maintaining / updating a form's state is one of the most mundane tasks a WinForms programmer can be charged to do.

hth.
-Doug
__________________
===============================================
Doug Parsons
Wrox online library: Wrox Books 24 x 7
Did someone here help you? Click on their post!
"Easy is the path to wisdom for those not blinded by themselves."
===============================================
The Following User Says Thank You to dparsons For This Useful Post:
stevemcd999 (February 27th, 2009)
 
Old February 27th, 2009, 06:56 AM
Registered User
 
Join Date: Feb 2009
Posts: 4
Thanks: 2
Thanked 0 Times in 0 Posts
Default

thanks again for your help.

Steve





Similar Threads
Thread Thread Starter Forum Replies Last Post
Most efficient way to insert text into a file StumblingInTheDark Visual Basic 2005 Basics 1 February 22nd, 2007 01:09 PM
Most efficient overriding technique jcsdeveloper C# 4 December 7th, 2005 04:18 PM
Efficient implementation of multidimensional array Utwig C# 2 October 26th, 2004 04:34 AM
Database search - more efficient way? SoC Classic ASP Basics 4 August 15th, 2004 08:56 PM
Paging Again Still Not Efficient alyeng2000 ASP.NET 1.0 and 1.1 Basics 0 March 4th, 2004 08:36 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.