|
benjamin yap wrote: childLogin.MdiParent = this;
This is why you can't do it. Get rid of this line, it makes no sense to have it. Set te Owner property instead ( or Parent, I forget which, but I think it's Owner you want ). This stops your modal form from ever being hidden by it's parent.
benjamin yap wrote: stripLblLoginAs.Text = "Login As :";
This is going to occur *after* your login form has shown.
Now the easy easy way to make this work is to set the DIalogResult to DialogResult.OK only if the login succeeds. Then you can do
if (childLogin.ShowDialog() == DialogResult.OK)
{
// logged in
}
else
{
// failed, close the program or whatever
}
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Christian, i am very sorry for asking so many question, I just started c# few days ago. Please bear with me
childLogin.MdiParent = this; --> i though this is to link to the parent form?
How do i set to owner property?
|
|
|
|
|
This is a link in an MDI form, I've never used it and it apparently only works to create child forms within an MDI app. childLogin.Owner = this; will do what you want.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
A dialog is not a MdiChild, so <ode>childLogin.MdiParent = this; can be ignored.
According to my experience:
<br />
childForm child=new childForm();<br />
child.ShowDialog(parent);<br />
works.
My code and I is not professional. take careful advantage.
|
|
|
|
|
hmm after i remove that line, and set to owner property, i get this error when i press the login button
else if ((txtUsername.Text == username) && (txtPassword.Text == password))
{
FrmMain frmMain = (FrmMain)this.MdiParent;
frmMain.toolStripStaff.Visible = true; <----ERROR HERE
this.Hide();
}
Object reference not set to an instance of an object.
|
|
|
|
|
FrmMain frmMain = (FrmMain)this.MdiParent
your login form doesn't have a parent, so the frmMain will be null when running.
try this:
in main form:
LoginForm login=new LoginForm();
login.ShowDialog(this);
if (login.DialogResult==DialogResult.OK)
{
this.toolStripStaff.Visible = true;
........
in login form:
else if ((txtUsername.Text == username) && (txtPassword.Text == password))
{
this.DialogResult=DialogResult.OK;
........
|
|
|
|
|
Great! Thanks alot!
So how do i pass the value of the txtUsername inside my Login to my statusstrip at my mainform
stripLblLoginAs.Text = "Login As :" + login.txtUsername.Text;
|
|
|
|
|
Err, I see, txtUsername is private huh?
define a property:
<br />
public string Username<br />
{<br />
get{return txtUsername.Text;}<br />
}<br />
So, in main form:
<br />
stripLblLoginAs.Text = "Login As :" + login.Username;<br />
|
|
|
|
|
set the txtUsername as public, or just define a public variable in child form.
|
|
|
|
|
See, apart from being ugly as all sin, that plain doesn't work. He wants to send a message back to the parent, so how does the parent know that the child value has changed. Delegates solve both these problems, they are not ugly and they go in any direction.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
I admit that it's ugly. But it works.
|
|
|
|
|
Yes, but some of us write professional code, not just whatever works ( and your solution still does not work )
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
It also breaches one of the tenets of Object Oriented programming.
|
|
|
|
|
Why don't you the login form as a dialog?
|
|
|
|
|
i prefer a form with textbox nicer and more professional
|
|
|
|
|
Forms can be shown as dialog and return a DialogResult, that makes things simple.
|
|
|
|
|
Yes, if the form is modal, then it makes sense to do what you suggested, I just assumed from the question wording that it was modeless. In that case, I apologise, I would use properties and the DialogResult to return a value from a modal form.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
You can in your child form's constructor set a field to the opener of it, then at anytime call any method on that form using its reference called. ex:
class Parent
{
public void Anymethod(){}
public Parent()
{
Child c = new Child(this);
}
}
class Child
{
private Form Owner;
public Child(Form f)
{Owner = f;}
public void CallParent()
{
Owner.AnyMEthod();
}
}
|
|
|
|
|
Hi,
I have problem for developing in OO style, I know the basic of OO.
which refrences are suitable for this purpose?
(with examples)
Best wishes
|
|
|
|
|
Hmm.... I think that OO thinking really comes more with practice, but Microsoft has a book, called Object Thinking.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
When you know the mechanics of object-oriented programming but you don't really know how apply it to a well-thought out application, this is a pretty good book:
"Object Design: Roles, Responsibilities, and Collaborations"...
|
|
|
|
|
Hi
How to create collection class??
I have to save more than one rows in Database.I think collection class is the best way of doing this type of task.
Or Is there any other way of doing this type of task?
Thanx
Seema
|
|
|
|
|
Seema Gosain wrote: How to create collection class??
Why would you ? The built in ones work just great.
Seema Gosain wrote: I have to save more than one rows in Database.
OK - you mean you need to store into the actual SQL database ? Then you need to write SQL, not use a collection class.
Sounds to me like you know some terminologies but not what they mean, have you worked through a beginners book, or are you learning C# on the job ?
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Hi Evry1..
I have couple of Picture Boxes ... If I mouse over on a picture box it should be highlighted...How will I do that using c#
sample code is appreciated..
regards,
Subhash.
|
|
|
|
|
By handling the mouse events and drawing a box around the picture box, I guess. Personally, I'd ditch the picture box, draw the images yourself, and have far more options for how to highlight them.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|