1
A
回答
1
有使用的PInvoke在http://www.aaronlerch.com/blog/2007/12/01/watermarked-edit-controls/
然而笔者注意到,设置“提示”文本的这一个实现...
这将仅适用于Windows XP工作,更高,只有如果视觉 样式启用
...和docs for CB_SETCUEBANNER状态的最小客户端是Windows Vista中。所以它可能不适合所有的环境。
万一页面消失,这里的相关类:
CueComboBox.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace Lerch.Samples
{
public class CueComboBox : ComboBox
{
#region PInvoke Helpers
private static uint CB_SETCUEBANNER = 0x1703;
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
private static extern IntPtr SendMessage(HandleRef hWnd, uint Msg, IntPtr wParam, String lParam);
#endregion PInvoke Helpers
#region CueText
private string _cueText = String.Empty;
/// <summary>
/// Gets or sets the text the <see cref="ComboBox"/> will display as a cue to the user.
/// </summary>
[Description("The text value to be displayed as a cue to the user.")]
[Category("Appearance")]
[DefaultValue("")]
[Localizable(true)]
public string CueText
{
get { return _cueText; }
set
{
if (value == null)
{
value = String.Empty;
}
if (!_cueText.Equals(value, StringComparison.CurrentCulture))
{
_cueText = value;
UpdateCue();
OnCueTextChanged(EventArgs.Empty);
}
}
}
/// <summary>
/// Occurs when the <see cref="CueText"/> property value changes.
/// </summary>
public event EventHandler CueTextChanged;
[EditorBrowsable(EditorBrowsableState.Advanced)]
protected virtual void OnCueTextChanged(EventArgs e)
{
EventHandler handler = CueTextChanged;
if (handler != null)
{
handler(this, e);
}
}
#endregion CueText
#region Overrides
protected override void OnHandleCreated(EventArgs e)
{
UpdateCue();
base.OnHandleCreated(e);
}
#endregion Overrides
private void UpdateCue()
{
// If the handle isn't yet created,
// this will be called when it is created
if (this.IsHandleCreated)
{
SendMessage(new HandleRef(this, this.Handle), CB_SETCUEBANNER, IntPtr.Zero, _cueText);
}
}
}
}
相关问题
- 1. Dropdownlist默认值
- 2. 输入字段中的默认文本
- 3. 默认输入数字值
- 4. 提示输入文字
- 5. Combobox打字时输入文字
- 6. 删除默认输入提交按钮
- 7. 提供cin输入的默认值
- 8. 如何在dropDownlist中显示默认值
- 9. dropdownlist插入总是默认值
- 10. 在shell脚本输入提示中返回默认值
- 11. Rails simple_form默认输入值不显示
- 12. 排除输入框的默认文字,只输入用户输入
- 13. php combobox默认选择
- 14. jQuery的日期选择器默认值输入字段提交
- 15. 添加默认值DropDownList
- 16. 的form_tag默认输入字段
- 17. JFX ComboBox提示文本
- 18. 提交后显示输入文字
- 19. 输入上的默认文本
- 20. 提示具有默认
- 21. 如何在提示用户输入时提供可编辑的默认值?
- 22. 输入默认的CSS
- 23. HTML/PHP - 默认输入值
- 24. SimpleForm默认输入类
- 25. HTML输入默认值
- 26. Ember输入 - 默认值
- 27. 当他输入文字时自动提示用户输入
- 28. 在样式为“DropDownList”的ComboBox中使用空行作为默认行?
- 29. 在输入文字前减少默认的光标大小
- 30. 作为jQuery datepicker的文本输入字段默认日期
谢谢,我会检查出来。 – Klas 2012-01-18 13:24:15