aewarnick Posted March 7, 2003 Posted March 7, 2003 (edited) Having a form send back a DialogResult value. Is that possible? If so, how do you do it? I'll tell you what I am doing so that you understand better. I have a tab control that is password protected by another password form that pops up. If the password is correct I want to send back "access" if it is not correct I want to send back "noaccess". Edited March 7, 2003 by aewarnick Quote C#
*Gurus* divil Posted March 7, 2003 *Gurus* Posted March 7, 2003 Provided you've shown the form with the ShowDialog method, you can just set DialogResult from within the popup form. I suggest you use Ok and Cancel for your access and noaccess values, respectively. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
aewarnick Posted March 7, 2003 Author Posted March 7, 2003 (edited) Ok, I have it set up. But no matter what I get the result "Cancel" returned because I need to close the form with this.Close(). Even when I use Dispose I get the same thing. Edited March 7, 2003 by aewarnick Quote C#
aewarnick Posted March 7, 2003 Author Posted March 7, 2003 (edited) // // PassForm // this.AutoScaleBaseSize = new System.Drawing.Size(6, 14); this.ClientSize = new System.Drawing.Size(194, 80); this.Controls.AddRange(new System.Windows.Forms.Control[] { this.TB, this.label1}); this.Font = new System.Drawing.Font("Verdana", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0))); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow; this.MaximizeBox = false; this.MinimizeBox = false; this.Name = "PassForm"; this.ShowInTaskbar = false; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "Security"; this.TopMost = true; this.ResumeLayout(false); this.DialogResult=DialogResult.No; } #endregion private void TB_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) { if((int)e.KeyChar==(int)Keys.Enter) { string pass=""; pass=CommunicationLog.aaa.GetValue("aaa").ToString().ToLower(); if(pass==this.TB.Text.ToLower()) { //CommunicationLog.Access=true; r=DialogResult.Yes; this.Dispose(); } else {//MessageBox.Show("Access Denied"); r=DialogResult.No; this.Dispose();} } -------------------------------------------------------------------------------- PassForm P=new PassForm(); DialogResult r= P.ShowDialog(); if(r==DialogResult.Yes) MessageBox.Show(r+""); else MessageBox.Show(r+""); Edited March 7, 2003 by divil Quote C#
aewarnick Posted March 7, 2003 Author Posted March 7, 2003 Ok, now I remember. DialogResult is a property, not a variable. It works now. Thank you very much. Quote C#
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.