|
tarun1991,
Do I need to do this for each textbox? Your example refers to textBox2 only. I have 3 textboxes total.
-Rob
|
|
|
|
|
Rob, it depends on you. At which point you are creating its object, you need to create its event.
If you create the control inside the loop, you have to declare its location and size. Here you will call it as :
for(int i =0;i<3;i++)
{
TextBox textBox = new TextBox();
textBox.Text .....
textBox.Location....
textBox.size....
textBox.KeyDown += (press TabButton) //whole next coding will automatically generated.
}
//This part will generate automatically.
public void textBox_KeyDown(Object sender,Eventargs e)
{
// here you need to code you statement part.
}
Regards
Tarun
|
|
|
|
|
Rob, There is also an another way. You need to write the code one time and set the all textboxes event name as textBox_Keydown. This can be done, if all the textbox performs same function with same behavior.
|
|
|
|
|
In addition to the method that Dave shows, you can also set the Form's KeyPreview property to 'true, and catch the Enter Key in a KeyUp EventHandler:
private void Form1_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
Console.WriteLine("enter key seen");
}
} If you have both an 'AcceptButton defined for the Form, and KeyPreview set to 'true, and a KeyUp EventHandler: both Events will fire, with the Button getting a "virtual click" first.
However, I think using either of these two techniques is (almost always) a mistake because most applications are going to need to perform some kind of validation on user entry before "submit."
With either of these two techniques, you won't know where the Enter key Event came from (okay, there is a work-around for that using 'ActiveControl, but I'll skip over that).
imho a much better technique is something like this:
private void button1_Click(object sender, EventArgs e)
{
Console.WriteLine("button click ... active Control is {0}", ActiveControl.Name);
}
private void TextBoxes_KeyUp(object sender, KeyEventArgs e)
{
if (! (e.KeyCode == Keys.Enter)) return;
button1.Enabled = false;
TextBox activeTextBox = sender as TextBox;
string currentText = activeTextBox.Text;
if(currentText.Where(ch => Char.IsDigit(ch)).ToList().Count > 3)
{
Console.WriteLine("fail: TextBox{0} has more than 3 digits", activeTextBox);
activeTextBox.Focus();
e.Handled = true;
return;
}
switch (activeTextBox.Name)
{
case "textBox1":
if (! (currentText.Where(ch => Char.IsLetter(ch)).ToList().Count == 4))
{
Console.WriteLine("fail: TextBox1 does not have 4 letters");
activeTextBox.Focus();
e.Handled = true;
return;
}
break;
case "textBox2":
break;
case "textBox3":
break;
}
button1.Enabled = true;
button1.PerformClick();
} Note that you need to wire-up the KeyUp EventHandler to each of the TextBoxes you wish to validate.
Also, note that the decision to disable the Button used for "submit" reflects my own conviction that it is better to have UI controls that do not function if using them would have unknown side-effects, or allow errors.
While disabling the Button may not quite make sense in this example; my choice would be to enable the Button only when all 3 TextBoxes have validated content. Your Application design may not require this.
Writing code to keep track of which TextBoxes are currently validated, and to evaluate whether all TextBoxes have valid content is not difficult.
Validation is a good thing !
«OOP to me means only messaging, local retention and protection and hiding of state-process, and extreme late-binding of all things. » Alan Kay's clarification on what he meant by the term "Object" in "Object-Oriented Programming."
|
|
|
|
|
Bill,
In your example you use TextBoxes_KeyUp. When you use the name "TextBoxes" are you suggesting that each textbox requires this treatment? I wasn't sure if I used the KeyPress event for the form if it would work for all controls.
I used my newly acquired regex skills that I learned from CodeProject to perform the validation and it exactly meets the specifications for the project. Works great.
In testing this app, I seem to have a habit of pressing the enter key when the form is filled out. Since it feels natural to press the enter key to submit the form, I thought it would be a good idea to add this feature. That is where I'm at with this app at the moment. After submit is clicked, the heart of the program will begin to take place. That could spark a few discussions as I continue to develop the app.
-Rob
|
|
|
|
|
I am using Custom Featured MessageBox taken from codeproject developed by Xmen WK
while using this i am unable to change font size of the messagebox
|
|
|
|
|
There are many MessageBox realted articles on CodeProject; you don't tell us which one you are referring to.
Consider posting a message on the article with your question.
«OOP to me means only messaging, local retention and protection and hiding of state-process, and extreme late-binding of all things. » Alan Kay's clarification on what he meant by the term "Object" in "Object-Oriented Programming."
|
|
|
|
|
If you downloded the MessageBox source from CP .You can also look for what actualy the author has made with that hope you can find the solution from the source to change the font size.If you cont find it you can also request the same message to the author at the comment section of that article.
Can you paste the article link so that it will be check for the possible ways to change the font size .
|
|
|
|
|
PLease elaborate your requirement?
hi
|
|
|
|
|
If you mean this one: Custom Featured MessageBox[^], then don't post this here - if you got the code from an article, then there is a "new message" button at the bottom of that article, which causes an email to be sent to the author. They are then alerted that you wish to speak to them.
Posting this here relies on them "dropping by" and realising it is for them.
The original author appears to be still logging in, so he may respond - even to a 6 and a half year old article!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Hi,
I have fromOptions and I am showing a user control for every option using this code:
ucOptionsBarcode options_barcode = new ucOptionsBarcode();
options_barcode.Left = 270;
options_barcode.Top = 12;
options_barcode.Width = 500;
options_barcode.Height = 300;
this.Controls.Add(options_barcode);
I would like to change the code to loop through all user controls on the form, if the user control was already added earler then just BringToFront, otherwise Controls.Add it?
How can I do this please?
Technology News @ www.JassimRahma.com
|
|
|
|
|
Try:
Control found = null;
foreach (Control c in Controls)
{
if (c is ucOptionsBarcode)
{
found = c;
break;
}
}
if (found == null)
{
}
else
{
found.BringToFront();
}
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
modified 25-Dec-14 2:05am.
|
|
|
|
|
Message Closed
modified 26-Dec-14 0:58am.
|
|
|
|
|
The name did seem familiar.
What are you doing up at this time of night?
You realise Santa won't come until you are asleep?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
sorry what's :
bool Control found = null;
it's not accepting it?
Merry Christmas
Technology News @ www.JassimRahma.com
|
|
|
|
|
That's a typo...
It should be Control found = null, without the bool...
Skipper: We'll fix it.
Alex: Fix it? How you gonna fix this?
Skipper: Grit, spit and a whole lotta duct tape.
|
|
|
|
|
As Peter says, it's a typo.
Fixed.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
I have to generate and store bulk(almost 1 Million) pdf reports from a database to a LAN location.
Scenario: Here data is scattered in many tables. Need to fetch data from DB tables and then put them into a PDF format. These PDFs will be placed at a LAN location.
Question: Please suggest a best way (Whether batch job or crystal report in console application or any other suggestion) to do so.
Thanks in advance.
|
|
|
|
|
You should start by figuring out how you are going to convert this information into PDF format: using the iTextsharp library, a PDF printer driver, Web page, something else ... ?
|
|
|
|
|
There are more than 1 million records, thus it would be best if I can make a batch job for this.
Also for pdf format, crystal report will be feasible but the question is, if crystal report is feasible to take dynamic arguments and then will be able to export PDFs to the LAN location?
|
|
|
|
|
Listen to what the man said: don't start out with "oh I need a batch job", start with "how am I going to do the actual conversion?" and then work out how to automate that.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Member 11332969 wrote: I have to generate and store bulk(almost 1 Million) pdf reports from a database to a LAN location.
I seriously doubt that is a valid business requirement. Some one is confused.
Also is this supposed to be a one time effort? So three years from now exactly the same 'report' will still be valid?
But as noted else where start with creating one report just so you can measure how many resources it takes to generate it. Not to mention what resources you have available to create the report. But based solely on the requirements that you specified I would create an application that would do the following
1 Take input parameters that specified the 'range' of what should be create
2 Process that range sequentially and after each 'report' was generated create a entry in file to indicate it was complete.
3 Then 'send' the file to the 'lan' (whatever that means), Then make a different entry that it was successfully sent.
4 Repeat steps 2/3 till the entire 'range' is spanned.
Writing to the file above allows you to track that everything was done. It also allows you the option to restart if the app fails without redoing all of the work.
In terms of the specific technology necessary to create the report that depends on the content of the report. Crystal is ok but one can get by with other tools if necessary.
|
|
|
|
|
I have create windows application. I have a requirement of continuous stationary printing in vb.
|
|
|
|
|
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind.
Use the "Improve question" widget to edit your question and provide better information.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
OriginalGriff wrote: Use the "Improve question" widget Good luck to him trying to find it.
|
|
|
|