Is it possible to enable controls on the form from a class.
-
Hi I am developing a C# windows application in .net1.1 In this i have a form, in which i am taking the input parameters, if the parameters are valid i am passing the paramers to a method which is in another class. while passing the paramers i am disabling some buttons on the form. After completing the process i want to enable the buttons on the form from the class. Is it possible to enable controls on the form from a class. Thanks in Advance Ramu
-
Hi I am developing a C# windows application in .net1.1 In this i have a form, in which i am taking the input parameters, if the parameters are valid i am passing the paramers to a method which is in another class. while passing the paramers i am disabling some buttons on the form. After completing the process i want to enable the buttons on the form from the class. Is it possible to enable controls on the form from a class. Thanks in Advance Ramu
Ramu.M wrote:
Is it possible to enable controls on the form from a class
yes
Luc Pattyn
try { [Search CP Articles] [Search CP Forums] [Forum Guidelines] [My Articles] } catch { [Google] }
-
Ramu.M wrote:
Is it possible to enable controls on the form from a class
yes
Luc Pattyn
try { [Search CP Articles] [Search CP Forums] [Forum Guidelines] [My Articles] } catch { [Google] }
-
Hi I am developing a C# windows application in .net1.1 In this i have a form, in which i am taking the input parameters, if the parameters are valid i am passing the paramers to a method which is in another class. while passing the paramers i am disabling some buttons on the form. After completing the process i want to enable the buttons on the form from the class. Is it possible to enable controls on the form from a class. Thanks in Advance Ramu
Hi . Yes you can , something like following code :
public class ControlForm { public static void EnableTextBox() { FrmTest frmTest = new frmTest(); frmTest.txtName.Enable = true; } }
Important :Set your control modifier property to Internal or Public Bad Programming :Don't try to do this . It's not a smart coding .DMASTER
-
The other class must know about the form - so you must pass details of the form to the other class (remember, forms are classes too) somehow. Then the class can access the form. You must provide a mechanism on the form to receive the request
class MyForm : Form
{
...// The form class needs a mechanism to receive the request to // disable the controls. public void DisableControls() { // Code to disable the controls goes here }
}
class MyOtherClass
{
// The other class needs to store the form
private MyForm myForm;// In this example the other class gets told about the form at // the time it is instantiated. It could also set up a property // to receive that information. public MyOtherClass(MyForm myForm) { this.myForm = myForm; } // The class has some code somewhere that needs to disable the // controls on the form. public SomeMethodThatNeedsToDisableTheControls() { ... myForm.DisableControls(); ... }
}
Does this help?
Upcoming events: * Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ... "I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless." My website
-
Hi I am developing a C# windows application in .net1.1 In this i have a form, in which i am taking the input parameters, if the parameters are valid i am passing the paramers to a method which is in another class. while passing the paramers i am disabling some buttons on the form. After completing the process i want to enable the buttons on the form from the class. Is it possible to enable controls on the form from a class. Thanks in Advance Ramu
Even you can use Delegates for Enabling/Disabling controls of the Form. The Delegate will remove the requirement to declare control objects (Text etc) public.
Manoj Never Gives up
-
If you hold a reference to the form, you can manipulate everything on it that is declared public, as in myForm.myButton.Enabled=true; But it is considered bad design to make controls public, since everyone holding the reference (myForm) can also replace, resize, move, hide, ... said control. In fact, it is almost always wrong to provide public fields, only methods and properties should be candidates for the public attribute. An acceptable approach is: - keep the controls private (or protected) to your form class; - provide public methods (or properties) inside your form class, that offer the required functionality to the outside world, no more, no less; - pass the form's reference to your class and have it use the public methods or properties. And if you are familiar with delegates, they offer the best approach. It basically means your form creates a delegate (that's like a function pointer connected to the form's object), so now it can pass that delegate to your class, without even having to pass the form's reference itself. That is encapsulation, provide as little as possible, just give what is absolutely necessary. :)
Luc Pattyn
try { [Search CP Articles] [Search CP Forums] [Forum Guidelines] [My Articles] } catch { [Google] }
-
Even you can use Delegates for Enabling/Disabling controls of the Form. The Delegate will remove the requirement to declare control objects (Text etc) public.
Manoj Never Gives up
Manoj Kumar Rai wrote:
The Delegate will remove the requirement to declare control objects (Text etc) public.
Text is a parameter on the control. You cannot make that public. You must make the control public, or create a new property on the form that proxies for the control's property.
Upcoming events: * Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ... "I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless." My website
-
Manoj Kumar Rai wrote:
The Delegate will remove the requirement to declare control objects (Text etc) public.
Text is a parameter on the control. You cannot make that public. You must make the control public, or create a new property on the form that proxies for the control's property.
Upcoming events: * Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ... "I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless." My website
Yes Yes, You are corrrect. I meant TextBox there.
Manoj Never Gives up
-
Hi I am developing a C# windows application in .net1.1 In this i have a form, in which i am taking the input parameters, if the parameters are valid i am passing the paramers to a method which is in another class. while passing the paramers i am disabling some buttons on the form. After completing the process i want to enable the buttons on the form from the class. Is it possible to enable controls on the form from a class. Thanks in Advance Ramu
-
I'm already say it . So , what ...:confused:
DMASTER