|
You're welcome
I are troll
|
|
|
|
|
Hey,
I have some problems with the KeyDown event. When a user keeps a key pressed, the KeyDown event keeps being fired. I don't want this to happen, I just want to trap it once so I know that the key is pressed. I use the KeyUp event to check if the key is released.
Can somebody help me out on this one?
Zaegra
Motivation is the key to software development.
|
|
|
|
|
Could you add a boolean flag and set it to true in key down and to false in key up. If the flag is true, ignore the event. Something like this in keydown:
if (keydown = false) then
keydown = true
... your other code ...
end if
and in keyup
keydown = false
|
|
|
|
|
You can't stop the event being fired.
What you could do is declare a boolean variable, e.g. keyIsDown, and set it to true in the KeyDown handler and false in the KeyUp handler. The variable would then be used to control whatever you're doing in the handlers.
Without knowing exactly what you are rying to do I can't suggest anything else.
Regards
David R
|
|
|
|
|
Well, I'd like to trap Key Combinations like Alt+F4 etcetera but I can't find a way to do this, because the event keeps being fired, so I get 20x Shift and 1x F4 Any suggestions on how to trap Key Combinations?
Motivation is the key to software development.
|
|
|
|
|
I'm a bit hazy on this since I've not used Key events for some years.
But here's my suggestion.
When KeyDown fires store the key code in a variable (as well as setting keyIsDown flag).
When the event fires again, if the current key code is same as previous just ignore it. When the code changes do whatever you have to.
One thing that stopped me using key events is that generally I wouldn't want to change the behavior of standard key combinations like Alt=F4.
Regards
David R
|
|
|
|
|
Are you checking them both at the same time, or one after another? The event gets fired alot, but firing an event doesn't eat away too much CPU-time. If you only need the combination of the keys, then try this;
Private Sub TextBox1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
If (e.KeyCode = Keys.F4 And e.Shift) Then
MessageBox.Show("Hit it, Sam!")
End If
End Sub
I are troll
|
|
|
|
|
Hi,
don't try anything that adds state variables (such as a KeyIsDown variable) since that is bound to fail under special circumstances (e.g. when the app looses focus in between a key going down and up again, the state variable will be incorrect on the next KeyDown, which then won't get processed since KeyIsDown is still true...)
You don't need to track the modifier keys (ALT, CTRL, SHIFT) at all, the system does that for you: you can get their immediate value at all times; in particular there is Control.ModifierKeys which always reflects the current situation; but there is even better: each KeyDown event has a KeyEventArgs which holds properties Alt, Control, Shift.
So simply check the key is F4 and Alt is true.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
I have this code written in VFP, I converted to VB.net and it seem it is working
If any one has any comment on the code about what should I use or not use or he have better idea, please say so
' This program capture CTRL+SHIFT, it can be changed to capture any combination
' Add Timer ,Command button to the form
' In the declaration
Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Integer)
Declare Function GetKeyState Lib "user32" Alias "GetKeyState" (ByVal nVirtKey As Long) As Integer
Const VK_SHIFT = &H10
Const VK_CONTROL = &H11
'Button1_Click
Me.Timer1.Interval = 1
Me.Timer1.Enabled = True
' After clicking, try to press CTRL+SHIFT or SHIFT+CTRL
' Timer1_Tick
Dim nKeySHIFT, nKeyCTRL
nKeySHIFT = GetKeyState(VK_SHIFT)
nKeyCTRL = GetKeyState(VK_CONTROL)
If nKeySHIFT <> 0 And nKeySHIFT <> 1 And nKeyCTRL <> 0 And nKeyCTRL <> 1 Then
MessageBox.Show("SHIFT + CTRL is pressed")
Timer1.Enabled = False
End If
Samir R. Ibrahim
|
|
|
|
|
Hi,
I wrote a program and I want to do a check with the version that is on the internet.
I create and adapt the file on the webserver when I have a new version
now I use:
wc = New Net.WebClient
Dim version As Byte() = wc.DownloadData(UriVersion)
Dim sHTTPver As String = System.Text.ASCIIEncoding.ASCII.GetString(version)
Dim vnCurrentVersion As System.Version = Functions.fgetProgramVersionNumber()
Dim nVersion As Double = Val(vnCurrentVersion.Build & "." & vnCurrentVersion.Revision.ToString("00000"))
Dim nhttpVer As Double = Val(sHTTPver)
Function fgetProgramVersionNumber() As System.Version
Dim VersionNo As System.Version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version()
Return VersionNo
End Function
this lines of code to check is there is a newer version.
however this methode seems not to increment all the time. When I compile on another computer it decrease. how can I have a beter control over the version with a automatic incresed number
|
|
|
|
|
OK, why are you going through all of this?? Why not just send the current program name and version number to a webserver on your server that responds with a True or False if there is a newer version? Then, you can download the latest version of the file and replace your application.
It seems like you're putting all the version checking code into the application itself when it should be on the server side.
|
|
|
|
|
Hi,
I think I need to write some phpcode to do that?
I think I have to update some DB on the server side also.
I never hade take a look on php nor asp
Jan
|
|
|
|
|
No, you don't need PHP to do that. If you've got IIS as a webserver, you can use C#, VB.NET, or any other .NET targeted language to do it. If you don't have IIS, then you can use Java.
jan212r wrote: I think I have to update some DB on the server side also
Why? The code is getting the new version from the server already, so there shouldn't be anything you change on the server. The WebService code would just use that same number as the new version.
|
|
|
|
|
Hi
I have trouble with ADO.Net. I don't understand when to use what. I'm using Visual Basic in Visual Studio 2005.
In my program I have a dataadapter-,dataset and a bindingsource control.
When I try to use the code
Dim cnNwind As New OleDb.OleDbConnection(Me.FilmTableAdapter.Connection.ConnectionString)
Dim cmOrder As OleDb.OleDbCommand = Nothing
Dim strSQL As String = "DELETE FROM " + table + " WHERE ID = " + cbo.SelectedValue.ToString
cmOrder = New OleDb.OleDbCommand(strSQL, cnNwind)
cmOrder.ExecuteNonQuery()
nothing happens, the record isn't deleted.
I have also tried using the adapters Delete method
Me.FilmTableAdapter.Delete(cbo.SelectedValue.ToString)
Me.FilmTableAdapter.Update(Me.FilmerDataSet)
and nothing happens.
I don't know if I had to use the update method, but it didn't mattered if I did or didn't.
I have also tried to add parameters when I used the Delete method, but it didn't helped.
cmOrder.Parameters.AddWithValue("@Original_ID", cbo.SelectedValue.ToString)
Me.FilmTableAdapter.Delete(cbo.SelectedValue.ToString)
So I have know clue what to do or when I should use either of the methods to delete a record.
If there is somone who can explain when to use either of these examples, please explain that for me. And when should I use the update method, because I don't know.
And what should I do in my program to delete a record.
PLEASE HELP ME!!!!
FIA
|
|
|
|
|
you have to call cnNwind.Open() before executing a command.
Calin
|
|
|
|
|
Sorry, I didn't paste that line. I have already used the code.
cnNwind.Open()
before I used the ExecuteNonQuery or the dataapter's Delete method and it still doesn't work.
|
|
|
|
|
If the rest of the code you haven't show around these small sections is correct, the ID you're supplying to the SQL DELETE statement isn't matching any records.
|
|
|
|
|
I'll give it another try.
I have in my program a dataadapter, a dataset and a databindingsource control.
I have tried the code below
Sub deleteRecords(ByVal cbo As ComboBox, ByVal table As String)
Dim cnNwind As New OleDb.OleDbConnection (Me.FilmTableAdapter.Connection.ConnectionString)
Dim cmOrder As OleDb.OleDbCommand = Nothing
Dim strSQL As String = "DELETE FROM " + table + " WHERE ID = " + cbo.SelectedValue.ToString
cmOrder = New OleDb.OleDbCommand(strSQL, cnNwind)
'cmOrder.Parameters.AddWithValue("@Original_ID", cbo.SelectedValue.ToString)
cnNwind.Open()
cmOrder.ExecuteNonQuery()
cnNwind.Close()
End Sub
and nothing happens. It doesn't matter if I add the parameters or not.
And the ID is in the database.
I have also tried the dataadapters Delete method
Sub deleteRecords(ByVal cbo As ComboBox, ByVal table As String)
Dim cnNwind As New OleDb.OleDbConnection(Me.FilmTableAdapter.Connection.ConnectionString)
Dim cmOrder As OleDb.OleDbCommand = Nothing
cnNwind.Open()
Me.FilmTableAdapter.Delete(cbo.SelectedValue.ToString)
Me.FilmTableAdapter.Update(Me.FilmerDataSet)
cnNwind.Close()
End Sub
but nothing happens here either.
I don't know when to use either of these examples or when to add the parameters or use the Update method. And now when neither of them working with parameters and Update or not, I need some explanation on when to use either of the examples I have and when to use parameter or Update. And of course what to do in my program.
I hope this code explains my trouble more.
|
|
|
|
|
And have you checked the value of cbo.SelectedValue when you put it in the SQL string?? Does this value actually exist in the table?
|
|
|
|
|
Hi again
Yes the value exists, so I have no idea why it's not working. Can it maybe be that the combobox is bound to fields in the database. I have also changed the disabled mode in the Access database.
|
|
|
|
|
Wait a minute. You're using an Access database?? Is this database part of your project? If so, then the code might actually be working. If your database is in the project folder and you compile the program, the database file (*.mdb) will be copied to the bin folder of your project. Now, every time you compile and run your app the database is being copied to the bin folder AGAIN, overwriting any changes you've made since the database was first added to the project.
|
|
|
|
|
Yes, the database is included. Doesn't it have to be if I'm using dataadapter, dataset controls and bound conrols? I tried to exclude the database, but then I got an InvalidOperationException that said it couldn't find the database. What do I have to do now?
|
|
|
|
|
fiaolle wrote: Doesn't it have to be if I'm using dataadapter, dataset controls and bound conrols?
If you've used the dataset designer, yes, it does.
Put the database back in the proejct like you had it. You just need to understand that any changes you make to the database will be undone because the database is being recopied to the Release or Debug folders every time you run it. Your code is making changes to that copy of the database, not the copy you see in the project.
|
|
|
|
|
I don't understand the point of that. Because when I delete an item in the comboBox I want the item to be removed from the comboBox. I really don't know how to do that the easiest way. But should I remove my controls and my database and connect to my database another way. Are there no connection controls in Visual Studio 2005, because I didn't get one when I added a new DataSource.
|
|
|
|
|
fiaolle wrote: Because when I delete an item in the comboBox I want the item to be removed from the comboBox.
I'm assuming you databound the combo to a dataset or datatable. In that case, you don't delete anything from the Combo. You delete it from the data, then either rebind the Combo, or refresh the datasource that the combo is bound to. This will automatically take the item out of the list in the Combo.
|
|
|
|