- [DEVEXPRESS] Hướng dẫn bật tính năng Scroll Pixcel in Touch trên GridView
- [DEVEXPRESS] Hướng dẫn sử dụng TileBar viết ứng dụng duyệt hình ảnh Winform
- [DEVEXPRESS] Tô màu border TextEdit trên Winform
- [C#] Lấy dữ liệu từ Console Write hiển thị lên textbox Winform
- [C#] Hiển thị Progress bar trên Window Console
- [C#] Di chuyển control Runtime và lưu layout trên winform
- [SQLSERVER] Sử dụng hàm NULL IF
- [C#] Chia sẽ source code mã đi tuần bằng giao diện Winform
- [C#] Flash Window in Taskbar Winform
- Download và Giải nén tập tin File sử dụng Powershell
- [C#] Hướng dẫn cách lấy thông tin đăng nhập tài khoản và mật khẩu web browser trên windows
- [VB.NET] CRUD Thêm xóa sửa tìm kiếm Realtime FireBase
- [C#] Hiển thị thông báo Toast Message trong lập trình Winform
- [C#] Cấu hình định dạng ngày tháng, thời gian trên Windows cho ứng dụng Winform
- [C#] Rút gọn đường dẫn link url với TinyURL API
- [C#] Hướng dẫn cách bo tròn winform with Radius
- [C#] Chia sẽ class BackGroundOverlay Show Modal cho Winform
- [C#] Hướng dẫn Flip Image Winform
- [C#] Invoke là gì? cách sử dụng phương thức Invoke()
- [C#] Hướng dẫn chia sẽ file, folder từ ứng dụng sang Zalo Chat
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!