Form Questions

Hi,

I am having trouble with a timer application i am making. I need to make the form central to the x axis, wahtever the resolution, but the y axis must always be at "0".

Also, i would like to change the blinking cursor which you type from in a text box to a green square instead of the traditional line. any helop on this would be appreciated.

Any Help would be good

Thanks

Jamie



Answer this question

Form Questions

  • jorgepblank

    I don't see why not. Start a 50 msec interval timer on the GotFocus event, stop it on the LostFocus event. In the Tick event handler, play with the color or the size of the caret.


  • Micael Baerens

    Thanks alot, that really helped, just one other question...

    I would like to be able to press any return button on a form and it will check if the text box has the right phrase in it, and then close the form, so basically, i want the text box to submit, like it would with an ok button, but without a button and just when you press enter, if you know what i mean!


  • cpurick

    This should work for your 1st question.

    Public Class Form1

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    Dim r As Rectangle = My.Computer.Screen.WorkingArea

    Dim m As Integer = CInt((r.Width / 2) - Me.Width / 2)

    Me.Location = New Point(m, 0)

    End Sub

    End Class



  • Adminanup

    I see what you mean, I have set up the timer but the trouble is that in the code above, where it says mcaretbmp=, I have used a picture from My Resources because that was easier for me to get it how I wanted at the time, however is I have to use the original method that is fine...

    So I was just wondering, using what I have, if you could give me a bit more info on what to put in the tick event, and also if I need to use the other method, how to do it this way in a bit more depth.

    Thanks

    Jamie


  • Cpt Rick

    Q1:
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Me.Location = New Point((Screen.PrimaryScreen.Bounds.Width - Me.Width) \ 2, 0)
    End Sub

    Q2:
    Declare Function CreateCaret Lib "user32.dll" (ByVal hwnd As IntPtr, ByVal hbmp As IntPtr, ByVal width As Integer, ByVal height As Integer) As Boolean
    Declare Function ShowCaret Lib "user32.dll" (ByVal hwnd As IntPtr) As Boolean
    Private mCaretBmp As Bitmap

    Private Sub TextBox1_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.GotFocus
    With TextBox1
    Dim blob As Size = TextRenderer.MeasureText("X", .Font)
    mCaretBmp = New Bitmap(blob.Width, blob.Height)
    Dim gr As Graphics = Graphics.FromImage(mCaretBmp)
    Dim br As New SolidBrush(Color.FromArgb(255, 255, 0, 255))
    gr.FillRectangle(br, mCaretBmp.GetBounds(GraphicsUnit.Pixel))
    CreateCaret(TextBox1.Handle, mCaretBmp.GetHbitmap, blob.Width, blob.Height)
    ShowCaret(TextBox1.Handle)
    br.Dispose()
    gr.Dispose()
    End With
    End Sub

    Put the mCaretBmp creation code in the FormLoad event for efficiency...


  • Deldy

    Thank you for all your help with all of the questions, I just have one other:-

    Above you helped me to make the cursor into a green square - I was wondering if there was any way to make it fade in instead of just appear - its probably not possible but I was just wondering ---

    Thanks for all your help

    Jamie


  • Deepu.MI

    Well, it's starting to get a bit over the top. But, why not. Since you're using a bitmap, why don't you just use an array of bitmaps (ImageList jumps to mind). In the Tick event, change the caret bitmap by indexing the ImageList. Kill the timer when you've reached the last bitmap in the list...


  • flash.tato

    Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
    If e.KeyCode = Keys.Enter Then
    '--- Verify if contents are OK, something like this:
    If IsNumeric(TextBox1.Text) Then Me.Close()
    End If
    End Sub



  • NILKAMAL

    Where's my 'delete post' button

  • Marek Istvanek

    Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown

    If e.KeyCode = Keys.Enter Then

    Dim upstr As String = TextBox1.Text.ToUpper

    If upstr.IndexOf("TEST") <> -1 Then

    ' Remove msgbox line after debugging

    MsgBox("Test was part of the text")

    Me.Close()

    End If

    End If

    End Sub



  • Form Questions