473,387 Members | 1,925 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Enable / Disable forms?

Hi!

I have two forms, one opening the other. The opener disables itself
when it opens the other window, and the other window is suppose to
enable the first window again when closed. I tried this code, but I
get the error that "'object' does not contain a definition for
'DoEnable'". I'm quite a rookie in C#, so hopefully there is a quick
way to fix this...

FORM1:
private void buttonNew_Click(object sender, System.EventArgs e)
{
this.Enabled = false;
NewCDForm myNewCDForm = new NewCDForm(this);
myNewCDForm.Show();
}

public void DoEnable()
{
this.Enabled = true;
}
FORM 2:
private void NewCDForm_Closed(object sender, System.EventArgs e)
{
myCaller.DoEnable();
}

best regards,
Andreas
Nov 16 '05 #1
9 30922
Are you storing the Form reference in the overloaded constructor for Form2
as the proper type? Make sure that you're not storing the Form1 reference as
a basic Form.

--
Tim Wilson
..Net Compact Framework MVP

"Andreas" <d9****@efd.lth.se> wrote in message
news:f7**************************@posting.google.c om...
Hi!

I have two forms, one opening the other. The opener disables itself
when it opens the other window, and the other window is suppose to
enable the first window again when closed. I tried this code, but I
get the error that "'object' does not contain a definition for
'DoEnable'". I'm quite a rookie in C#, so hopefully there is a quick
way to fix this...

FORM1:
private void buttonNew_Click(object sender, System.EventArgs e)
{
this.Enabled = false;
NewCDForm myNewCDForm = new NewCDForm(this);
myNewCDForm.Show();
}

public void DoEnable()
{
this.Enabled = true;
}
FORM 2:
private void NewCDForm_Closed(object sender, System.EventArgs e)
{
myCaller.DoEnable();
}

best regards,
Andreas

Nov 16 '05 #2
Oh, sorry. I have one more method of importance, the load-method of
Form 2 that sets myCaller = FORM1! (or at least that is what I try to
do.)
So, my problem is still, why can't I call myCaller.DoEnable()???

I'm not sure what you ment with "basic Form" Tim, I store it as
"object".

FORM 1:
private void buttonNew_Click(object sender, System.EventArgs e)
{
this.Enabled = false;
NewCDForm myNewCDForm = new NewCDForm(this);
myNewCDForm.Show();
}

public void DoEnable()
{
this.Enabled = true;
}

FORM 2:
internal class NewCDForm : System.Windows.Forms.Form
{
object myCaller;
public NewCDForm(object caller)
{
myCaller = caller;
}
private void NewCDForm_Closed(object sender, System.EventArgs e)
{
myCaller.DoEnable();
}
}

Thanks again,
Andreas Lundgren

"Tim Wilson" <TIM(UNDERSCORE)WILSON(AT)ROGERS(PERIOD)COM> wrote in message news:<eZ**************@TK2MSFTNGP15.phx.gbl>...
Are you storing the Form reference in the overloaded constructor for Form2
as the proper type? Make sure that you're not storing the Form1 reference as
a basic Form.

--
Tim Wilson
.Net Compact Framework MVP

"Andreas" <d9****@efd.lth.se> wrote in message
news:f7**************************@posting.google.c om...
Hi!

I have two forms, one opening the other. The opener disables itself
when it opens the other window, and the other window is suppose to
enable the first window again when closed. I tried this code, but I
get the error that "'object' does not contain a definition for
'DoEnable'". I'm quite a rookie in C#, so hopefully there is a quick
way to fix this...

FORM1:
private void buttonNew_Click(object sender, System.EventArgs e)
{
this.Enabled = false;
NewCDForm myNewCDForm = new NewCDForm(this);
myNewCDForm.Show();
}

public void DoEnable()
{
this.Enabled = true;
}
FORM 2:
private void NewCDForm_Closed(object sender, System.EventArgs e)
{
myCaller.DoEnable();
}

best regards,
Andreas

Nov 16 '05 #3
Instead of storing the Form as an Object type, store it as the actual Form
type. The compiler needs to verify that the method that you are attempting
to call actually exists on the object. So, let's say, that the first Form
class reference, the one that is being passed into the "NewCDForm" Form, is
called "Form1", then you would need to store it as the proper Form type
instead of object.

FORM 2:
internal class NewCDForm : System.Windows.Forms.Form
{
Form1 myCaller;
public NewCDForm(Form1 caller)
{
myCaller = caller;
}
private void NewCDForm_Closed(object sender, System.EventArgs e)
{
myCaller.DoEnable();
}
}

--
Tim Wilson
..Net Compact Framework MVP

"Andreas" <d9****@efd.lth.se> wrote in message
news:f7**************************@posting.google.c om...
Oh, sorry. I have one more method of importance, the load-method of
Form 2 that sets myCaller = FORM1! (or at least that is what I try to
do.)
So, my problem is still, why can't I call myCaller.DoEnable()???

I'm not sure what you ment with "basic Form" Tim, I store it as
"object".

FORM 1:
private void buttonNew_Click(object sender, System.EventArgs e)
{
this.Enabled = false;
NewCDForm myNewCDForm = new NewCDForm(this);
myNewCDForm.Show();
}

public void DoEnable()
{
this.Enabled = true;
}

FORM 2:
internal class NewCDForm : System.Windows.Forms.Form
{
object myCaller;
public NewCDForm(object caller)
{
myCaller = caller;
}
private void NewCDForm_Closed(object sender, System.EventArgs e)
{
myCaller.DoEnable();
}
}

Thanks again,
Andreas Lundgren

"Tim Wilson" <TIM(UNDERSCORE)WILSON(AT)ROGERS(PERIOD)COM> wrote in message

news:<eZ**************@TK2MSFTNGP15.phx.gbl>...
Are you storing the Form reference in the overloaded constructor for Form2 as the proper type? Make sure that you're not storing the Form1 reference as a basic Form.

--
Tim Wilson
.Net Compact Framework MVP

"Andreas" <d9****@efd.lth.se> wrote in message
news:f7**************************@posting.google.c om...
Hi!

I have two forms, one opening the other. The opener disables itself
when it opens the other window, and the other window is suppose to
enable the first window again when closed. I tried this code, but I
get the error that "'object' does not contain a definition for
'DoEnable'". I'm quite a rookie in C#, so hopefully there is a quick
way to fix this...

FORM1:
private void buttonNew_Click(object sender, System.EventArgs e)
{
this.Enabled = false;
NewCDForm myNewCDForm = new NewCDForm(this);
myNewCDForm.Show();
}

public void DoEnable()
{
this.Enabled = true;
}
FORM 2:
private void NewCDForm_Closed(object sender, System.EventArgs e)
{
myCaller.DoEnable();
}

best regards,
Andreas

Nov 17 '05 #4
Thanks Tim!
(Google problem made me answer the first post.)

That solvs my problem, but it removes a bit of the beauty! What if
this was a more general form that could have different callers? Lets
say a kind of a more advanced Yes/No form. In VB6, I can typically do
such an design where a general form can call a specific function that
several different callers have implemented.

best regards
/Andreas
Nov 17 '05 #5
One way you could do this is to create a base Form class that contains the
method. Then have all the other Forms inheriting from this Form. Then use
the base Form type as the expected parameter. Since all the derived Forms
will contain the method through inheritance, you would gain some more
flexibility this way.

Alternatively, you might consider creating a custom event on the second Form
that other Forms can hook into and receive notification when something
interesting happens. In this case, the event is already created for you. If
you listen for the second Form to close, through the Closed event, the first
Form can re-enable itself.

....

Form2 f = new Form2();
f.Closed += new EventHandler(f_Closed);
this.Enabled = false;
f.Show();

....

private void f_Closed(object sender, EventArgs e)
{
this.Enabled = true;
}

Are you sure that you don't want to use the ShowDialog() method ike Otis
proposed?

--
Tim Wilson
..Net Compact Framework MVP

"Andreas" <d9****@efd.lth.se> wrote in message
news:f7**************************@posting.google.c om...
Thanks Tim!
(Google problem made me answer the first post.)

That solvs my problem, but it removes a bit of the beauty! What if
this was a more general form that could have different callers? Lets
say a kind of a more advanced Yes/No form. In VB6, I can typically do
such an design where a general form can call a specific function that
several different callers have implemented.

best regards
/Andreas

Nov 17 '05 #6
Thanks a lot!

That was two handsome ways to solv my problem! I tried the
ShowDialog() functionallity, and it was a simple way to solve simple
problems, byt if you want for example a general print dialog that
could be opened from several different forms, and the print dialog
must notify it's caller the status when it is done, the ShowDialog()
is not enougth. (It did however solv my acctual question, but as a
newbe to the language, I was also intressted in finding a solution to
the general problem.)

/Andreas
Nov 17 '05 #7
So are you back up and running? No problems now?

--
Tim Wilson
..Net Compact Framework MVP

"Andreas" <d9****@efd.lth.se> wrote in message
news:f7**************************@posting.google.c om...
Thanks a lot!

That was two handsome ways to solv my problem! I tried the
ShowDialog() functionallity, and it was a simple way to solve simple
problems, byt if you want for example a general print dialog that
could be opened from several different forms, and the print dialog
must notify it's caller the status when it is done, the ShowDialog()
is not enougth. (It did however solv my acctual question, but as a
newbe to the language, I was also intressted in finding a solution to
the general problem.)

/Andreas

Nov 17 '05 #8
Andreas wrote:
That solvs my problem, but it removes a bit of the beauty! What if
this was a more general form that could have different callers? Lets
say a kind of a more advanced Yes/No form. In VB6, I can typically do
such an design where a general form can call a specific function that
several different callers have implemented.


You might consider defining an appropriate interface that all callers must
implement. This will be less specific. Otherwise, inheriting from a common
base class would solve your problem, too.

Nov 17 '05 #9
Andreas wrote:

[...snip...]
for example a general print dialog that
could be opened from several different forms, and the print dialog
must notify it's caller the status when it is done, the ShowDialog()
is not enougth. [...snip...]

Your form might contain public properties for the information you'd want to
pass to the caller(s). The caller may retrieve the properties value after
the form has closed. Setting the Forms DialogResult property when dismissing
the dialog might be an option, too:

Form1 myDialog = new MyDialog();
if (myDialog.ShowDialog() == DialogResult.OK)
{
int retrievedCount = myDialog.itemCount;
string retrievedText = myDialog.userText;
};

Where itemCount and userText are examples for properties of the MyDialog
class.
(It did however solv my acctual question, but as a
newbe to the language, I was also intressted in finding a solution to
the general problem.)

/Andreas


HTH
Michael
Nov 17 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Bob Bedford | last post by:
I've this code: function checkdate(FormSubmit){ alert(document.getElementById('Mois').value); if(eval(document.getElementById('Mois'))>0 && eval(document.getElementById('Annee'))>0){...
1
by: vncntj | last post by:
i want to enable one listbox and disable the other depending on if i check winter_gala (checkbox) here is my code. <script type="text/javascript"> function check() { if...
6
by: Ben | last post by:
Here's what I have se far: <script type="text/javascript"> other_text.disabled = true; function other_text() { other_text.disabled = (other_check.checked == false)? false : true; } </script>...
3
by: DBQueen | last post by:
I have a form with lines of controls. On some of the lines there are 3 controls (call them A,B,C); other lines have only control A. The controls have been numbered sequentially (Q20, Q21....Q76)...
1
by: Suni | last post by:
Hi everybody, But what I am trying to do is like, there are 2 forms, and if I click on the button in form1, it'll open up form2 and disable the button in form1. Then when I click on the button in...
3
by: Stilgar[bbs.isca.uiowa.edu] | last post by:
Here's my newbie question: I have several VB forms which are all inherit a standard template form that I made. In my template form, I added a menu bar with some generic cut, copy, and paste...
1
by: inadsad | last post by:
Good Day, I have 2 forms with bindingNavigator and have a simple routine to enable/disable navigator buttons. Each nav button is assigned to a tag value. The problem is that if I want to...
1
by: Birky | last post by:
I have a form (Custom_Code) that has a sub form (Support_Groups_Form) associated to it. I have a need to enable and disable the fields depending on user selection but I am having trouble controlling...
3
by: Pietro | last post by:
Hi all, First of all I'd like to thank you very very much ,as finally after many years of searching,I could find a code to disable/enable the shift key,but actually i cannot use the code as I'm...
3
by: Donald A. Fisher | last post by:
Hello. I've been working a vb project and have a form with a button on it that performs some actions after disabling the button when clicked: Code disabling button and starting actions: Private...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.