|
Just drag the Timer control from the toolbox to your form.
---
b { font-weight: normal; }
|
|
|
|
|
ah cool
|
|
|
|
|
I am trying to format cost once the file is written to the database. Here is what I have:
Dim FormatCost As String
FormatCost = Format(row("coreprice").ToString(), "c")
It is displaying c instead of the actual number, but when I do this for example:
MessageBox.Show(Format(553378.6789, "c"))
This code works fine.
Any advice will be greatly appreciated!
jds1207
|
|
|
|
|
your using your ToString too early. you can only format a number/date. if the argument is a string, it doesn't understand that.
FormatCost = format(CSng(row('coreprice")),"c").tostring
|
|
|
|
|
|
FormatCost = String.Format(CSng(row("coreprice")), "c")
You do NOT need to call ToString on the return value of Format, since it's already a String.
Sorry, just one of my pet peeves.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
My apologies...I find extra operations annoying as well...
|
|
|
|
|
please tell me how to do numlock and caplock on or off show in statusbar panel.
Thanks.
Rehan.
|
|
|
|
|
Easy. Create 2 Status strip labels (CapsText and NumText). Then, create a timer and set it's value for about 100 milliseconds. Then in the timer control, type:
<br />
If My.Computer.Keyboard.CapsLock = True Then<br />
CapsText.Text = "Caps On"<br />
End If<br />
If My.Computer.Keyboard.CapsLock = False Then<br />
CapsText.Text = "Caps Off"<br />
End If<br />
<br />
If My.Computer.Keyboard.NumLock = True Then<br />
Numtext.Text = "Num On"<br />
End If<br />
If My.Computer.Keyboard.NumLock = False Then<br />
NumText.Text = "Num Off"<br />
End If<br />
I hope this helps. Be sure to have the timer go off frequently, otherwise there will be a delay between the user hitting the key and the text changing.
|
|
|
|
|
Bad solution. You do not need a Timer to do this. See my post to the OP for a better solution.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Handle your Form's KeyDown or KeyUp event (the KeyPreview property of the form needs to be turned on!) and look for the keycodes NumLock and Capital, then update whatever control you're using as a status indicator appropriately.
Private Sub Form_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = Keys.NumLock Then
' Keyboard.Numlock will return True or False depending on the status
' of the indicator light on the keyboard.
UpdateNumLockIndicator(My.Computer.Keyboard.NumLock)
End If
If e.KeyCode = Keys.Capital Then
UpdateCapsLockIndicator(My.Computer.Keyboard.CapsLock)
End If
End Sub
...and you do NOT need a Timer to do this!
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Forgive but wouldn't this only handle the event when your form has focus? If you minimized your form and hit numlock, then maximized your form, it wouldn't know that the numlock was changed. I believe that's the purpose of the timer. So to solve this on a form_resize event, call the code on a windowstate change from minimized.
Private Sub Form2_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
if me.WindowState<>FormWindowState.Minimized then
UpdateNumLockIndicator(My.Computer.Keyboard.NumLock)
UpdateCapsLockIndicator(My.Computer.Keyboard.CapsLock)
end if
End Sub
Actually you would need to put it on the Form_Activate event as well...
|
|
|
|
|
There are a few other events you would have to handle to always know the state of the keyboard.
I'm not saying a timer is perfect, but definitely less coding.
Maybe a keyboard hook?
|
|
|
|
|
A keyboard hook would be the ultimate solution for the problem.
I personally, favor more coding over the use of more resources. Using a Timer and redrawing the status control every 100ms imports its own problems, especially in an environment that makes heavy use of custom drawn controls that take some time to draw.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
That's why I used a timer!
|
|
|
|
|
Yep, but the whole point is that a Timer is totally unnecessary and overkill since Ultra's example would needlessly redraw the status control every 100ms.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
thank for the answer but i am using visual basic.net 2003 in this vision i find error: (variable not declear) in "UpdateNumLockIndicator" & "My.Computer.Keyboard.NumLock"
please help me in this case.
thanks.
Rehan.
|
|
|
|
|
UpdateNumLockIndicator is a method that you have to supply to update whatever control your using to show the status of the toggle.
The My namespace is only available in VB.NET 2005. It doesn't exist in 2002 or 2003.
Public Declare Auto Function GetKeyState Lib "user32.dll" (ByVal KeyCode As Integer) As Short
Public ReadOnly Property NumLock As Boolean
Get
Return ((GetKeyState(144) And 1) > 0)
End Get
End Property
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
i am using below function but doen't work. if you please me how to use it this function in detail so i can solve my problem.
Public Declare Auto Function GetKeyState Lib "user32.dll" (ByVal KeyCode As Integer) As Short Public ReadOnly Property NumLock As Boolean
Get
Return ((GetKeyState(144) And 1) > 0)
End Get
End Property
Thanks
Rehan.
|
|
|
|
|
You update the status of the indicators by checking this NumLock Property in your KeyDown event code.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Hello,
i have a question about the WebBrowser.NewWindow Event.
How can i open an Popup in a new Window? In this event, i can only Cancel the Internet Explorer, but i cannot tell my application, that it should open the Page in a new Form?
In VisualBasic 6 it has worked, when i use the Microsoft WebBrowser COM Tool, then it works too, but i want to use the VisualBasic. net 2005 WebBrowser Class.
Has anybody a solution for this problem?
Thanks to you all
|
|
|
|
|
Does anyone know how to add a tasks window to a vb.net control? It's the small arrow at the top right area of the control. When a developer clicks on it, it shows a drop down menu.
|
|
|
|
|
how do i programatically insert a text at a particular cursor location in a text box
t.aransiola
|
|
|
|
|
replace the text "hello" with whatever you want
Select Case Me.TextBox1.SelectionStart
Case 0
Me.TextBox1.Text = "hello" & Me.TextBox1.Text
Case Else
Me.TextBox1.Text = Mid(Me.TextBox1.Text, 1, Me.TextBox1.SelectionStart) & _
"hello" & _
Mid(Me.TextBox1.Text, Me.TextBox1.SelectionStart + 1)
End Select
|
|
|
|
|
Hi,
What abt this solution
textbox1.SelectedText="Text To Insert"<br />
Hope this Works...
Nitin...
|
|
|
|