WinForm 은 TextBox 에 워 터 마크 문자 기능 을 설정 합 니 다.
키 코드 는 다음 과 같 습 니 다:
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace WinFormUtilHelpV2
{
/// <summary>
/// .NET 2.0 TextBox
/// </summary>
public static class TextBoxToolV2
{
private const int EM_SETCUEBANNER = 0x1501;
[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern Int32 SendMessage
(IntPtr hWnd, int msg, int wParam, [MarshalAs(UnmanagedType.LPWStr)] string lParam);
/// <summary>
/// TextBox
/// </summary>
/// <param name="textBox">TextBox</param>
/// <param name="watermark"> </param>
public static void SetWatermark(this TextBox textBox, string watermark)
{
SendMessage(textBox.Handle, EM_SETCUEBANNER, 0, watermark);
}
/// <summary>
///
/// </summary>
/// <param name="textBox">TextBox</param>
public static void ClearWatermark(this TextBox textBox)
{
SendMessage(textBox.Handle, EM_SETCUEBANNER, 0, string.Empty);
}
}
}
테스트 코드 는 다음 과 같 습 니 다:
using System;
using System.Windows.Forms;
using WinFormUtilHelpV2;
namespace WinFormUtilHelpV2Test
{
public partial class WinTextBoxToolV2Test : Form
{
public WinTextBoxToolV2Test()
{
InitializeComponent();
}
private void WinTextBoxToolV2Test_Load(object sender, EventArgs e)
{
textBox1.SetWatermark(" ....");
textBox2.SetWatermark(" ....");
}
private void button1_Click(object sender, EventArgs e)
{
textBox1.ClearWatermark();
textBox2.ClearWatermark();
}
}
}
테스트 효 과 는 다음 그림 과 같다.본 고 에서 말 한 TextBox 에 워 터 마크 문자 기능 예 시 를 설정 하 는 것 이 여러분 의 C\#프로 그래 밍 에 도움 이 되 기 를 바 랍 니 다!
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
C# Excel 템플릿 내보내기(Word 등)프로젝트에서 Excel, Word, pdf 등 템플릿 내보내기를 자주 사용해야 합니다. 다음은 자신이 정리한 간단한 버전의 템플릿 내보내기입니다. 복잡한 내보내기와 유사합니다. 조금만 수정하면 됩니다.다음 내보내기 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.