|
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.
|
|
|
|
|
Hi,
I've solved my problem, be it in a manner which could as well be posted under coding horrors:
In the validating event of the maskedTextBox I call on a timer (which was added to the userControl), and let its Tick event set the focus.
private void maskedTextBox1_Validating(object sender, CancelEventArgs e)
{
if (this.maskedTextBox1.Text == "0")
{
timer1.Start();
e.Cancel = true;
}
}
private void timer1_Tick(object sender, EventArgs e)
{
this.maskedTextBox1.Text = "1";
this.maskedTextBox1.Focus();
this.maskedTextBox1.SelectAll();
timer1.Stop();
}
Cheers.
|
|
|
|
|
I spent several hours trying to get this working, and to no avail until I stumbled upon your answer.
Whatever dark magic you've applied to this task in order to arrive at using a timer, I take it your journey as a sorcerer is already a colourful one.
Thanks alot sir.
|
|
|
|
|
|
myventsi wrote: I don' t get the structures of connections and etc
This [^]is possibly one of the simplest example you could find.
Anyways, you need to buy a good book on C# and start reading it.
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
Suppose I want to call a function whenever I'll press Control + N together.
Now I know I need to catch the keyPress event. But how can I catch two key in one event..?
Thanking In Advance
Johnny
|
|
|
|
|
You need to use either KeyDown or KeyUp events.
if (e.KeyData == Keys.N && e.Modifiers == Keys.Control)
{
}
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
|
Hello,
I have a web site with files and direcotires (with files and other directories and files.....in each).
I need to find a particular file in this site (i will provide the main site and it will search recursively inside it and inside the folder to find the file i need). How can i do it?
|
|
|
|
|
First of all this should be in ASP.Net forum.
Use the DirectoryInfo and FileInfo classes to perform the search.
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
ok,
And it can search in web sites too?
BTW- i want to do it in C# windows application and not in ASP.NET
|
|
|
|
|
Well, that can do the search everywhere provided you have the read access in that website.
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
OK . But in which format do i need to write the website URL?
like this?
DirectoryInfo myDir = new DirectoryInfo("http://www.yahoo.com");
?
Or how?
|
|
|
|
|
Heloo Experts!!!
I am upadating date in my grid.on refresh button click it must show upadated date. i m using Datagrid.refresh() method for same.But cant work;
tel me way.using C# & SQL 2005
Please help!!
|
|
|
|
|
Hi my friends;
I have a different problem. I have a main form that is MDI parent of other forms. I use speech recognition, and I started it as a thread in my main form. It works fine while opening child forms or closing them. But problem begins here. For example I have an active MDI child that have a method or button click event. How can I call the method of my active form from it's MDI parent. I want to do this because I use speech recognition, I want to guide program with my voice commands. Like following I want call DoJob method.
Form frm = this.ActiveMdiChild;
frm.DoJob();
Thank you.
|
|
|
|
|
Not sure which exactly is your problem, but you can do it this way:
1) In the child form, the DoJob() method must be either public or internal (in order to enable access from the parent form).
2) In your parent form you can do something like:
ChildForm cf = (ChildForm)this.ActiveMdiChild;
cf.DoJob();
where ChildForm is your child form's class name.
2+2=5 for very large amounts of 2
(always loved that one hehe!)
|
|
|
|
|
You mean you need to call the method accros threads? If so:
frm.Invoke(new MethodInvoker(delegate() { frm.DoJob(); }));
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Hello Friends.
Suppose I have two functions name
GetBUUser(); && GetISUser(); And both these function call a function name
LoadUserBUStatus(); Now in LoadUserBUStatus() function how do I know which is the caller function..? I hope I made myself clear..
Thanks in Advance..
Johnny
|
|
|
|
|
You need to use Reflection and the Stack. Check out this[^] article.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Ok, I'll bite, why not use a wherefrom parameter, reflection and the stack seems both convoluted and expensive. I can understand if he has no control of the design of the calling methods but he implies he is writing them.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
When I read the question I immediately remembered needing to do something like this before and how I solved it. It was painful which is why it's imprinted on my memory and popped straigt to the tips of my fingers.
In my situation, I couldn't alter the parameters received without breaking other stuff (I can't remember why an overload wasn't allowed, but there was a reason), so sending an additional parameter in the calling method wasn't an option for me.
I agree, a 'whereFrom' parameter would definately be easier for the OP.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
When playing with the stack at runtime, remember that the JIT is allowed to perform inlining, so stack frames might disappear in release build (possibly even depending on the installed .NET version - the inlining heuristics are tuned from time to time).
You'd have to mark all three GetBUUser(), GetISUser() and LoadUserBUStatus with MethodImplOptions.NoInlining to be safe from that.
But on 64-bit .NET, even that isn't enough: there the JIT will perform the tail call optimization, which can also cause stack frames to disappear. Unfortunately, there's no way to disable tail calls.
You should avoid analyzing the stack at runtime at all costs.
|
|
|
|
|
Why not pass in a WhereFrom parameter?
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Dear All,
currently i am using Socket class to send and receive files from FTP.
every thing works fine and I am really happy with that. My concern is i can download files at fixed number of bytes as i am fixing my buffer to be send to server at 16*1024 bytes (16KB). I am looking for a method where i can download files from ftp at my internet bandwidth and the same should apply for uploading too.
i am looking to hear from u guys
Abdul Rahaman Hamidy
Database Developer
Kabul, Afghanistan
|
|
|
|
|