Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 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 June 17th, 2004, 12:30 AM
Registered User
 
Join Date: Jun 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Clearing TextBoxes

Hi ,

I'm new to CSharp,I would like to ask if the METHOD that I planning to develop is feasible.

I trying to develop a class that have a method to clear all the contents of all textbox in a certain "form".


For example:
When I call a method of a Class that clear all the contents of all Text Box in a certain form, it will empty all the textboxes of the form that I would like to.


using System.Windows.Forms;
namespace TestProject
{
    /// <summary>
   /// Summary description for Form1.
  /// </summary>
  public class CTestForm : System.Windows.Forms.Form
 {
   private System.Windows.Forms.TextBox txtUsername;
   private System.ComponentModel.Container
                             components = null;

    private void cmdClear_Click(object sender, System.EventArgs e)
     {
         /*The code below is the method that I want to
         Develop, that the funtionality of the method "ClearTextBox" is to clear all the contents of a textbox control in a certain form "FORM1".*/

         [u]
         ClassClearControls myControls= new ClassClearControls();
         myControls.ClearTextBox(thisForm);
         </u>


     }

  }
}

Please give me some ideas of doing this.Because the problem here is how can I refer to the FORM that it was been passed to a method of a class and do some action of clearing all the contents of of all the textboxes of the FORM that was passed to it.


Human Knowledge Belongs to the World
 
Old June 17th, 2004, 02:06 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
Send a message via Yahoo to melvik
Default

if u need just IDEA its mine:
Code:
textbox1.text = "";
And if u wanna make it dinamic for any textbox u can pass the textBox as an parameter or use sender.

HTH.

Always:),
Hovik Melkomian.
 
Old June 17th, 2004, 11:02 AM
tnd tnd is offline
Authorized User
 
Join Date: Jun 2004
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Default

If you called it by myControls.ClearTextBox(thisForm) then in the actual implementation of ClearTextBox you can reference the form directly. But there are a few problems.
1. I think this is what you are having problem with
The actual declaration of the function is soemthing like.
void ClearTextBox(myForm as Form) {implementation}
The problem is myForm is declared as a Form but the thisForm you passed is a sub-class of Form and therefore myForm have no knowledge of the methods/parameters available in thisForm)
One way around this is to base 'thisForm' on another form which includes a virtual method like ClearTextBoxes then inside myControls.ClearTextBox, you would be able to call myForm.ClearTextBox. But if you are going to do this, you might as well consider dropping the whole myControls and just stick with thisForm.ClearTextBox.
Also something else you want to look out for. I noticed the declaration for the textbox is private. You must declare them and any methods as public if you intend to do this.







Similar Threads
Thread Thread Starter Forum Replies Last Post
clearing out the form x_ray VB.NET 2002/2003 Basics 9 February 21st, 2006 04:44 PM
clearing the form europhreak Dreamweaver (all versions) 1 September 18th, 2005 03:35 AM
Clearing a LOGON_USER kgould Classic ASP Basics 0 February 10th, 2005 10:46 PM
Clearing a Form jbenson001 ASP.NET 1.x and 2.0 Application Design 2 December 3rd, 2003 11:43 AM





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