-
Custom Control
I want to create a custom control that has a cursor like a regular text box, I tried using a line and a timer that makes the line 'Blink', but that wasn't too reliable because I had to change the location and background in the timer... I guess I could do it, but I wanted to ask my question here.
Basically what I am doing is creating a custom control to allow inputs as in fractions, sub/superscripts, etc.... The TextBox Control doesn't support text in that many locations. Just to give you an idea of what I am trying to do... :)
-
Re: Custom Control
I tried starting a 'math type editor' a long time ago as well, but gave up pretty quickly. I think it's a lot more complicated than you might think. You would almost certainly have to custom draw everything, basically creating a Textbox from scratch.
-
Re: Custom Control
You can use the CreateCaret and ShowCaret Win32 API functions. This example creates a cursor in a PictureBox (you would normally always do the call in the GotFocus event).
Code:
Private Declare Function CreateCaret Lib "user32.dll" ( _
ByVal hWnd As IntPtr, _
ByVal hBitmap As IntPtr, _
ByVal nWidth As Integer, _
ByVal nHeight As Integer _
) As Boolean
Private Declare Function ShowCaret Lib "user32.dll" ( _
ByVal hWnd As IntPtr _
) As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
CreateCaret(PictureBox1.Handle, IntPtr.Zero, 0, 12)
ShowCaret(PictureBox1.Handle)
End Sub
-
Re: Custom Control
Thanks.
Now I want to 'write' text to my control. Would you create another control to function as a 'Fraction', one as a 'Square Root'...
I tried just printing text to the control, but I wasn't able to retrieve the text.