Click here to Skip to main content
15,903,816 members
Home / Discussions / C#
   

C#

 
QuestionFocus in ToolStripControlHost after validating cancelled Pin
netogg24-May-09 4:24
netogg24-May-09 4:24 
Hello,

I've embedded a MaskedTextBox in a UserControl and added it to the ToolStrip of a Form via ToolStripControlHost:

private void Form1_Load(object sender, EventArgs e)
{
ToolStrip1.Items.Add(new ToolStripControlHost(new UserControl1()));
}

In the Validating event of the MaskedTextBox in my UserControl the value of the Text is checked and if necessary corrected:

private void maskedTextBox1_Validating(object sender, CancelEventArgs e)
{
if (maskedTextBox1.Text == "0")
{
maskedTextBox1.Text = "1";
maskedTextBox1.SelectAll();
e.Cancel = true;
}
}

The user can give any input in the MaskedTextBox, validation should only occur when "leaving". If the focus "leaves" the MaskedTextBox (by the user clicking anywhere or tabbing), validation is performed.

If validation fails ( in this case Text = "0") a corrected value ("1") is set, no events (e.g. button clicks) occur outside the control and the control's text should be highlighted

After the value was automatically corrected (the user has been shown a warning... not relevant), he can now of course "Leave" without ado.

If the UserControl is added to a Form all the described behaviour occurs.

However as the userControl is put in a ToolStripControlHost I can't get the text of the MaskedTextBox highlighted after the validation of the maskedtextbox (inside the toolstrip) fails.

Any help on this would be sincerely appreciated.
AnswerRe: Focus in ToolStripControlHost after validating cancelled Pin
netogg29-May-09 23:53
netogg29-May-09 23:53 
GeneralRe: Focus in ToolStripControlHost after validating cancelled Pin
acolight17-Mar-11 10:27
acolight17-Mar-11 10:27 
Question[Message Deleted] Pin
hkjghkj124-May-09 4:03
hkjghkj124-May-09 4:03 
AnswerRe: DataGridView and mdb Pin
Manas Bhardwaj24-May-09 4:20
professionalManas Bhardwaj24-May-09 4:20 
QuestionKeyPress Event Pin
Saiyed Alam24-May-09 0:58
Saiyed Alam24-May-09 0:58 
AnswerRe: KeyPress Event Pin
DaveyM6924-May-09 1:22
professionalDaveyM6924-May-09 1:22 
GeneralRe: KeyPress Event Pin
Saiyed Alam24-May-09 16:37
Saiyed Alam24-May-09 16:37 
Questionsearch in site Pin
michaelgr124-May-09 0:42
michaelgr124-May-09 0:42 
AnswerRe: search in site Pin
Manas Bhardwaj24-May-09 0:57
professionalManas Bhardwaj24-May-09 0:57 
GeneralRe: search in site Pin
michaelgr124-May-09 0:58
michaelgr124-May-09 0:58 
GeneralRe: search in site Pin
Manas Bhardwaj24-May-09 1:18
professionalManas Bhardwaj24-May-09 1:18 
GeneralRe: search in site Pin
michaelgr124-May-09 1:31
michaelgr124-May-09 1:31 
QuestionRefresh Datagrid Pin
KIDYA23-May-09 23:20
KIDYA23-May-09 23:20 
QuestionCalling Method of an Active Form from the MDI Parent Pin
uygarer23-May-09 23:13
uygarer23-May-09 23:13 
AnswerRe: Calling Method of an Active Form from the MDI Parent Pin
Moreno Airoldi24-May-09 0:12
Moreno Airoldi24-May-09 0:12 
AnswerRe: Calling Method of an Active Form from the MDI Parent Pin
DaveyM6924-May-09 0:25
professionalDaveyM6924-May-09 0:25 
QuestionFunction Caller Pin
Saiyed Alam23-May-09 22:56
Saiyed Alam23-May-09 22:56 
AnswerRe: Function Caller Pin
DaveyM6923-May-09 23:02
professionalDaveyM6923-May-09 23:02 
GeneralRe: Function Caller Pin
Mycroft Holmes23-May-09 23:38
professionalMycroft Holmes23-May-09 23:38 
GeneralRe: Function Caller Pin
DaveyM6924-May-09 0:05
professionalDaveyM6924-May-09 0:05 
GeneralRe: Function Caller Pin
Daniel Grunwald24-May-09 4:32
Daniel Grunwald24-May-09 4:32 
AnswerRe: Function Caller Pin
Mycroft Holmes23-May-09 23:35
professionalMycroft Holmes23-May-09 23:35 
Questiondownload at internet bandwith with c# Pin
Abdul Rahman Hamidy23-May-09 22:26
Abdul Rahman Hamidy23-May-09 22:26 
Question[Message Deleted] Pin
hkjghkj123-May-09 21:28
hkjghkj123-May-09 21:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.