Is it possible to change the caret to some other shape
that I define?
Thanks for any help or pointers.
Dave
You will find a VB6 sample here:
<http://www.activevb.de/tipps/vb6tipps/tipp0192.html>
You will have to translate it to .NET (untested).
--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Thanks for the pointer. Although it is in German and VB6,
I think I get the idea. Basically I will need to invoke
functions from the user32 lib when the control gets focus.
Anybody else have suggestions or pointers to a C# example
or explanation in English?
Thanks,
Dave
>.
>
If you still have problems on this issue, please let me know!
Thanks for using MSDN Newsgroup.
<code>
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Diagnostics;
using System.Runtime.InteropServices;
namespace WindowsForm_OwnerCaret
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Drawing.Bitmap bm;
private IntPtr hBitmap;
private int blinkTime;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.Button showCaret;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.textBox2 = new System.Windows.Forms.TextBox();
this.showCaret = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(112, 24);
this.textBox2.Name = "textBox2";
this.textBox2.TabIndex = 2;
this.textBox2.Text = "textBox2";
//
// showCaret
//
this.showCaret.Location = new System.Drawing.Point(16, 24);
this.showCaret.Name = "showCaret";
this.showCaret.TabIndex = 4;
this.showCaret.Text = "ShowCaret";
this.showCaret.Click += new System.EventHandler(this.button1_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(256, 69);
this.Controls.Add(this.showCaret);
this.Controls.Add(this.textBox2);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void Form1_Load(object sender, System.EventArgs e)
{
bm = new Bitmap("app.ico");
hBitmap = bm.GetHbitmap();
}
private void button1_Click(object sender, System.EventArgs e)
{
NativeMethod.CreateCaret(this.textBox2.Handle,hBitmap,16,16);
NativeMethod.ShowCaret(this.textBox2.Handle);
}
}
class NativeMethod
{
[DllImport("user32.dll")]
public extern static int GetCaretBlinkTime();
[DllImport("user32.dll")]
public extern static int SetCaretBlinkTime(int wMSeconds);
[DllImport("user32.Dll")]
public extern static int GetCaretPos(ref POINT pt);
[DllImport("user32.dll")]
public extern static int SetCaretPos(int x, int y);
[DllImport("user32.Dll")]
public extern static int DestroyCaret();
[DllImport("user32.dll")]
public extern static int CreateCaret(IntPtr hwnd, IntPtr hBitmap, int
nWidth, int nHeight);
[DllImport("user32.dll")]
public extern static int ShowCaret(IntPtr hwnd);
[DllImport("user32.dll")]
public extern static int HideCaret(IntPtr hwnd);
[StructLayout(LayoutKind.Sequential)]
public struct POINT
{
public int x;
public int y;
}
}
}
</code>
Best regards,
Ying-Shen Yu [MSFT]
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties and confers no rights.
You should not reply this mail directly, "Online" should be removed before
sending, Thanks!
--------------------
| Content-Class: urn:content-classes:message
| From: "Dave Leach" <ba...@agilent.com>
| Sender: "Dave Leach" <ba...@agilent.com>
| References: <067501c391c9$26fd14c0$a401...@phx.gbl>
<bmf59a$m9bj5$3...@ID-208219.news.uni-berlin.de>
| Subject: Re: How to change Caret in TextBox?
| Date: Mon, 13 Oct 2003 16:42:57 -0700
| Lines: 34
| Message-ID: <0a5701c391e3$bae5ec60$a301...@phx.gbl>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="iso-8859-1"
| Content-Transfer-Encoding: quoted-printable
| X-Newsreader: Microsoft CDO for Windows 2000
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| Thread-Index: AcOR47rldO2CHK3sRBuhKWD/q0akxQ==
| Newsgroups: microsoft.public.dotnet.framework.windowsforms.controls
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.windowsforms.controls:11462
| NNTP-Posting-Host: TK2MSFTNGXA11 10.40.1.163
| X-Tomcat-NG: microsoft.public.dotnet.framework.windowsforms.controls
Thanks for the example code below. It provided enough
information for me to get the desired result.
Thanks again,
Dave
>.
>