如何让TextBox内没有光标闪烁? using this:[DllImport("user32.dll", EntryPoint="HideCaret")]public static extern bool HideCaret ( IntPtr hwnd); 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 [DllImport("user32.dll", EntryPoint="HideCaret")]public static extern bool HideCaret ( IntPtr hwnd);这段代码怎么放?能不能给个完整的例子?谢谢! >>>>这段代码怎么放?能不能给个完整的例子?放在任何一个class中都可以,因为它是一个public static函数,调用的时候ClassName.HideCaret(..)就可以了 已经实现了,代码如下:--------------------------------------using System;using System.Drawing;using System.Collections;using System.ComponentModel;using System.Windows.Forms;using System.Runtime.InteropServices;namespace test{ /// <summary> /// HideControlCaret 的摘要说明。 /// </summary> public class HideControlCaret : System.Windows.Forms.Form { private System.Windows.Forms.Label label1; private System.Windows.Forms.TextBox txtForeColor; /// <summary> /// 必需的设计器变量。 /// </summary> private System.ComponentModel.Container components = null; public HideControlCaret() { // // Windows 窗体设计器支持所必需的 // InitializeComponent(); // // TODO: 在 InitializeComponent 调用后添加任何构造函数代码 // } /// <summary> /// 清理所有正在使用的资源。 /// </summary> protected override void Dispose( bool disposing ) { if( disposing ) { if(components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows 窗体设计器生成的代码 /// <summary> /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// </summary> private void InitializeComponent() { this.txtForeColor = new System.Windows.Forms.TextBox(); this.label1 = new System.Windows.Forms.Label(); this.SuspendLayout(); // // txtForeColor // this.txtForeColor.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(255)), ((System.Byte)(224)), ((System.Byte)(192))); this.txtForeColor.Cursor = System.Windows.Forms.Cursors.Default; this.txtForeColor.Location = new System.Drawing.Point(100, 36); this.txtForeColor.Name = "txtForeColor"; this.txtForeColor.ReadOnly = true; this.txtForeColor.Size = new System.Drawing.Size(128, 21); this.txtForeColor.TabIndex = 3; this.txtForeColor.Text = ""; this.txtForeColor.MouseDown += new System.Windows.Forms.MouseEventHandler(this.txtForeColor_MouseDown); // // label1 // this.label1.Location = new System.Drawing.Point(20, 40); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(68, 16); this.label1.TabIndex = 4; this.label1.Text = "选择颜色:"; // // HideControlCaret // this.AutoScaleBaseSize = new System.Drawing.Size(6, 14); this.ClientSize = new System.Drawing.Size(292, 129); this.Controls.Add(this.label1); this.Controls.Add(this.txtForeColor); this.Name = "HideControlCaret"; this.Text = "HideControlCaret"; this.Load += new System.EventHandler(this.HideControlCaret_Load); this.ResumeLayout(false); } #endregion [DllImport("user32.dll", EntryPoint="HideCaret")] public static extern bool HideCaret (IntPtr hwnd); private void txtForeColor_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { // show color picker dialog ColorDialog dlg = new ColorDialog(); dlg.Color = txtForeColor.BackColor; // if the user clicked OK, set new border color if (dlg.ShowDialog() == DialogResult.OK) txtForeColor.BackColor = dlg.Color; HideCaret(txtForeColor.Handle); } private void HideControlCaret_Load(object sender, System.EventArgs e) { HideCaret(txtForeColor.Handle); } }}现在只是不能控制窗体加载时就让Textbox没有光标,本来想在HideControlCaret_Load中实现,但是好像不行。 Replace private void HideControlCaret_Load(object sender, System.EventArgs e) { HideCaret(txtForeColor.Handle); }with private void HideControlCaret_Activated(object sender, System.EventArgs e) { HideCaret(txtForeColor.Handle); } 播放音乐时候显示的那些特效有人研究过没? 实用的查询需求,这样的SQL 语句怎么写? 如何启动不明文保存在硬盘上的程序?保存在资源里程序,大家出个意见~~ datagridview的单元格输入问题? 用C#下的Raw Socket编程实现网络封包监视(如何具体实现,请高手指点!) 如何定义这个结构体? 一个小小小的C#问题 委托有什么好处?一般用在什么地方? C# COM挂接事件问题 (新手求助)窗口为什么需要确认两次才可以? 用Ado.net可以对数据进行批量添加或更新,是什么意思,如何实现,能否给出代码示例 如何实现对象的值传递?
public static extern bool HideCaret (
IntPtr hwnd
);这段代码怎么放?能不能给个完整的例子?谢谢!
--------------------------------------
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Runtime.InteropServices;namespace test
{
/// <summary>
/// HideControlCaret 的摘要说明。
/// </summary>
public class HideControlCaret : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox txtForeColor;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null; public HideControlCaret()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent(); //
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
} /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.txtForeColor = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// txtForeColor
//
this.txtForeColor.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(255)), ((System.Byte)(224)), ((System.Byte)(192)));
this.txtForeColor.Cursor = System.Windows.Forms.Cursors.Default;
this.txtForeColor.Location = new System.Drawing.Point(100, 36);
this.txtForeColor.Name = "txtForeColor";
this.txtForeColor.ReadOnly = true;
this.txtForeColor.Size = new System.Drawing.Size(128, 21);
this.txtForeColor.TabIndex = 3;
this.txtForeColor.Text = "";
this.txtForeColor.MouseDown += new System.Windows.Forms.MouseEventHandler(this.txtForeColor_MouseDown);
//
// label1
//
this.label1.Location = new System.Drawing.Point(20, 40);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(68, 16);
this.label1.TabIndex = 4;
this.label1.Text = "选择颜色:";
//
// HideControlCaret
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 129);
this.Controls.Add(this.label1);
this.Controls.Add(this.txtForeColor);
this.Name = "HideControlCaret";
this.Text = "HideControlCaret";
this.Load += new System.EventHandler(this.HideControlCaret_Load);
this.ResumeLayout(false); }
#endregion
[DllImport("user32.dll", EntryPoint="HideCaret")]
public static extern bool HideCaret (IntPtr hwnd); private void txtForeColor_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
// show color picker dialog
ColorDialog dlg = new ColorDialog();
dlg.Color = txtForeColor.BackColor; // if the user clicked OK, set new border color
if (dlg.ShowDialog() == DialogResult.OK)
txtForeColor.BackColor = dlg.Color; HideCaret(txtForeColor.Handle);
} private void HideControlCaret_Load(object sender, System.EventArgs e)
{
HideCaret(txtForeColor.Handle);
} }
}
现在只是不能控制窗体加载时就让Textbox没有光标,
本来想在HideControlCaret_Load中实现,但是好像不行。
private void HideControlCaret_Load(object sender, System.EventArgs e)
{
HideCaret(txtForeColor.Handle);
}with
private void HideControlCaret_Activated(object sender, System.EventArgs e)
{
HideCaret(txtForeColor.Handle);
}