|
use the below code
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)(0x0D))
MessageBox.Show("Enter Pressed");
}
Thanks
Rajesh B --> A Poor Workman Blames His Tools <--
|
|
|
|
|
I assume you want it VB.Net not C#. Try this
Private Sub txtTest_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtTest.KeyDown
If e.KeyCode = Keys.Enter Then
MsgBox("You pressed the Enter Key")
End If
End Sub
Happy Coding
|
|
|
|
|
Hello!
Could u help me pls
How to add a new context menu into the CD drive's context menu ? [ie.close tray,open tray(eject)]
i'll thz ........
|
|
|
|
|
I gave you a link to article on Context Menu's yesterday when you asked this question.
Now that you know what to look for, have you tried doing some of your own research using google / codeproject etc?
Start writing your own code now, and come back when you have a specific problem.
|
|
|
|
|
how to bound text box control for numeric keys in vb.net
|
|
|
|
|
use char.IsDigit method
Rajesh B --> A Poor Workman Blames His Tools <--
|
|
|
|
|
I have a form that is showing a MessageBox using MessageBox.Show, and trying to receive events from the Help button on the MessageBox so I can execute my own code. The Microsoft documentation shows how to do this; however, using what is suggested does not work. Here's a shortened version of my code:
Private Function MethodName() As Boolean
AddHandler Me.HelpRequested, AddressOf Me.MsgBoxHelpRequested
Select Case MessageBox.Show("Text", "Title", MessageButtons.YesNoCancel, _
MessageBoxIcon.Question, MessageBoxDefaultButton.Button2, 0, True)
Case MsgBoxResult.Yes
' Do stuff
Case MsgBoxResult.No
' Do stuff
Case MsgBoxResult.Cancel
RemoveHandler Me.HelpRequested, AddressOf Me.MsgBoxHelpRequested
Return False
End Select
RemoveHandler Me.HelpRequested, AddressOf Me.MsgBoxHelpRequested
End Function
'
'
Private Sub MsgBoxHelpRequested(ByVal sender As Object, _
ByVal hlpevent As System.Windows.Forms.HelpEventArgs)
' Breakpoint that never gets hit
' More code
End Sub
I posted this question yesterday on stackoverflow[^], where we get into quite a spirited discussion, with a bunch of suggestions that ultimately never seemed to pan out, if you want to see what I've already tried.
Currently I'm working on seeing if there's any way to determine if the event was even raised in the first place - either by trying to manually raise the event and see if my code gets called, or seeing if there's any way to break on an event.
Does anybody have any suggestions?
Oh, and by the way, Chris Maunder: CodeProject is much better designed than StackOverflow. Reading stackoverflow is a pain on the eyes, trying to comment is a pain in the neck - coming back home here is such a relief. While the people over there are just as nice as here, I wish I had thought to check here yesterday.
|
|
|
|
|
Yes i have a suggestion;
I placed a button on the form, and coded the following;
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim response As MsgBoxResult = MsgBox("the prompt", MsgBoxStyle.MsgBoxHelp + MsgBoxStyle.Information + MsgBoxStyle.YesNo, "The Title")
MsgBox(response)
End Sub
Private Sub FormMain_HelpRequested(ByVal sender As Object, ByVal hlpevent As System.Windows.Forms.HelpEventArgs) Handles Me.HelpRequested
MsgBox("help Requested")
End Sub
This displays a Yes No Help msgbox, when the help is pressed, another msgbox appears with the help requested.
Based on this, what you could do is set a variable before entering the msgbox with some form of identifier, then in the HelpRequested call, check the value of that variable and perform the appropriate help action.
|
|
|
|
|
Okay, I'm not sure why you're showing a second MsgBox to display the MsgBoxResult of the first one in the first function, but the second function doesn't help me because it's yet another variation of what I've been trying to do that I have already determined does not work for me.
|
|
|
|
|
i was only using msgbox to illustrate a point thats all.
What are you trying to do then, what i have shown in the example code is the help button being handled, which is what i thought you couldn't achieve?
Private helpTopic as integer =0
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
helpTopic = 1
Dim response As MsgBoxResult = MsgBox("the prompt", MsgBoxStyle.MsgBoxHelp + MsgBoxStyle.Information + MsgBoxStyle.YesNo, "The Title")
If response = vbYes Then
Else
End If
End Sub
Private Sub FormMain_HelpRequested(ByVal sender As Object, ByVal hlpevent As System.Windows.Forms.HelpEventArgs) Handles Me.HelpRequested
Select Case helpTopic
Case 1
Case Else
End Select
End Sub
is that better without the extra msgboxes!
|
|
|
|
|
Sorry to snap at you, I got a little annoyed yesterday at people telling me what to do and posting essentially my exact code.
Your code isn't the current iteration of my exact code, but it's been tried.
Unsuccessfully.
|
|
|
|
|
So, I'm not sure what's wrong with your code. I did this:
Private Sub Button3_Click(...)
AddHandler Me.HelpRequested, AddressOf Me.MsgBoxHelpRequested
Select Case MessageBox.Show("Text","Title", MessageBoxButtons.YesNoCancel, _
MessageBoxIcon.Question, MessageBoxDefaultButton.Button2, 0, True)
End Select
End Sub
Private Sub MsgBoxHelpRequested(...)
MessageBox.Show("got here")
End Sub
and I "got here". Am I the only one that this works for?
|
|
|
|
|
Actually, I seem to be the only one it doesn't work for.
And only in this project.
I've copied and pasted my exact code to a new Project, and after taking care of all the blue underlines, it works perfectly. I can't figure out why it's not working in the the real application; the only thing I can think is that the event is never being fired from the MessageBox somehow - I've added handlers for the event in every possible way I can think of, and none of them ever get called. If only I could fire the event myself or break execution when the event is called, it would be so tremendously helpful, but I neither of these seem possible, and I'm getting extremely frustrated.
|
|
|
|
|
check you haven't got 2 handlers poitint to the same code, that seems to effect things.
For example, look at my most recent code i have the Button2Help, if i change the handler to FormMain_HelpRequested (which is handled by Me.HelpRequested) it won't work.
|
|
|
|
|
Nope, that works for me also.
Both Versions of Code, using 2 buttons on form;
Public Class FormMain
Private helpTopic As Integer = 0
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
helpTopic = 1
Dim response As MsgBoxResult = MsgBox("the prompt", MsgBoxStyle.MsgBoxHelp + MsgBoxStyle.Information + MsgBoxStyle.YesNo, "The Title")
If response = vbYes Then
Else
End If
End Sub
Private Sub FormMain_HelpRequested(ByVal sender As Object, ByVal hlpevent As System.Windows.Forms.HelpEventArgs) Handles Me.HelpRequested
Select Case helpTopic
Case 1
Case Else
End Select
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
AddHandler Me.HelpRequested, AddressOf Button2Help
MessageBox.Show("The text", "The caption", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, 0, True)
End Sub
Private Sub Button2Help()
MsgBox("Some help please")
End Sub
End Class
|
|
|
|
|
This code is actually getting executed by way of a .dll which Raises an event back on the calling Form that leads to this code. If I move this code back to just before where the code heads out to the .dll, it works. Could something be going on behind the scenes due to the .dll call that could be causing this?
modified on Thursday, May 13, 2010 4:58 PM
|
|
|
|
|
OH. MY. GOODNESS. So I started checking the source code for the MessageBox.Show in Reflector. As it turns out, if you don't specify the Owner, as you aren't allowed to do when you want to handle HelpRequested yourself, it uses UnsafeNativeMethods.GetActiveWindow() to determine who to send the HelpRequested to. The moment I saw this, I knew what was going on. The application I'm working in has a splash screen that shows the status to the user that is shown in the .dll. THAT is the ActiveWindow. When I forced it down and called Activate on my Form just before this code, it worked.
Trevortni wrote:
Private Function MethodName() As Boolean
Me.Activate()
AddHandler Me.HelpRequested, AddressOf Me.MsgBoxHelpRequested
Select Case MessageBox.Show("Text", "Title", MessageButtons.YesNoCancel, _
MessageBoxIcon.Question, MessageBoxDefaultButton.Button2, 0, True)
Case MsgBoxResult.Yes
' Do stuff
Case MsgBoxResult.No
' Do stuff
Case MsgBoxResult.Cancel
RemoveHandler Me.HelpRequested, AddressOf Me.MsgBoxHelpRequested
Return False
End Select
RemoveHandler Me.HelpRequested, AddressOf Me.MsgBoxHelpRequested
End Function
'
'
Private Sub MsgBoxHelpRequested(ByVal sender As Object, _
ByVal hlpevent As System.Windows.Forms.HelpEventArgs)
' Breakpoint that finally gets hit
' More code
End Sub
|
|
|
|
|
good to hear that you have got to the bottom of the problem.
|
|
|
|
|
Kudos to you for posting the solution.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Hi all
I'm experiencing troubles with the code from this site.
Which parameter is exspected instead of:"master..sysdatabases" in the following sql-command:
Dim mySQL As String = _
"IF EXISTS (" & _
"SELECT * " & _
"FROM master..sysdatabases " & _
"WHERE Name = 'MyDatabase')" & vbCrLf & _
"DROP DATABASE MyDatabase " & vbCrLf & _
"CREATE DATABASE MyDatabase "
I'm using sql server 2008 express
Thanks,
Lucchingolo
|
|
|
|
|
please don't post the same question in more than one forum; if some people were to answer here, and some elsewhere, it would become very messy. See the forum guidelines.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
Hi Luc,
i must admit that i made a few mistakes.
I'm sorry.
When (in the General Database forum) i have been suggested to chage to the VS-forum i did not think of the consequences. I was too much focused on my little problem.
And regarding the "formatted code", you are right of course. I promise i will do it better the next time.
As english is not my native language, i must admit that i struggle with two of your expressions.
1. What is Q&A?
2. What do you mean by "real forum"?
thanks a lot,
Lucchingolo
|
|
|
|
|
There is a Questions&Answers section on this site; it is rather new, and does not support discussions, it only serves simple questions and answers. Real forums, like this one, as well as the personal profile page, allow for back-and-forth conversations and discussions, so the issues can get an in-depth treatment when required.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
Tanks, everything is clear now.
|
|
|
|
|
So what's the error message? Your statement of "Which parameter is exspected instead of:"master..sysdatabases" doesn't make sense. What do you want this to do?
|
|
|
|
|