How to Unhide the Hidden form
-
Hi i am new in c#. I am developing an application which have a main form(frmstart) and second form (frmreader). i am moving from frmstart to frmReader form by a button click. it work fine. before moving to frmReader i hide frmStart. now i am on frmReader and i want to return back to my previous frmStart form. which is hidden. please tell me how to unhide the form. # code MovetoFrmReader frmReader R1 = new frmReader(); this.Hide(); R1.Show(); #code Returmback to frmStart this.Dispose(); ??? here in place of ??? what i need to write. Please Help me. Thanks Ravindra :doh:
-
Hi i am new in c#. I am developing an application which have a main form(frmstart) and second form (frmreader). i am moving from frmstart to frmReader form by a button click. it work fine. before moving to frmReader i hide frmStart. now i am on frmReader and i want to return back to my previous frmStart form. which is hidden. please tell me how to unhide the form. # code MovetoFrmReader frmReader R1 = new frmReader(); this.Hide(); R1.Show(); #code Returmback to frmStart this.Dispose(); ??? here in place of ??? what i need to write. Please Help me. Thanks Ravindra :doh:
Firstly, don't use Dispose, use Close instead - it will be disposed later when the CG gets round to it. Remember that your form may have results that the main form expects to be able to pick up. Instead, either 1) Pass the frmStart instance to frmReader (not brilliant, but it will work) and use the Show method on it before you Close() frmReader. This may give you problems if you miss a way to close teh form that you are not handling. or 2) Use
R1.ShowDialog();
instead ofR1.Show();
This will prevent frmStart from proceeding until frmReader is closed. It can then unhide itself. (Much preferable, as frmReader can be more generic and does not need to know about the existance of frmStart)Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
-
Firstly, don't use Dispose, use Close instead - it will be disposed later when the CG gets round to it. Remember that your form may have results that the main form expects to be able to pick up. Instead, either 1) Pass the frmStart instance to frmReader (not brilliant, but it will work) and use the Show method on it before you Close() frmReader. This may give you problems if you miss a way to close teh form that you are not handling. or 2) Use
R1.ShowDialog();
instead ofR1.Show();
This will prevent frmStart from proceeding until frmReader is closed. It can then unhide itself. (Much preferable, as frmReader can be more generic and does not need to know about the existance of frmStart)Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
OriginalGriff wrote:
it will be disposed later when the CG gets round to it.
Nah. I don't expect Christian flies around the world collecting our junk. :-D
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
Hi i am new in c#. I am developing an application which have a main form(frmstart) and second form (frmreader). i am moving from frmstart to frmReader form by a button click. it work fine. before moving to frmReader i hide frmStart. now i am on frmReader and i want to return back to my previous frmStart form. which is hidden. please tell me how to unhide the form. # code MovetoFrmReader frmReader R1 = new frmReader(); this.Hide(); R1.Show(); #code Returmback to frmStart this.Dispose(); ??? here in place of ??? what i need to write. Please Help me. Thanks Ravindra :doh:
Handle the
FormClosing
event ofR1
infrmstart
and it can unhide itself.// Different variable names used than in question!
using System;
using System.Windows.Forms;public partial class FormStart : Form
{
public FormStart()
{
InitializeComponent();
// Clicking the form will launch the reader
Click += new EventHandler(FormStart_Click);
}private void FormStart\_Click(object sender, EventArgs e) { ShowFormReader(); } private void ShowFormReader() { FormReader formReader = new FormReader(); formReader.FormClosing += new FormClosingEventHandler(formReader\_FormClosing); formReader.Show(); Hide(); } private void formReader\_FormClosing(object sender, FormClosingEventArgs e) { Show(); }
}
If it's not a close of
R1
that triggers this then you can easily create a custom event and handle that.Dave
Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum. Astonish us. Be exceptional. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) -
OriginalGriff wrote:
it will be disposed later when the CG gets round to it.
Nah. I don't expect Christian flies around the world collecting our junk. :-D
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
Good spot! :laugh:
Dave
Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum. Astonish us. Be exceptional. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) -
OriginalGriff wrote:
it will be disposed later when the CG gets round to it.
Nah. I don't expect Christian flies around the world collecting our junk. :-D
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
Luc Pattyn wrote:
I don't expect Christian flies around the world collecting our junk.
He can't - all airlines suck today :-D
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
-
Hi i am new in c#. I am developing an application which have a main form(frmstart) and second form (frmreader). i am moving from frmstart to frmReader form by a button click. it work fine. before moving to frmReader i hide frmStart. now i am on frmReader and i want to return back to my previous frmStart form. which is hidden. please tell me how to unhide the form. # code MovetoFrmReader frmReader R1 = new frmReader(); this.Hide(); R1.Show(); #code Returmback to frmStart this.Dispose(); ??? here in place of ??? what i need to write. Please Help me. Thanks Ravindra :doh:
Dave's approach is fine. Maybe a simpler approach is also acceptable: if the one form is hidden while the other is shown, the latter probably could be shown as a dialog, hence:
this.Hide();
otherForm.ShowDialog();
this.Show();:)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
Handle the
FormClosing
event ofR1
infrmstart
and it can unhide itself.// Different variable names used than in question!
using System;
using System.Windows.Forms;public partial class FormStart : Form
{
public FormStart()
{
InitializeComponent();
// Clicking the form will launch the reader
Click += new EventHandler(FormStart_Click);
}private void FormStart\_Click(object sender, EventArgs e) { ShowFormReader(); } private void ShowFormReader() { FormReader formReader = new FormReader(); formReader.FormClosing += new FormClosingEventHandler(formReader\_FormClosing); formReader.Show(); Hide(); } private void formReader\_FormClosing(object sender, FormClosingEventArgs e) { Show(); }
}
If it's not a close of
R1
that triggers this then you can easily create a custom event and handle that.Dave
Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum. Astonish us. Be exceptional. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)WRT your code, I want to get data from FormReader to FormStart. I uses following 2 approaches: A)
FormReader formReader = new FormReader(this);
Now, making FormStart member as internal/public accessing them on FormReader. B)On click(here its closing) event handler as you did
private void formReader_FormClosing(object sender, FormClosingEventArgs e)
{
//access member of FormReader
}But here i have to make FormReader Member internal/public My question is, Which approach is good? As in first we are making parent form member public, But,In 2nd we are child form member public. Or is there any other way? +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Also If i have a case like
interface IA
{
void M();
}interface IB { void M(); } class ABC : IA, IB { public void M() { MessageBox.Show("Hello"); } }
ABC a = new ABC();
a.M();Whose Interface method i am implementing? Its running not giving error? What is the use of this definition ? And what should i do if i want to implement IA not IB or vice versa. Or by default its calling/implementing IA M, as it's mentioned 1st as ABC:IA,IB
-
WRT your code, I want to get data from FormReader to FormStart. I uses following 2 approaches: A)
FormReader formReader = new FormReader(this);
Now, making FormStart member as internal/public accessing them on FormReader. B)On click(here its closing) event handler as you did
private void formReader_FormClosing(object sender, FormClosingEventArgs e)
{
//access member of FormReader
}But here i have to make FormReader Member internal/public My question is, Which approach is good? As in first we are making parent form member public, But,In 2nd we are child form member public. Or is there any other way? +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Also If i have a case like
interface IA
{
void M();
}interface IB { void M(); } class ABC : IA, IB { public void M() { MessageBox.Show("Hello"); } }
ABC a = new ABC();
a.M();Whose Interface method i am implementing? Its running not giving error? What is the use of this definition ? And what should i do if i want to implement IA not IB or vice versa. Or by default its calling/implementing IA M, as it's mentioned 1st as ABC:IA,IB
With regard to your first question - getting data from
FormReader
toFormStart
: Do NOT use method A. It works but it is a nasty hack that as things get more complex you will regret! Method B does not require any change to the access modifier ofFormReader
. Thesender
parameter will (normally) be theFormReader
instance. So, inside the handler add something like this:FormReader formReader = sender as FormReader;
if(formReader != null)
{
// You can now use formReader. to access any properties/methods
}There is another method if you want
FormReader
to informFormStart
that there is data it may be interested in - you can raise a custom event inFormReader
and subscribe to that inFormStart
. Have a look at this tip[^], this tip[^], then this article[^] if this would fit your case better.Dave
Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum. Astonish us. Be exceptional. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) -
WRT your code, I want to get data from FormReader to FormStart. I uses following 2 approaches: A)
FormReader formReader = new FormReader(this);
Now, making FormStart member as internal/public accessing them on FormReader. B)On click(here its closing) event handler as you did
private void formReader_FormClosing(object sender, FormClosingEventArgs e)
{
//access member of FormReader
}But here i have to make FormReader Member internal/public My question is, Which approach is good? As in first we are making parent form member public, But,In 2nd we are child form member public. Or is there any other way? +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Also If i have a case like
interface IA
{
void M();
}interface IB { void M(); } class ABC : IA, IB { public void M() { MessageBox.Show("Hello"); } }
ABC a = new ABC();
a.M();Whose Interface method i am implementing? Its running not giving error? What is the use of this definition ? And what should i do if i want to implement IA not IB or vice versa. Or by default its calling/implementing IA M, as it's mentioned 1st as ABC:IA,IB
Sorry, forgot your second question! The answer is neither. An interface has no implementation so you never actually use any methods/properties/events they appear to have. You always use the implementation in the class that provides the implementation.
Dave
Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum. Astonish us. Be exceptional. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)