473,465 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

cannot re-enable disable button

16 New Member
Im using two forms. On form 1 i decides to open the specific form(form 2) i disables the
button which is present in form 1 by changing its property to btn.Enabled=false;

When i open the second form(form 2)and after doing some operations there i close
form 2 in c# there is a function
public void formclosed(Object sender,formclosedeventsargs e)
{

//in this function i call the form 1 constructor once again
form1 f1= new form1();

}
form1()
{
this.butn.enabled=true;

}

In doing dis nothing happens i still see btn in form1 as disabled i cannot click and perform
any other operation on it.

Please tell me whats going on...
Nov 7 '07 #1
5 6158
r035198x
13,262 MVP
Im using two forms. On form 1 i decides to open the specific form(form 2) i disables the
button which is present in form 1 by changing its property to btn.Enabled=false;

When i open the second form(form 2)and after doing some operations there i close
form 2 in c# there is a function
public void formclosed(Object sender,formclosedeventsargs e)
{

//in this function i call the form 1 constructor once again
form1 f1= new form1();

}
form1()
{
this.butn.enabled=true;

}

In doing dis nothing happens i still see btn in form1 as disabled i cannot click and perform
any other operation on it.

Please tell me whats going on...
An object's constructor is called only once when that object is created. You did not call form1's constructor again. You created another form called form1 again.
If you want to control form1's controls from methods inside the form2 class then you need to pass a reference of the form1 object to either form2's contructor or one of its methods. Or better still, you could have a controller class that determines when what is displayed and how. It's just another design issue again ...
Nov 7 '07 #2
zonar00
16 New Member
An object's constructor is called only once when that object is created. You did not call form1's constructor again. You created another form called form1 again.
If you want to control form1's controls from methods inside the form2 class then you need to pass a reference of the form1 object to either form2's contructor or one of its methods. Or better still, you could have a controller class that determines when what is displayed and how. It's just another design issue again ...
I solved the problem i did it through passing the ref of form 1 into form 2 constructor. It did the tricked for me.

form1 f1;
form2(form1 f11)
{
f1=f11;
}

this f1 thus contained the current status for form 1 and i was able to control the disable feature by calling f1.btn.enabled=true;

where "btn"property / accessibility was set to "public"in order it to be accessible in other forms.
Nov 7 '07 #3
r035198x
13,262 MVP
I solved the problem i did it through passing the ref of form 1 into form 2 constructor. It did the tricked for me.

form1 f1;
form2(form1 f11)
{
f1=f11;
}

this f1 thus contained the current status for form 1 and i was able to control the disable feature by calling f1.btn.enabled=true;

where "btn"property / accessibility was set to "public"in order it to be accessible in other forms.
I hope you are always concious of having good design though ... and those variable names (form1, form2, f111) , I always see them in most .NET programs posted here, they are so bad and should be avoided. Variable names should reflect the real world use of the property.
That will save you and other programmers who may have to look at your code a lot of debugging time when the program becomes big.
Nov 7 '07 #4
zonar00
16 New Member
I hope you are always concious of having good design though ... and those variable names (form1, form2, f111) , I always see them in most .NET programs posted here, they are so bad and should be avoided. Variable names should reflect the real world use of the property.
That will save you and other programmers who may have to look at your code a lot of debugging time when the program becomes big.
yeah i know my programming teachers used to say the same thing over and over again.but i think in unsafe hands these real life resemblance means that your code becomes much clearer and understandable.

Without them, the other coder/hacker etc has to really dig in to understand whts going on. Its just as simple like if the fun() for the login process is named as authenticate(). The other coder would easily know that what it should and is there for.
Nov 7 '07 #5
r035198x
13,262 MVP
yeah i know my programming teachers used to say the same thing over and over again.but i think in unsafe hands these real life resemblance means that your code becomes much clearer and understandable.

Without them, the other coder/hacker etc has to really dig in to understand whts going on. Its just as simple like if the fun() for the login process is named as authenticate(). The other coder would easily know that what it should and is there for.
Trust me code hackers will be able to understand it even if you use form1 type variable names. You need better obfuscation algorithms than that.
The danger here is that will you be able to understand your own code when you want to edit it one day?
Nov 7 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Bob | last post by:
I am displaying a form with a datagrid populated from a select of database records which now exceed 12,000 when I select them all. The form displays just fine with all 12,000+ entries but when I...
1
by: Peter | last post by:
I've purchased VS.NET 2005 Standard and have tried to install SQL Server 2005 Express, but get the following error in the error log. Please could someone help me.... Microsoft SQL Server 2005...
3
by: David T. Ashley | last post by:
Hi, Red Hat Enterprise Linux 4.X. I'm writing command-line PHP scripts for the first time. I get the messages below. What do they mean? Are these operating system library modules, or...
19
by: lawrence k | last post by:
How can I find out where my script is outputting to the screen for the first time? My error logs are full of stuff like this: PHP Warning: session_start(): Cannot send session cache...
1
by: vsp15584 | last post by:
Hii..i use the coding as below :- import java.applet.applet; import java.awt.*; import com.sun.j3d.utils.applet.mainframe; import com.sun.j3d.utils.universe.*; import...
4
by: ThunderMusic | last post by:
Hi, I have a custom form that works fine when I debug it or run it in release mode but cannot be loaded in the designer... Actually, it can be loaded in the designer when no control is on it, but...
0
by: =?Utf-8?B?QWxoYW1icmEgRWlkb3MgS2lxdWVuZXQ=?= | last post by:
Hello, mister I have an application web asp.net 2.0 + vs 2005 and VS 2005 Web Application Project. Its appears this error in execution: "Cannot Create/Shadow Copy '<projectname>' when that...
3
by: amanjsingh | last post by:
Hi, I am trying to implement Java Web Service using Apache Axis2 and Eclipse as a tool. I have created the basic code and deployed the service using various eclipse plugin but when I try to invoke...
1
by: kw.housing | last post by:
I have all the library already in path: $ ls -l /opt/IBM/db2/lib64 | grep libdb2o -r-xr-xr-x 1 bin bin 7757295 Jul 12 2006 libdb2osse.a* -r--r--r-- 1 bin bin ...
3
by: Sindhu Rani | last post by:
i hav created 3 classes in 3 different files. am gettin an error durin compilation. wat shud i do??? C:\s\source>javac -d ..\classes devtestdrive.java devtestdrive.java:5: cannot resolve symbol...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.