- [DEVEXPRESS] Chia sẻ code các tạo report in nhiều hóa đơn trên XtraReport C#
- [POWER AUTOMATE] Hướng dẫn gởi tin nhắn zalo từ file Excel - No code
- [C#] Chia sẻ code lock và unlock user trong domain Window
- [SOFTWARE] Giới thiệu bộ phần mềm tính Kết Cấu Thép HatteSale, Mộng Đơn, Dầm, Sàn, Móng Cọc, Vách, Xà Gồ, Tính Tải Trọng
- [DEVEXPRESS] Vẽ Biểu Đồ Stock Chứng Khoán - Công Cụ Thiết Yếu Cho Nhà Đầu Tư trên Winform
- [C#] Hướng dẫn bảo mật ứng dụng 2FA (Multi-factor Authentication) trên Winform
- [C#] Hướng dẫn convert HTML code sang PDF File trên NetCore 7 Winform
- [C#] Hướng dẫn viết ứng dụng chat với Gemini AI Google Winform
- Hướng dẫn khóa file bằng nhiều process id, không cho xóa tập tin
- Hướng dẫn cách tạo Product Id cho ứng dụng phần mềm XXXXX-XXXXX-XXXXX-XXXXX
- [SQLSERVER] Hướng dẫn tạo script sql từ ứng dụng Sqlserver management Studio
- [C#] Hướng dẫn sử dụng thư viện AutoITx lấy id và password Ultraviewer trên winform
- [VB.NET] Hướng dẫn lấy thông tin tài khoản đăng nhập windows và khởi động lại ứng dụng ở chế độ Administrator
- [C#] Sử dụng thư viện Polly gửi lại request api khi request bị lỗi hay rớt mạng
- [DEVEXPRESS] Chia sẻ source code tạo báo cáo report in tem nhãn label trên C# winform
- [DEVEXPRESS] Hướng dẫn vẽ biểu đồ Bar Chart trên Winform
- [C#] Tạo form đăng nhập và đăng ký với hiệu ứng Sliding Animation Effect
- [C#] Hướng dẫn tạo thanh toán đơn hàng qua mã vạch VietQR sử dụng API PayOS hoàn toàn miễn phí
- [C#] Hướng dẫn ghi log ra RichTextBox giống Console trên Winform sử dụng thư viện Serilog
- [C#] Hướng dẫn cách tạo mã QR Code trên file Excel
Hướng dẫn tạo watermark trong Textbox giống thuộc tính placeholder trong thiết kế web
Hôm nay, mình xin tiếp tục hướng dẫn các bạn cách tạo Watermark trong textbox.
Giống thuộc tính placeholder trong textbox của html5.
Vậy Watermark là gì?
Trên một số tài liệu hay hình ảnh các bạn thường hay thấy các dòng chữ mờ mờ ghi thương hiệu hay tác giả tạo ra tài liệu, hình ảnh – đó chính là Watermark. Trên hình 1 là một ví dụ về Watermark trong Word.
Giao diện Demo ứng dụng:
Code Csharp:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace DemoWindowsApplication
{
public partial class WaterMark : Form
{
public WaterMark()
{
InitializeComponent();
textBox1.ForeColor = Color.LightGray;
textBox1.Text = "Please Enter Name";
this.textBox1.Leave += new System.EventHandler(this.textBox1_Leave);
this.textBox1.Enter += new System.EventHandler(this.textBox1_Enter);
textBox2.ForeColor = Color.LightGray;
textBox2.Text = "Please Enter Address";
this.textBox2.Leave += new System.EventHandler(this.textBox2_Leave);
this.textBox2.Enter += new System.EventHandler(this.textBox2_Enter);
}
private void textBox1_Leave(object sender, EventArgs e)
{
if (textBox1.Text == "")
{
textBox1.Text = "Please Enter Name";
textBox1.ForeColor = Color.Gray;
}
}
private void textBox1_Enter(object sender, EventArgs e)
{
if (textBox1.Text == "Please Enter Name")
{
textBox1.Text = "";
textBox1.ForeColor = Color.Black;
}
}
private void textBox2_Enter(object sender, EventArgs e)
{
if (textBox2.Text == "Please Enter Address")
{
textBox2.Text = "";
textBox2.ForeColor = Color.Black;
}
}
private void textBox2_Leave(object sender, EventArgs e)
{
if (textBox2.Text == "")
{
textBox2.Text = "Please Enter Address";
textBox2.ForeColor = Color.Gray;
}
}
}
}
Code VB.NET
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Windows.Forms
Namespace DemoWindowsApplication
Partial Public Class WaterMark
Inherits Form
Public Sub New()
InitializeComponent()
textBox1.ForeColor = Color.LightGray
textBox1.Text = "Please Enter Name"
Me.textBox1.Leave += New System.EventHandler(Me.textBox1_Leave)
Me.textBox1.Enter += New System.EventHandler(Me.textBox1_Enter)
textBox2.ForeColor = Color.LightGray
textBox2.Text = "Please Enter Address"
Me.textBox2.Leave += New System.EventHandler(Me.textBox2_Leave)
Me.textBox2.Enter += New System.EventHandler(Me.textBox2_Enter)
End Sub
Private Sub textBox1_Leave(ByVal sender As Object, ByVal e As EventArgs)
If textBox1.Text = "" Then
textBox1.Text = "Please Enter Name"
textBox1.ForeColor = Color.Gray
End If
End Sub
Private Sub textBox1_Enter(ByVal sender As Object, ByVal e As EventArgs)
If textBox1.Text = "Please Enter Name" Then
textBox1.Text = ""
textBox1.ForeColor = Color.Black
End If
End Sub
Private Sub textBox2_Enter(ByVal sender As Object, ByVal e As EventArgs)
If textBox2.Text = "Please Enter Address" Then
textBox2.Text = ""
textBox2.ForeColor = Color.Black
End If
End Sub
Private Sub textBox2_Leave(ByVal sender As Object, ByVal e As EventArgs)
If textBox2.Text = "" Then
textBox2.Text = "Please Enter Address"
textBox2.ForeColor = Color.Gray
End If
End Sub
End Class
End Namespace
Chúc các bạn thành công!
Hãy nhớ like and share nha các bạn!