|
I want to select all text in a textbox, so I coded the SelectAll() method inside the GotFocus event handler.
This did not work, so I inserted a breakpoint to try to find the problem and what I found is that after the execution of the SelectAll() instruction the LostFocus event is fired and the code within the LostFocus handler executed.
The same thing hapens when using the TAB key to go to the textbox. However in this case the text remains selected
Bottom line I want to select the all text in the text box after clicking the control.
I looked around and the MouseDown event does the trick. However if I try to move the insertion point by clicking with the mouse all the text is selected again. And that is not a desirable behavior for this program.
Any ideas? Thanks In Advance!
|
|
|
|
|
Without seeing your code for these two event handles, it's impossible to tell you what you did wrong.
Either your code is wrong or your testing method and/or description of the problem is.
SelectAll will NOT change the focus to another control or remove focus from the control that you called SelectAll on.
|
|
|
|
|
Quote: I inserted a breakpoint to try to find the problem and what I found is that after the execution of the SelectAll() instruction the LostFocus event is fired You observed the LostFocus event after hitting your breakpoint in GotFocus because the breakpoint transfered the focus to the debugger. Ain't event debugging fun?
I believe that you will need a custom control to change the default handling mouse handling to get the effect that you want. Here is quick example that intercepts the left mouse button down message to achieve this behavior.
Public Class TBSelectOnEnter
Inherits TextBox
Protected Overrides Sub OnEnter(ByVal e As System.EventArgs)
SelectAll()
MyBase.OnEnter(e)
End Sub
Private Const WM_LBUTTONDOWN As Int32 = &H201
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If Not Focused AndAlso (m.Msg = WM_LBUTTONDOWN) Then
Me.Focus()
Else
MyBase.WndProc(m)
End If
End Sub
End Class Just add this to your code and do a build. It should show up in your toolbox at the top in the "YourApplicationName Components" section. Then use it as your TextBox.
|
|
|
|
|
Thanks TnTinMn! It Works fine.
And thanks for helping me understand the "LostFocus Mystery"
|
|
|
|
|
You are welcome.
Just be careful with that control. I did not put a lot of thought into the ramifications of "eating" the mouse down message, but I can not think of any.
|
|
|
|
|
I will. I know now the way. It's easier to explore.
|
|
|
|
|
hello everyone,
i am using vb.net(2003 in windows application) along with sql server 2005 i need to give display data of a sql procedure whose columns are being generated dynamicaly. The problem arise when i want to give header of flexgrid as i am not able to find out how sql column headers can be retrieved in case of it is being generated dynamicaly(for windows application)...Plz help
ashish sharma
|
|
|
|
|
Flexgrid?? The older-than-dirt-itself Flexgrid?? WHY on earth are you using that thing?
Is there something wrong with using the DataGridView??
What you want to do is a very trivial SQL operation. You're just putting the SqlCommand object together to execute a stored procedure and the resultset will come back with the column header in place by default. Well, IF your stored procedure is written correctly anyway.
|
|
|
|
|
I'm building a neural network library pretty much to see if I can do it and advance my skills in programming. I'm currently building the Neuron class, and as you may or may not know, a neuron in a neural network has what's called an activation function; however my question below does not have to do with neural networks directly, strictly with the use of Func(Of TResult) delegate So within my neural network class I have several built in activation functions:
Private Function Identity(value As Double) As Double
Return value
End Function
Private Function [Step](value As Double) As Double
If value <= 0 Then
Return 0
Else
Return 1
End If
End Function
Private Function LogarithmicSigmoid(value As Double, alpha As Double) As Double
If value < -45.0 Then
Return 0
ElseIf value > 45.0 Then
Return 1
Else
Return (1.0 / (1.0 + Exp(-alpha * value)))
End If
End Function
Private Function SymmetricSigmoid(value As Double) As Double
Return HyperbolicTangent(value)
End Function
Private Function HyperbolicTangent(value As Double) As Double
If value < -45 Then
Return -1.0
ElseIf value > 45.0 Then
Return 1.0
Else
Return Tanh(value)
End If
End Function
I also have an enumeration for the user to select which activation function they want to use for the neuron:
Public Enum ActivationFunctions
IDENTITY
[STEP]
LOGARITHMIC_SIGMOID
SYMMETRIC_SIGMOID
HYPERBOLIC_TANGENT
End Enum
The first problem I'm having is with the following methods:
Private activationFunction As Func(Of Double)
Public Sub SetActivationFunction(activationFunction As ActivationFunctions, value As Double, Optional alpha As Double = 1)
Select Case activationFunction
Case ActivationFunctions.IDENTITY
Me.activationFunction = Function(value As Double)
End Select
End Sub
Public Sub SetActivationFunction(ByVal activationFunction As Func(Of Double))
End Sub
I can't figure out how to set the instance variable activationFunction to a specific method using the AddressOf operator while passing it a parameter. Specifically in the first SetActivationFunction if the user passes the ActivationFunctions.IDENTITY enumeration, I would like to set the instance variable activationFunction to the method Identity but also pass the value parameter.
I've tried changing the line marked "PROBLEM LINE" to Me.activationFunction = AddressOf Identity but got the error message Method 'Private Function Identity(value As Double) As Double' does not have a signature compatible with delegate 'Delegate Function Func(Of Double)() As Double' .
If I changed it to Me.activationFunction = AddressOf Identity(value) the error message become 'AddressOf' operand must be the name of a method (without parentheses) , and if I change it to Me.activationFunction = AddressOf Identity()(value) I get the error message Argument not specified for parameter 'value' of 'Private Function Identity(value As Double) As Double'
Based on the varying error message it seems like what I'm trying to do can be done, I just can't figure out the proper way to specify the argument for the Identity method while using the AddressOf operator.
Any help and guidance would be greatly appreciated. I should note that this is the first time I'm trying to use the Func(Of TResult) delegate in my own code, but since I want users to be able to supply their own methods and arguments for the parameters it seemed appropriate.
Thanks in advance for any help.
|
|
|
|
|
For as function with return type Double and a parameter of type Double, use the Func(T, TResult) delegate[^].
However, in this case, a delegate solution is not feasible as you have two different function signatures:
Func(Of Double, Double)
Func(Of Double, Double, Double)
An alternative would be:
Private Function GetActivationFunctionValue(ByVal functiontype As ActivationFunctions, _
ByVal value As Double, _
Optional ByVal alpha As Double = 1) _
As Double
Select Case functiontype
Case ActivationFunctions.IDENTITY
Return Identity(value)
Case ActivationFunctions.LOGARITHMIC_SIGMOID
Return LogarithmicSigmoid(value, alpha)
' other enum cases
End Select
End Function
|
|
|
|
|
That works fine for built-in functions but how can I generalize it so that a user can supply their own activation function to use instead of just the ones I define?
|
|
|
|
|
Quote: how can I generalize it so that a user can supply their own activation function to use instead of just the ones I define? You should probably ask this question as a new question to get input from others.
The best advice that I can offer on that is to define the allowed function structure and develop an expression builder so that the user must follow a structure you define. The expression could then be processed to emit a DynamicMethod[^] that can called if selected.
This will take a fair amount of work.
|
|
|
|
|
Hello everyone! My name is Emmanuel and I new to dis site and also to programming. I am trying to write a program with vb6.0 that can be use to lock pc in a cafe. I have successfully designed d program but d problem is hw can i disable/enable d ctrl+alt+del keys so that d program cannot b quit. Also, som people might wnt to switch off d system & reboot so that they can have access. Now hw can i make the program autorun at windows startup? I know dragging d exe app into d startup folder can solve dis but d problem is that i'm not writing dis program 4 my self and i won't b there when my clients will install it. So, pls give me d code dat will add d program to d startup folder and d code to remove it if d user click on disable autorun. I am using windows 7 ultimate OS. Tnx in adv.
|
|
|
|
|
Since you're new to programming, I HIGHLY suggest you drop VB6 right now and go get VB.NET Express. It's free from here[^].
Save yourself the grief of learning a bunch of bad habits that VB6 will teach you and you'll get far more features and flexibility by using .NET instead.
Otekpo Emmanuel wrote: hw can i disable/enable d ctrl+alt+del keys
You can't trap Ctrl-Alt-Del. It's impossible to disable it.
Since you're code running AS THE USER when it starts from double-clicking it or from the Run key in the Registry, the user can terminate it any way they want and you can't stop that from happening. Users are always able to terminate an app running in their security context.
The solution is to move your code to somewhere that normal users don't have permissions to terminate, such as a Windows Service running as Local System. VB6 cannot write Windows Services (without hacking it in!), but VB.NET can.
Truthfully, a café application like this is far from trivial to write, secure, test (you ARE testing this for security, correct?!) and support.
|
|
|
|
|
Ok Dave, thanks for your advice and I promise not to use such words again. You advice me to use Vb.Net and just as I said before, I'm new to programming and I don't any knowledge about Vb.Net. So would you please give some guidelines to abide to. And a site that can give me more experience on Vb.Net. Thanks.
|
|
|
|
|
Ok Dave, thanks for your advice and I promise not to use such words again. You advice me to use Vb.Net and just as I said before, I'm new to programming and I don't any knowledge about Vb.Net. So would you please give some guidelines to abide to. And a site that can give me more experience on Vb.Net. Thanks.
|
|
|
|
|
Guidelines?? For what?? No site can give you "more experience". The only thing that's going to do that is writing code, writing more code, and finally writing even more code.
|
|
|
|
|
Less of the textspeak - we are adults here!
It's well known that if all the cat videos and porn disappeared from the internet there would be only one site left and it would be called whereareallthecatvideosandporn.com
|
|
|
|
|
There's an older article on configuring XP as a kiosk machine[^]; might still have some good clues
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hello everyone! My name is Emmanuel and I'm new to programming. I designed a name dictionary with v6.0, where som1 can search 4 d meaning and origin of his name. Everytin is wrking fine. But when i make d project exe and try to run it in another system, it shows d database path is not a valid path but it will run fine in my system. Som1 out there shud hlp me plzzzzz. Tnx in adv.
|
|
|
|
|
Otekpo Emmanuel wrote: Som1 out there shud hlp me plzzzzz
This will almost certainly not happen as you are coding in a language that is DEAD , as Dave suggested get VB.Net express and start again.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I've a big interrogation concerning sound playback (WMP.lib)!
This code should play a sound, then compute...but it computes then play the sound!
Class MainWindow
Dim writingPath As String = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) & "\_UI Sounds\"
Dim uiPlayer As New WMPLib.WindowsMediaPlayer
Private Sub MainWindow_Loaded(sender As Object, e As System.Windows.RoutedEventArgs) Handles Me.Loaded
RunTest()
End Sub
Private Sub RunTest()
Debug.Print("Started!")
uiPlayer.URL = writingPath & "son1.wav"
uiPlayer.controls.play()
Dim a As Integer = 0
For i As Integer = 0 To 999999999
a = i
Next
Debug.Print("Done!")
End Sub
End Class
I thought that I perhaps should run the sound in a thread to be sure that it's played by its own!?
But this gives the same result
Imports System.Threading
Class MainWindow
Dim writingPath As String = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) & "\_UI Sounds\"
Dim uiPlayer As New WMPLib.WindowsMediaPlayer
Dim uiThread As Thread = New Thread(AddressOf PlayFile)
Private Sub MainWindow_Loaded(sender As Object, e As System.Windows.RoutedEventArgs) Handles Me.Loaded
RunTest()
End Sub
Private Sub RunTest()
uiThread = New Thread(AddressOf PlayFile)
uiThread.Start()
Debug.Print("Started!")
Dim a As Integer = 0
For i As Integer = 0 To 999999999
a = i
Next
Debug.Print("Done!")
End Sub
Private Sub PlayFile()
uiPlayer.URL = writingPath & "son1.wav"
uiPlayer.controls.play()
End Sub
End Class
How should I please proceed to hear my sound 'instantly'?
What's my mistake?
Thanks for your help!!
|
|
|
|
|
You've moved the wrong bit to the background thread.
Dim computeThread As Thread
Private Sub RunTest()
uiPlayer.URL = writingPath & "son1.wav"
uiPlayer.controls.play()
computeThread = new Thread(AddressOf Compute)
computeThread.Start()
End Sub
Private Sub Compute()
Debug.Print("Started!")
Dim a As Integer = 0
For i As Integer = 0 To 999999999
a = i
Next
Debug.Print("Done!")
End Sub
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
There are two possibilities to handle audio playing: one involves the message pump, the other one involves callback methods. I guess the WMPLib.WindowsMediaPlayer uses the message pump, and runs in the GUI thread of your application (as you explicitly call it uiPlayer). In that case, the messages can only be dealt with when the GUI of your apllication is ready to handle them.
You may test that hypotheses by adding an Application.DoEvents() to your for loop (do not do that for production code): playing should now be possible.
|
|
|
|
|
It doesn't work better.
Well, I had posted a simple code, hoping that it would be more clear for users to help me...but I'm afraid that I'd better post something very similar to my actual code..if I want the problem to be clearly exposed...and help you to try to help me
There's a sound class, called UISound:
Imports System.Threading
Public Class UISound
Dim writingPath As String = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) & "\_UI Sounds\"
Public Shared WithEvents uiPlayer As New WMPLib.WindowsMediaPlayer
Public Shared uiThread As Thread = New Thread(AddressOf ReceiveSound)
Public Shared Sub ReceiveSound(ByVal url As String)
uiThread = New Thread(AddressOf PlayFile)
uiThread.Start(url)
End Sub
Public Shared Sub PlayFile(ByVal url As String)
uiPlayer.URL = writingPath & url
uiPlayer.controls.play()
End Sub
End Class
The sound is called from a sub in the MainWindow...which itself fires other subs in cascade that involve a heavy compute time:
Sub one()
UISound.ReceiveSound("sound1.wav")
Dim a As Integer = 0
For i As Integer = 0 To 999999999
a = i
Next
Two()
End Sub
Sub two()
Dim a As Integer = 0
For i As Integer = 0 To 999999999
a = i
Next
Three()
End Sub
Sub Three()
Dim a As Integer = 0
For i As Integer = 0 To 999999999
a = i
Next
End Sub
It appears that the sound is played after the whole "cascade" is runned, so after Sub Three() End.
If you try this code you will verify that inserting
System.Windows.Forms.Application.DoEvents()
after uiPlayer.controls.play()...doesn't work better
Thanks for your help!!
|
|
|
|