Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (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 by aewarnick
C#
Posted (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 by aewarnick
C#
Posted (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 by divil
C#

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...