|
This is a perfect situation for using your own custom event. Something like this:
Create a delegate and event
public delegate void ConnectionChangedEventHandler(object sender, ConnectionEventArgs e);
public event ConnectionChangedEventHandler ConnectionChanged;
and a ConnectionEventArgs class
public class ConnectionEventArgs
{
public ConnectionEventArgs(bool isConnected)
{
m_IsConnected = isConnected;
}
private bool m_IsConnected;
public bool IsConnected
{
get { return m_IsConnected; }
}
}
then make the InternetConnection call a method
private void InternetConnectionAvailable()
{
OnConnectionChanged(new ConnectionEventArgs(true));
}
protected virtual void OnConnectionChanged(ConnectionEventArgs e)
{
if (ConnectionChanged != null)
ConnectionChanged(this, e);
}
Now you can subscribe to the ConnectionChanged event and update the StatusStrip
MyClassInstance.ConnectionChanged += new MyClass.ConnectionChangedEventHandler(MyClassInstance_ConnectionChanged);
void MyClassInstance_ConnectionChanged(object sender, ConnectionEventArgs e)
{
}
[edit] This is (obviously) also reusable for when it's not available too
private void InternetConnectionUnavailable()
{
OnConnectionChanged(new ConnectionEventArgs(false));
}
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)
modified on Thursday, October 16, 2008 1:07 PM
|
|
|
|
|
Hi,
Does someone know if it is possible to know if characters that was received, was received from the Keyboard or from the Barcode scanner?
Thanks
|
|
|
|
|
If your scanner is like ours, then no.
I would suggest you try asking the manufacturers of the scanner.
|
|
|
|
|
I am in need of the same thing. We use symbol scanners and I know that I read somewhere that most manufactures have a dll file to integrate with your applications. This hasnt been something I have looked into yet but will be very shortly. Can you let me know if you find out something, or maybe we can help each other complete this?
|
|
|
|
|
Brad,
Did you see the comment from Dave Kreskowiak, i think this will work. Your scnner should come with a form containing different bar codes. These are used to configure the scanner.
Cheers
|
|
|
|
|
Yes I saw that, and I think that is what I am going to do. I wish I did not have to do this as I like the barcode application to send just the barcode so it can work with other things I have but appears to be the only choice.
I use the POS-X Xi3000 ( http://www.posguys.com/barcode-scanner_3/POS-X-Xi3000_716/XI3000U_9177/[^] ) which is a great scanner, but I wish they had the ability to capture the scanner just like Symbol does.
|
|
|
|
|
You could try to measure the time delay between one char and another.. Barcode readers can be configurated to send the chars one after the another very quickly, humans can't
|
|
|
|
|
If it's a keyboard wedge scanner, then no, there's no way to tell.
Though, most scanners will let you setup a preamble/postamble sequence that the scanner pre-/post-pends to the data it "types", like adding "@@" to the string. So, if you scan a barcode of "123456789", the scanner actually sends "@@123456789". How I've done it in the past is to set my form's KeyPreview to True, and in the KeyDown event of the form, I look for the "@" character (in this example). If I keep getting the preamble sequence, then I know the next numbers I get are for the barcode and I redirect that data appropriately.
|
|
|
|
|
I am trying to figure out the best way to integrate this so that it can be customizable. My barcodes are always 12 characters long but you never know what might change in the future. So my thought is to look for two @@ which means were starting the barcode and then two @@ means the barcode has ended. I have activated the forms keypreview so I can now watch the keys on KeyPress. The problem I am having is trying to figure out the best way to make this dynamic and customizable by a config file incase the user wants to use three #'s instead of @.
private static string ConfigBarcodePreSuffix = "@";
private static int ConfigBarcodePreSuffixTimes = 2;
private static string Scanned_BarcodeText = "";
private static bool Scanned_BarcodeBeingScanned = false;
private static int Scanned_PreSuffixFoundTimes = 0;
private void frmEventTicketVerify_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar.Equals(ConfigBarcodePreSuffix))
{
if (!Scanned_BarcodeBeingScanned)
{
if (Scanned_PreSuffixFoundTimes == ConfigBarcodePreSuffixTimes)
{
Scanned_BarcodeBeingScanned = true;
}
}
else
{
if (Scanned_PreSuffixFoundTimes == ConfigBarcodePreSuffixTimes)
{
Scanned_BarcodeBeingScanned = false;
}
}
Scanned_PreSuffixFoundTimes++;
}
else
{
Scanned_PreSuffixFoundTimes = 0;
}
if (Scanned_BarcodeBeingScanned)
{
Scanned_BarcodeText += e.KeyChar.ToString();
}
else if (!Scanned_BarcodeText.Trim().Equals(""))
{
MessageBox.Show(Scanned_BarcodeText);
}
}
I am just starting to test this code, and I am not the best at C# so if you see any improvements or bugs I would be greatful.
|
|
|
|
|
Well, I didn't do much beyond glancing at the code, but I can tell you you're going about this wrong. The prefix can be any combination of characters (usually - depends on the barcode scanner) and doesn't have to be the same character repeating. On top of that, it's not a good idea to use the same combination of chracters for the pre and postambles. You won't be able to tell the difference between the start and stop combinations.
|
|
|
|
|
Hi,
I'm new to c# and was wondering if there is a quicker way of doing to following code without using the try and catch method as it is slow.
int result;
try
{
int str1_num = int.Parse(str1.Replace(",", ""));
int str2_num = int.Parse(str2.Replace(",", ""));
if (lvi1.ListView.Sorting == SortOrder.Descending)
{
if (str1_num < str2_num)
result = 1;
else
result = 0;
}
else
{
if (str1_num > str2_num)
result = 1;
else
result = 0;
}
}
catch
{
if (lvi1.ListView.Sorting == SortOrder.Descending)
result = String.Compare(str1, str2);
else
result = String.Compare(str2, str1);
}
Cheers
Fly
hmmm pie
|
|
|
|
|
Hi,
have a look at
int.TryParse().
This will avoid using try-catch.
Regards
Sebastian
|
|
|
|
|
As mentioned in the other post, use the TryParse method.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
Hello,
I am making a MSI setup with VS 2005 and have a custom action DLL added. I've been searching for a solution for my problem for a week now... My problem is exiting the custom action when the user clicks cancel on my dialog. The issue is that if I throw a InstallException, I get a error message box that refers to unhandeld exception. How can you exit a the installation from MSI without having this error message box? By exit I mean, rollback...
|
|
|
|
|
In Rollback part just add the dll...
I think it should work...jus try it
|
|
|
|
|
I added to rollback my dll too, the problem is: if I call Rollback directly nothing happens, if I say 'throw new InstallException("Canceld by user");' it rolls back nicely but before that, a general error MessageBox is shown...
|
|
|
|
|
Hello my friends!
I wants to create a chat application as client-server (one server and multiple clients). Please help me that which way is best to make it. With Sockets or Remoting objects (HttpChannel or TcpChannel)?
As you know if increases clients, server traffic is a serious problem.
Please describe your advices and suggestions...
Thanks.
|
|
|
|
|
You have two options for this:
1) Do some [deleted] research (qv google)
2) Post your requirements on rent-a-coder
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
Hi
What i want to do ?
I am displaying a picture in picture box
When user drags the picture then it has to appear in the another picture box
What i Did ..
private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
isdragged = true;
}
private void pictureBox2_MouseEnter(object sender, EventArgs e)
{
if (isdragged == true)
{
pictureBox2.ImageLocation = picpath;
isdragged = false;
}
}
isdragged is a boolean variable ....
picpath is a string i have stored the image location
After clicking on the picturebox1 and dragging it to the picture box 2 .. private void pictureBox2_MouseEnter event is not raising
I mean to say no effect when mouse enters into the picturebox2
I know i have done a mistake somewhere
Please tell me what i must do to solve this
(* Dont tell me to read a basic book .. i have read it twice ...*)
Joking
Thanks and Regards
If You win You need not Explain............
But If You Loose You Should not be there to Explain......
|
|
|
|
|
If you click and drag, you don't get any MouseUp event in the first picture box...
Krazy Programmer wrote: (* Dont tell me to read a basic book .. i have read it twice ...*)
Third time is the charm.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Guffa wrote: Third time is the charm.
YES , I know someone will tell this .. but not the correct answer
Anyway Thanks
I will be reading it again
If You win You need not Explain............
But If You Loose You Should not be there to Explain......
|
|
|
|
|
Krazy Programmer wrote: but not the correct answer
I think that it is. If you don't understand that you don't get an MouseUp event on a control where you don't release the mouse button, you are clearly missing some of the most fundamental ideas of the graphical interface and the event handling. The logical solution would be to go back and fill in the gaps.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
why drag?
why dont you browse a picture and load it in a picturebox?
OpenFileDialog open_file_dialog = new OpenFileDialog();
DialogResult dialog_result = open_file_dialog.ShowDialog();
if (dialog_result == DialogResult.OK)
{
mypicturebox.ImageLocation = open_file_dialog.FileName;
}
After that, dont know if you want a path to the picture or load/save them from/to a database.
nelsonpaixao@yahoo.com.br
trying to help & get help
|
|
|
|
|
nelsonpaixao wrote: why drag?
Requirement is drag and drop
If You win You need not Explain............
But If You Loose You Should not be there to Explain......
|
|
|
|
|
Hi all,
A while ago I posted a question on this topic, and received a great response. I made use of the article posted by Sacha Barber called Beginners Guide To Threading In .NET Part 5 of n. In this article he uses the SynchonizationContext to marshall the background work to the UI thread.
But the thing is that when I send response back to a listview on the GUI thread x amount of time in quick succession the whole application just freezes / hangs.
Is this a bad idea doing it like this or am I just doing something wrong (maybe a different approach)
private SynchronizationContext context;
.....
.....
context = SynchronizationContext.Current;
if (context == null)
{
context = new SynchronizationContext();
}
.....
.....
try
{
for (int i = 0; i < (int)e.Argument; i++)
{
context.Send(new SendOrPostCallback(delegate(object state)
{
lViewTransactionHistory.Items.Add(lViewTransactionHistory.Items.Count.ToString(), DateTime.Now.ToLongTimeString(), 0);
}), null);
}
}
catch (InvalidOperationException oex)
{
MessageBox.Show(oex.Message);
}
The only programmers that are better those C# programmers are those who code in 1's and 0's |
Programm3r
My Blog: ^_^
|
|
|
|