handled is not a member of Eventargs - vb.net

I inherited this vb.net code and am a newbie vb.net programmer with old programming skills.
This problem exists in many places after calling a dialog box. After processing the dialog, if the enter key is pressed on the dialog instead of clicking OK, the enter key logic is then processed on the main form. This is undesirable and i need to just display the form.
It looks like "e.handled = True" may be the way to clear the key results, but it produces the "handled is not a member of Eventargs" error.
Can you please recommend the best way to handle this situation?
Thank You,
Brian
Private Sub mnuAbout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuAbout.Click
Try
'Get the menu off of the screen cleanly
Application.DoEvents()
dlgAbout.ShowDialog()
**e.handled = True**
Catch ex As Exception
Call modErrorHandler.ErrorProcedure(ex.GetType.Name, Me.Name, ex.Message, ExceptionClassName(ex), ExceptionMethodName(ex), ExceptionLineNumber(ex))
End Try
End Sub

Related

OnRead event from scanner (Motorla EMDK) fires continuously

(I'm using VS2008 with EMDK v2.9 with Fix1)
I have a form, where I declare my reader:
Private WithEvents barcodeReader As Barcode.Barcode = New Barcode.Barcode
I want it to be active only in one of the controls on the form, so I do this:
Private Sub txbAccount_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txbAccount.GotFocus
barcodeReader.EnableScanner = True
End Sub
And turn it off the same way in the Lost Focus event of that textbox.
Here is the OnRead sub:
Private Sub barcodeReader_OnRead(ByVal sender As Object, ByVal readerData as Symbol.Barcode.ReaderData) Handles barcodeReader.OnRead
If (readerData.HasReader) Then
Try
Dim ctrl As TextBox = Ctype(GetActiveControl(), TextBox)
If (ctrl.Name = "txbAccount") Then
ctrl.Text = readerData.Text
End If
Catch ex As Exception
MessageBox.Show("Error: " & ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)
End If
End Sub
The problem is: as soon as I enable scanner in the GotFocus event of the textbox, the OnRead event will fire over and over (with empty data) until I actually press the scan key, scan actual data - then it stops.
I've read that maybe the Handled property is not getting set properly, however I don't see property like that for this.
Quick question to answer is the handledis usualy within the e eventargs (although I dont see any in that routine just readerdata it may be in there!?
On a side, with barcode scanners they usualy use the sendkeys commands to simply pass string through to the system. These can be trapped easily by using any of the OnKeyPress / OnKeyDown... etc. If you wanted to go down this route, you'll need to take each keypress / down as aan individual character, whereas your barcode.OnRead might do all that for you. (Again I havent used the EMDK you reference).
Lastly 'usualy' barcode scanners end with a cr (carriage return) some barcode scanners can turn this off, or change these in settings. If not this might be where the e.handled referenced elsewhere is talking about. This would be something like ..
if e.KeyChar = Chr(Keys.Enter) then
e.handled = true
end if
This would stop the send going to the object (textbox) and therfore not losing focus (as the enter key wasn't passed)
Hope this helps.. a bit :)
Chicken

Issue with radio buttons and message boxes in Visual Basic

In my application for Visual Basic, I have two radio buttons on the third TabPage. I scripted the "No" button to make a message box pop-up if you click it, but when I test it, instead of just showing the message once, it showed the same message again when I selected other option, "Yes".
I tried doing multiple things, but nothing worked. For the radio button, I did a simple line of code like this at first:
MsgBox("insert text here", MsgBoxStyle.OkOnly, "insert title here")
After I found out it appeared when you changed the selection to Yes, I tried doing this:
If RadioButton26_Select() = True Then
MsgBox("insert text here", MsgBoxStyle.OkOnly, "insert title here")
End If
Obviously, that didn't work either. In the first line of code for that radio button, I changed the RadioButton26_CheckedChanged to RadioButton26_Select:
Private Sub RadioButton26_Select(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton26.Select
That line I changed didn't have the () after the Selects, so I put the () after after all the Selects. That didn't work either.
So, I'm really confused here. Any help would be appreciated.
You want to use the RadioButton.Checked property. It indicates whether the RadioButton is "selected" or not.
You should also do it in the CheckedChanged event since that is raised every time the Checked value changes.
Private Sub RadioButton26_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton26.CheckedChanged
If RadioButton26.Checked = True Then
MessageBox.Show("insert text here", "insert title here", MessageBoxButtons.OK)
End If
End Sub
As you see I'm using MessageBox.Show() rather than the MsgBox() function. I recommend you to do so as well since the MsgBox() function exists purely for backwards compatibility with VB6, whereas MessageBox.Show() is the native .NET-way of doing it.

Avoid refresh event in a WebBrowser control?

I am using the GEPluginControl in VB.NET (VS2010).
My app works fine. I am using the GEWebBrowser control (included on the GEPluginControl), and I am able to show the information in the Google Earth format.
However, I am having troubles when the GEWebBrowser control Refresh method is called. When this happens, the GEWebBrowser starts to fail (the earth disappears and I am not able to reload it again).
I am not calling the Refresh method explicitly. I think this method is called automatically in the following case: when the user close the window, I'm catching the event Form_Closing, in order to ask the user if really wants to exit. If the answer is No, the user will stay on the app, but the GEWebBrowser control appears blank!. I can hear the sound associated to the refresh method, so I think this method may be my trouble.
Here is the Form_Closing event code:
Private Sub frmPrincipal_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
If MessageBox.Show("Quit", "Really want to exit?", _
MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes Then
'App end.
server.Stop()
Else
'User decides to stay.
e.Cancel = True
End If
End Sub
Does anybody knows how to avoid the WebBrowser (GEWebBrowser in this case) to execute the refresh method? If anyone knows how to solve this in any other way, I would still be very grateful.
You could try this (not guaranteed to work):
Private Sub StopRefresh(sender As System.Object, e As System.EventArgs) Handles WebBrowser1.ProgressChanged
WebBrowser1.Stop()
End Sub

Ok button in VB.net

I have a form that contain a combobox, I'm inserting an error check to check if the user hit the ok button before selecting a valid value from the combobox it mask the error and keep the form on focus, till the user select a proper value, but in my case after raise the error the application still close after i press Ok, would you help me identify my mistake
here is my code
Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
Try
If SymbolComboBox.SelectedValue Is Nothing Then
Throw New Exception()
Else
ErrorProvider1.SetError(SymbolComboBox, String.Empty)
Me.DialogResult = System.Windows.Forms.DialogResult.OK
Me.Close()
End If
Catch ex As Exception
ErrorProvider1.SetError(SymbolComboBox, "Error")
End Try
End Sub
Thank you in advance
Jp
Is your OK button the default accept button for the form ? If so, I beleive it will always return System.Windows.Forms.DialogResult.OK no matter the outcome, unless you specifically cancel the action. I do not remember how to cancel the action though, but if it's the case, I sugesst you remove that AcceptButton property of your form.
OR,
Is it possible that SymbolComboBox.SelectedValue is never 'Nothing' even when nothing is selected (like an empty string) ? I would use selectedIndex instead and check if it's equal to -1.
Hope that helps.
I'm not sure, but I do know that using exceptions like this to control program flow is a bad technique, and in this case unnecessary:
Private Sub OK_Button_Click(ByVal sender As Object, ByVal e As EventArgs)
Handles OK_Button.Click
If SymbolComboBox.SelectedValue Is Not Nothing Then
ErrorProvider1.SetError(SymbolComboBox, String.Empty)
Me.DialogResult = System.Windows.Forms.DialogResult.OK
Me.Close()
Else
ErrorProvider1.SetError(SymbolComboBox, "Error")
End If
End Sub
Why not look at using a required field validator to do this? Are you doing Web forms or Win Forms development? Also what is the value of SymbolComboBox.SelectedValue when you get this issue?

VB app not ending

I am using Visual Basic 2010 and I am makeing a simple login app it prompts you for a username and password if it gets it right I want to open a form then close the previus one but when I do me.close it ends the program and I can't go on
I am positive its working because I get the right password and username ut I can't close the first windows
I tried to hide it but when I do I cant close it and the program goes on without quiting and with a hidden form
I heard rumers that there is Sub that can control the x in the corner
if there is one that would probably solve my problem but I can't find it heres the code for the login form
Public Class Main_Login
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If TextBox1.Text = "My Name" And TextBox2.Text = "mypassword" Then
Contentsish.Show()
Me.Hide()
Label3.Hide()
Else
Label3.Show()
End If
End Sub
End Class
Then the Form if you enter the right login info
Public Class Contentsish
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Label1.Hide()
Timer1.Stop()
End Sub
End Class
how can I fix this problem?
Go into your project settings and set the application to close when the last form closes and not when the startup form closes.
edit: I just checked some of my VB.Net 2k8 code. What I do is create a new instance of the "child" form, do any initialization that I need, call .Show() on it, and then call .Close() on the current form (Me.Close()). Probably not the best way to do things, but it works for me. This is with the project setting I described earlier set. This allows me to exit from the child form or "logout" if needed.
Two other ways you can do this, in addition to Crags:
Load the main form first, then load the password from the main form.
You can use a separate vb module and use the Sub Main for the startup (you specify this in Project Properties, Application, Startup Object), then load the two forms from Sub Main.
So what happens if the login is incorrect? Sounds like you might want to show the login form using ShowDialog, maybe in your Main() before calling Application.Run(new FormMain());