|
in >> TextBox tb = sender as TextBox
what is sender? i have to replace sender with some other things right?
can i write the conditions which u typed under private bool.
do i need to type something in OnKeyPress property?
thanks i've learnt quite a lot from u =)
|
|
|
|
|
nidhelp wrote:
what is sender? i have to replace sender with some other things right?
No, the event has an object called sender. Did you not create the event yet ? I did it this way instead of using a variable directly precisely so that you didn't need to change the code I gave you.
nidhelp wrote:
can i write the conditions which u typed under private bool.
You can set up a property if you'd like. Then you need to change the variable name though.
nidhelp wrote:
do i need to type something in OnKeyPress property?
OnKeyPress lets you check every time the user types. If they are pressing a button to do something and you need THEN to check if the code is valid, forget the events ( although the Validating event may be worth a look, I know nothing about that ), and then it would make sense to make it a private property, to encapsulate this piece of functionality.
nidhelp wrote:
thanks i've learnt quite a lot from u =)
No worries, always glad to help.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
sorry but i dont get u... do i create KeyPressEvent n put those codes inside it?
|
|
|
|
|
If you want to validate whenever a key is pressed, yes. If you always need a valid code, then I'd go with the code that accepts nothing else ( unless it's some sort of licence key ). If you don't always need it, then I'd not bother with the event, because people can type what they like, you can proceed with and without a valid value ( although it would be better for the UI to tell people the value was not valid ). Then you can instead do this check when the button is pressed that causes the value to be used.
I'm about to leave for 2 days, so that's the end of my help for now. Good luck...
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
If you are using a textbox, you can handle the key press event and process the necessary logic to allow/disallow certain characters from being entered. Here's some code below. I have not tested it but the logic is there i believe:
private void tbEditor_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if(e.KeyChar == (char)8)
e.Handled = false;
else if(Char.IsLetter(e.KeyChar) == true && (tbEditor.Text.Length == 0 || tbEditor.Text.Length == 8))
e.Handled = false;
else if(Char.IsDigit(e.KeyChar) == true && (tbEditor.Text.Length > 0 || tbEditor.Text.Length < 8))
e.Handled = false;
else
e.Handled = true;
}
<font=arial>Weiye Chen
Life is hard, yet we are made of flesh...
|
|
|
|
|
hi
im not supposed to disable any keys from being entered into the textbox.. the user is free to type n my app shd only open up a form when he types in a correct format..
correct format is a letter, 7 numbers, a letter..
i also have to make sure the first letter is S or s or F or f.. as long as the first letter is not correct, the form will not open..
|
|
|
|
|
I got this to work with a combination of both ways. Using the Validating method, and a RegularExpression.
Just to confirm - the pattern you wanted was:
s,S,f or F at the start
7 numbers
and upper or lowercase letter at the end
which I represented as the reg ex: [sSfF]\d{7}[a-zA-Z]
In the form designer, highlight your textbox and look at the Properties grid. Swap it to events using the little lightning symbol. Scroll until you see an event named Validating . Double-Click inside the textbox to the right of the event name - this should do 2 things
1) Jump to the code-behind view
2) Enter the stub of an event...mine started life looking liek this:
private void textBox1_Validating(object sender, System.ComponentModel.CancelEventArgs e)
{
}
The two arguments passed to this method are very useful.
sender - is the thing that sent this event (the textbox in this case)
e - is the event arguments, in this case of type CancelEventArgs . This type of event arguments has a Cancel property which can be set to true for this event to indicate that the contexts of the text box are NOT valid (hence the event name validating.
So back to the problem. In pseudo-code:
if textbox is not valid<br />
set Cancel to true
this can be done in the following two lines
TextBox tb = sender as TextBox;<br />
e.Cancel = !Regex.Match(tb.Text,@"[sSfF]\d{7}[a-zA-Z]").Success;
However, to explain this
1) Cast the sender to type TextBox
TextBox tb = sender as TextBox
2)Determine if its text is valid:
bool isValid = Regex.Match(tb.Text,@"[sSfF]\d{7}[a-zA-Z]").Success;
3)if not valid, set Cancel to false
e.Cancel = !isValid;
end result: until you enter the correct sequence of characters into the textbox you are unable to tab out or close the form.
|
|
|
|
|
i just finished reading n doing the top half of what u typed only but i want to thank u already.. u r v detailed n i cld follow through n understand your instructions easily.. hey thanks! =)
i'll be reading n doing the bottom half after i type this.. hopefully it works..
=)
|
|
|
|
|
nidhelp wrote:
u r v detailed n i cld follow
If only I could understand your "english" anywhere near as well as you could understand my explaination we'd both be happy.
|
|
|
|
|
u r v detailed n i cld follow >> you are very detailed and i could follow =)
do u understand my "english" or do i have to type properly? sorry if you didnt.
|
|
|
|
|
Generally, this kind of !33tspeek is not really welcome here.
On the one hand it gives us the impression of talking to a 14-year old, on the other hand it's rather rude if people take their time to answer your problems and you don't even spend enough time to write properly.
mav
|
|
|
|
|
yes ok i understand now..
i just thought that people would understand !33tspeek easily..
so sorry about it..
|
|
|
|
|
I need to clarify this...
My code WAS like this:
private void button3_Click(object sender, System.EventArgs e)
{
if(Validate(textBox4.Text))
{
if (tabControl1.TabPages.Contains(tabPage6)) {
}
else
{
tabControl1.TabPages.Add(tabPage6); }
}
else
{
// show invalid username dialogbox
}
}
// Conditions to determine whether a tab page is to be displayed when Go button is clicked
private bool Validate(string Val)
{
if(Val!="")
{
if(Val.Length==9||Val.Length==12)
{
return true;
}
else
return false;
}
else
return false;
}
I donno how to edit my codes with the codes u gave me to make my app run..
can u teach me what's going on?
In fact, I also need to open a tab page if the text input is made up of 12 digits..
Therefore, a tab page should open when the text input is \d{12} OR [sSfF]\d{7}[a-zA-Z]..
The user is allowed to key in anything he wishes but the tab page will not open if what he entered doesnt meet the conditions set..
Thank you!
|
|
|
|
|
I'll continue to help when you eliminate txtspk from your posts. Go click the modify link on the above and type in English, and i'll check back very soon.
|
|
|
|
|
who can tell me how to active FormB from FormA, A(MainForm) and B(has been minimized) are in one application,but are not parent and child.
If FormA and FormB are belong to diffent applicaions what should i do to achieve the same goal?
thanks! ^_^
|
|
|
|
|
First
to activate Maximize or Minimize form from another one
windows forms has property called WindowState
so code somthing like this
anotherForm.WindowsState=FormWindowState.Normal<br />
MCAD
|
|
|
|
|
if form B has existed, how could i know, and how to find it.
thanks!
|
|
|
|
|
what do you mean by form is existed?
MCAD
|
|
|
|
|
as you dont answer my question if you want to search for
a window in windows use FindWindow API which will give
you the handel of the form
MCAD
|
|
|
|
|
Windows API is what i need .
Thank u for your patience.
^_^
|
|
|
|
|
this will give you only handle to maxmize or minimize
you nedd to change windows style set like WS_MAXIMIZE
Note: there are another version of FindWindow named
FindWindowEx
MCAD
|
|
|
|
|
Hi, Putting in documentation into code c# and I keep getting a million warnings because I have xsd schemas that have been generated automatically for me.
Is there someway to exclude the xsd schemas from the documentation NDoc build process.
I am currently using VS2003.
Thanks
David
|
|
|
|
|
Hi,
I am creating new Word documents using C# (automation) and would like to save the documents to SQL Server directly (bypassing the filesystem). Has anyone tried to do this? If so, how?
I already now how to upload documents to SQL Server. I just don't know how to go from a Document object created using C# to SQL Server directly.
Thanks for any pointers,
roccom
|
|
|
|
|
you can save word document as you save image
|
|
|
|
|
I've done something similar but not exactly something what you want to do. I've storred pictures in a database bypassing the file system. I was using PHP and MySQL to do this. In the MySQL database you have to have a table that is of type BLOB. Then you need to encode your word document and store the encoded object in the database. When you retrieve it you just need to do the opposite. Sorry I'm so vague about it but it's been a while since I did this project. If you do a websearch on "storring binary objects in a database" I'm sure you will find something more specific.
|
|
|
|