|
I would think that disposing the button would remove the connection to the event procedure.
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my homepage Oracle Studios
Discounted or Free Software for Students:
DreamSpark - downloads.channel8.msdn.com
MSDN Academic Alliance - www.msdnaa.com
|
|
|
|
|
|
Hi there,
I am writing an application to run on the compact framework.
The application accepts data from a usb barcode scanner and validate the entry against data held on a file read sequentially.
If the barcode data does not match the data on the file I want my user to be able to decide to accept the entry or not, so far so good.
I have a problem with my messagebox.show selection.
The problem is that the messagebox does not display for longer than 1/2 a second or so and code keeps running until the end of the method without stopping.
ps:The carriage return marks the end data input.
Here is the code:
// Textbox to catch the data from the USB scanner
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
try
{
if (e.KeyChar == 13) // Catch carriage return from barcode
{
string scannedData = textBox1.Text.Trim();
this.lblBarCode.Text = scannedData;
if (validate_data(scannedData) == false)
{
this.textBox1.Enabled = false;
DialogResult dlgRes = MessageBox.Show("BarCode data does not match, Accept entry ?",
"Validate BarCode",
MessageBoxButtons.YesNo,
MessageBoxIcon.Question,
MessageBoxDefaultButton.Button1);
if (dlgRes == DialogResult.Yes)
{
// TODO write to output file, don't forget system date !!
}
else
{
// TODO ignore input tidy up
}
}
else
{
// TODO write to output file, don't forget system date !!
}
}
}
catch (Exception z)
{
MessageBox.Show("Error " + z);
}
}
private Boolean validate_data(string scannedData)
{
int i = 0;
string lineData;
lineData = this.lstBoxFiles.SelectedItem.ToString();
i = lineData.IndexOf("-") + 1;
lineData = lineData.Substring(i);
if (lineData != scannedData)
{
return false;
}
else
return true;
}
}
Would any one be so kind as to explain what I am doing wrong.
Thank you
modified on Friday, July 11, 2008 9:55 AM
|
|
|
|
|
Is it the carriage return from the scanner that's invoking the button press on your message box?
If so try setting the e.handled property before showing your message box. Alternatively, most barcode scanners can be programmed to use the tab character instead of the carriage return - in fact that's the normal configuration in my experience. If you can configure it this way you can use the LostFocus event instead with no problems.
Dave
|
|
|
|
|
It is the carriage return invokes yes,
Thanks for your help, will try all this today
Thanks Dave,
modified on Friday, July 11, 2008 9:56 AM
|
|
|
|
|
Hi there,
I could still not make it work.
What I noticed is that if I display a messagebox in my keypress event when I run the code the messagebox displays then disappears without human intervention but the next messagebox does not?
I had to put two messageboxes one after the other in order to achieve my goal.
Pretty ugly I admit. I am missing some fundamental understanding somewhere.
I am running the code on an psion 8515, Compact Framework 3.5, OS windows CE.NET version 5.
Here is the code for anyone interested
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
try
{
if (e.KeyChar == (char)Keys.Return) // Catch carriage return from barcode
{
MessageBox.Show(""); // do not delete. I do not understand why but if we remove this event then the next message box does not stop.
e.Handled = true;
this.lblBarCode.Text = textBox1.Text.Trim();
if (validate_data(lblBarCode.Text) == false)
{
this.textBox1.Enabled = false;
switch(MessageBox.Show(" BarCode does not match, Accept BarCode ?",
"Validate BarCode", MessageBoxButtons.YesNo,
MessageBoxIcon.Question,
MessageBoxDefaultButton.Button1))
{
case DialogResult.Yes:
// TODO write to output file, don't forget system date !!
MessageBox.Show("Yes ");
break;
case DialogResult.No:
MessageBox.Show("No ");
// TODO ignore input tidy up
break;
}
}
else
{
// TODO write to output file, don't forget system date !!
}
}
}
catch (Exception z)
{
MessageBox.Show("Error in btnOpenSort_Click" + z);
}
}
private Boolean validate_data(string scannedData)
{
try
{
int i = 0;
string lineData;
lineData = this.lstBoxFiles.SelectedItem.ToString();
i = lineData.IndexOf("-") + 1;
lineData = lineData.Substring(i);
if (lineData != scannedData)
return false;
else
return true;
}
catch (Exception z)
{
MessageBox.Show("Error in validate_data " + z);
return false;
}
}
Thank you,
Scalpabob
modified on Friday, July 11, 2008 9:57 AM
|
|
|
|
|
Sorry for the delay in responding - I've only just checked this thread!
I stripped your code a little so I could just run it on a form with one textbox and it works fine!
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
try
{
if (e.KeyChar == (char)Keys.Return)
{
e.Handled = true;
if (validate_data(textBox1.Text.Trim()) == false)
{
this.textBox1.Enabled = false;
switch (MessageBox.Show(" BarCode does not match, Accept BarCode ?",
"Validate BarCode", MessageBoxButtons.YesNo,
MessageBoxIcon.Question,
MessageBoxDefaultButton.Button1))
{
case DialogResult.Yes:
break;
case DialogResult.No:
break;
}
}
}
}
catch (Exception z)
{
MessageBox.Show("Error in btnOpenSort_Click" + z);
}
}
private Boolean validate_data(string scannedData)
{
return false;
}
Have you tested it just inputting data using the keyboard? If it works for you that way you need to look into the configuration codes for the scanner.
Dave
|
|
|
|
|
Thanks for your help.
Indeed it works fine.
|
|
|
|
|
You're welcome
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Expect everything to be hard and then enjoy the things that come easy. (code-frog)
|
|
|
|
|
Hi,
I am reading data from an xml file.
The xml is set up so that there could be line feeds for some of the lines.
When I get these data back in the immediate window I see \n which I believe indicates the carriage return for each line?
How can I get rid of these?
Thanks
"\n use master\n go\n IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[uspGetDomainName]') AND type in (N'P', N'PC'))\n BEGIN\n EXEC dbo.sp_executesql @statement =
...
...
...
|
|
|
|
|
arkiboys wrote: How can I get rid of these?
String.Replace()
/ravi
|
|
|
|
|
Is it possible to read a specific cell or a range of cells from a spreadsheet document?
Thank you
|
|
|
|
|
|
I am trying to calculate the AVG for fields in a SQL SERVER database for a specified time interval. There may be times when there is no data for this interval. What would be the SELECT statement which will not execute the AVG of data if there is no data. I have tried to use "WHERE field IS NOT NULL", but this still throws an exception and stops execution of the program.
|
|
|
|
|
Instead of where clause use ISNULL(FieldName,'1900-1-1')
Good luck
Kutty
|
|
|
|
|
hi,
i am new to windows services and i have created a windows service which works fine when i manually start and stop it. i have changed the property to start the service automatically. and i need the service to start at the time of machine logging in. but the service is not starting. help me with fixing this issue. and this service is not related to any software. what it does is when the service is started is saves a string to the event viewer. but its not automatically started even if its property is set to start automatically.
|
|
|
|
|
karthi84 wrote: at the time of machine logging in
The Service will start when the Operating System starts, not when a user logs in.
You could use a Scheduled Task to do that. Especially if the "Service" writes and then exits, that's not what services are for.
Services normally start when the system starts, and run continuously until the system shuts down.
|
|
|
|
|
thanks for the reply. my problem is fixed. the problem was it was depending on a service which starts after this service starts. so i have fixed with this issue and once again thanks for your answer.
|
|
|
|
|
Are you running on Vista?
Dave
|
|
|
|
|
thanks for your time for replying me. my problem is fixed. the problem was it was depending on a service which starts after this service starts. so i have fixed with this issue and once again thanks for your answer.
|
|
|
|
|
Im working on an image project which requires a lot of pointers. Ive recently had a smoothing function working where i loop over all the pixels and apply a smoothing function to the pixel. I've now been asked to seperate this function so mutliple functions can be used with the pixel loop.
The smoothing function worked in two parts, the first part set variables for use later in the function and the second part did the pixel loop and applied the smoothing to the image. Now i set the variables in one function, before i enter the loop, and then call a smooth function while in the loop. I tried to have a long* global to the class ,named _norm_buff, which is set in the first function and used in the second but after entering the smooth function the value at the address of the _norm_buff is reset to 0.
The line where the _norm_buff is reset
long* sum_buff = stackalloc long[this._width];
Could the stackalloc be overwriting the value in _norm_buff?
|
|
|
|
|
I'm reading up on encryption in .NET, but I don't fully understand the concept of digital signing. Could somebody help me out here?
- Alice and Bob each have a set of private and public keys. Alice has Bobs public key and Bob has Alices.
- Alice wants to send a message to Bob and sign it
- She hashes the plaintext and encrypts it with her private key, and embeds the sign into the message encrypted with Bobs public key
- Bob receives the message and sign and checks it by decrypting using alices public key and comparing the hash values
Now heres what I don't understand:
Alice encrypts the hash with her private key and Bob decrypts it using Alices public key -- I though you could only encrypt using public and decrypt using private, not the other way around.
Does anybody know? :/
|
|
|
|
|
http://en.wikipedia.org/wiki/Public-key_cryptography[^]
Look at the diagrams down the right hand side.
You send a private message by encrypting with the recipients public key. They decrypt with their own private key. This allows you to be sure only the intended recipient can view it, because only they have the correct private key.
You sign a message by encrypting it with your own private key. The recipient decrypts it with your public key. This verifies that it came from you, otherwise the decryption wouldn't have worked. But importantly the message isn't secret because anyone can decrypt with your public key as everyone has access to it. All you have done is verified the sender though.
Simon
|
|
|
|
|
I have a DataGrid that binds to a DataSet, bu specifying the DataSource and DataMember properties:
this.myGrid.DataMember = "Something";
this.myGrid.DataSource = this.myDataSet;
However, I wish to filter some data that it displays. More precisely, I wish to filter out or even replace (in a column in the DataGrid) some data according to another column value in the DataGrid.
Is there a way to accomplish that ?
Best wishes, D
|
|
|
|
|
Have a look at the DataView class desmond,
with it you are able to query the dataSet...
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
you.suck = (you.passion != Programming)
|
|
|
|