My floating TextBox control sometimes disappears

I have a derived TextBox control I use to rename treenodes and it disp

Page 1 of 1

1 Replies - 4145 Views - Last Post: 31 May 2009 - 10:26 AM Rate Topic: -----

#1 DdoubleD  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 27-May 09

My floating TextBox control sometimes disappears

Post icon  Posted 31 May 2009 - 08:37 AM

I cannot figure out how to keep the control from hiding. The CanRenameNode(...) displays a MessageBox on error. I am using the TextBox (tbxRename) to rename a TreeNode in my TreeView and I display it over the SelectedNode.

After it disappears, if I click on the SelectedNode being renamed again, Validating gets called, error MessageBox is displayed again, then the TextBox (tbxRename) reappears! Meaning, the TextBox is still processing input or rather seems to be the control with focus.

This disappearing behavior only occurs with Enter pressed to accept the contents and does not occur when the user clicks on another TreeNode.

I think I added the tbxRename.Show() to the code below at some point trying to resolve this error, but I guarantee Hide() is not being called in my code.

		// RENAME SITENAME
		private void tbxRename_Validating(object sender, CancelEventArgs e)
		{
			if (tbxRename.originalText != tbxRename.Text)
			{
				//TreeNode node = dtvSiteName.SelectedNode;
				System.Diagnostics.Debug.Assert(dtvSiteName.SelectedNode == renameNode);
				// Check for any problems (duplicates, etc.) and inform user.
				if (!CanRenameNode(tbxRename.originalText, tbxRename.Text))
				{
					e.Cancel = true;
					tbxRename.Show();
					tbxRename.BringToFront();
					tbxRename.Select(0, tbxRename.Text.Length);
				}
			}
		}




Is This A Good Question/Topic? 0
  • +

Replies To: My floating TextBox control sometimes disappears

#2 SixOfEleven  Icon User is offline

  • using Caffeine;
  • member icon

Reputation: 945
  • View blog
  • Posts: 6,342
  • Joined: 18-October 08

Re: My floating TextBox control sometimes disappears

Posted 31 May 2009 - 10:26 AM

Try adding a call to Invalidate at the end of the method, that would tell the control that it needs to be redrawn:

		// RENAME SITENAME
		private void tbxRename_Validating(object sender, CancelEventArgs e)
		{
			if (tbxRename.originalText != tbxRename.Text)
			{
				//TreeNode node = dtvSiteName.SelectedNode;
				System.Diagnostics.Debug.Assert(dtvSiteName.SelectedNode == renameNode);
				// Check for any problems (duplicates, etc.) and inform user.
				if (!CanRenameNode(tbxRename.originalText, tbxRename.Text))
				{
					e.Cancel = true;
					tbxRename.Show();
					tbxRename.BringToFront();
					tbxRename.Select(0, tbxRename.Text.Length);
				}
			}
						tbxRename.Invalidate();
		}



Was This Post Helpful? 0
  • +
  • -

Page 1 of 1