-
Apr 29th, 2013, 04:22 AM
#1
Thread Starter
Addicted Member
[RESOLVED] Textbox Cursor Size
Would anyone know how to change the size of the cursor (IBeam) for a textbox, i.e: The blinker at the beginning of the textbox to the size of at least one character.
Cheers
-
Apr 29th, 2013, 04:27 AM
#2
Re: Textbox Cursor Size
Do you actually mean the width?
-
Apr 29th, 2013, 04:29 AM
#3
Thread Starter
Addicted Member
Re: Textbox Cursor Size
Yeah ive seen the cursor change event and ive tested some sorta of coding that i thought might work but didn't (probably isnt even the right one) aha
-
Apr 29th, 2013, 04:34 AM
#4
Re: Textbox Cursor Size
What you see in a TextBox is not the cursor in that sense. Anything to do with the cursor in WinForms is related to the mouse pointer. What you're talking about is called the caret.
This code is C# but it seems to address what you want to do:
http://stackoverflow.com/questions/6...nforms-textbox
-
Apr 29th, 2013, 04:40 AM
#5
Thread Starter
Addicted Member
Re: Textbox Cursor Size
cheers for that although i have no idea how C# works so i wouldnt be able to convert it into vb.net
-
Apr 29th, 2013, 04:54 AM
#6
Frenzied Member
Re: Textbox Cursor Size
google convert C# to vb.net, then copy and paste
-
Apr 29th, 2013, 05:06 AM
#7
Thread Starter
Addicted Member
Re: Textbox Cursor Size
oh yes thats great. although now im placing the code in the form and its generated a load of issues for other tools. so i didnt save the program so i must be doing something wrong. heres the code: just to confirm, where does each bit go, i tried it and it nearly mucked up the whole thing.
Code:
Public Partial Class Form1
Inherits Form
<DllImport("user32.dll")> _
Private Shared Function CreateCaret(hWnd As IntPtr, hBitmap As IntPtr, nWidth As Integer, nHeight As Integer) As Boolean
End Function
<DllImport("user32.dll")> _
Private Shared Function ShowCaret(hWnd As IntPtr) As Boolean
End Function
Public Sub New()
InitializeComponent()
End Sub
Private Sub Form1_Shown(sender As Object, e As EventArgs)
CreateCaret(textBox1.Handle, IntPtr.Zero, 10, textBox1.Height)
ShowCaret(textBox1.Handle)
End Sub
End Class
-
Apr 29th, 2013, 05:07 AM
#8
Re: Textbox Cursor Size
Originally Posted by Sean.Downes
cheers for that although i have no idea how C# works so i wouldnt be able to convert it into vb.net
C# works pretty much the same as VB but with a C-based syntax rather than a BASIC-based syntax. For instance, that code has a handler for the form's Shown event, just as you would in VB. It uses the DllImport attribute to decorate Windows API functions, just as you would in VB. Etc.
-
Apr 29th, 2013, 05:08 AM
#9
Re: Textbox Cursor Size
Originally Posted by Sean.Downes
oh yes thats great. although now im placing the code in the form and its generated a load of issues for other tools. so i didnt save the program so i must be doing something wrong. heres the code: just to confirm, where does each bit go, i tried it and it nearly mucked up the whole thing.
Code:
Public Partial Class Form1
Inherits Form
<DllImport("user32.dll")> _
Private Shared Function CreateCaret(hWnd As IntPtr, hBitmap As IntPtr, nWidth As Integer, nHeight As Integer) As Boolean
End Function
<DllImport("user32.dll")> _
Private Shared Function ShowCaret(hWnd As IntPtr) As Boolean
End Function
Public Sub New()
InitializeComponent()
End Sub
Private Sub Form1_Shown(sender As Object, e As EventArgs)
CreateCaret(textBox1.Handle, IntPtr.Zero, 10, textBox1.Height)
ShowCaret(textBox1.Handle)
End Sub
End Class
Get rid of the constructor and the event handler actually has to hand the event. Try creating a handler for the Load event, or any event for that matter, and you'll see the obvious difference.
-
Apr 29th, 2013, 05:14 AM
#10
Thread Starter
Addicted Member
Re: Textbox Cursor Size
oh geee, i have no idea, im not a very good at programming, i barely know the basics :/ thanks anyhow for your help appreciated
-
Apr 29th, 2013, 08:06 PM
#11
Re: Textbox Cursor Size
vb.net Code:
Public Class Form1
Declare Auto Function CreateCaret Lib "user32" (hWnd As IntPtr, hBitmap As IntPtr, nWidth As Integer, nHeight As Integer) As Boolean
Declare Auto Function ShowCaret Lib "user32" (hWnd As IntPtr) As Boolean
Private Sub Form1_Shown(sender As System.Object, e As System.EventArgs) Handles MyBase.Shown
CreateCaret(TextBox1.Handle, IntPtr.Zero, 10, TextBox1.Height)
ShowCaret(TextBox1.Handle)
End Sub
End Class
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
Apr 30th, 2013, 02:40 AM
#12
Thread Starter
Addicted Member
Re: Textbox Cursor Size
Hi thanks, this works great but for some reason it adds the text im typing into a different textbox, ive checked the code just incase i put the wrong textbox number and i definently havent and also when i click a different textbox it returns to the normal skinny blinker
thank
-
Apr 30th, 2013, 03:04 AM
#13
Re: Textbox Cursor Size
Only one control can own the text caret at the time so Windows will automatically destroy and recreate the caret when you move focus between controls. Move the two lines of code from the Form_Load event to the GotFocus event of the TextBox in question.
Last edited by Joacim Andersson; Apr 30th, 2013 at 03:08 AM.
-
Apr 30th, 2013, 04:26 AM
#14
Thread Starter
Addicted Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|