***** Programmer *****
Bạn có muốn phản ứng với tin nhắn này? Vui lòng đăng ký diễn đàn trong một vài cú nhấp chuột hoặc đăng nhập để tiếp tục.
***** Programmer *****

Học lập trình từ căn bản

Tìm kiếm
 
 

Display results as :
 


Rechercher Advanced Search

Latest topics
» Tuyên mộ thành viên
[Toturial] Textbox EmptyWed Oct 24, 2012 5:28 am by quangvuspkt

» Bai tap Java can ban (Phan III )
[Toturial] Textbox EmptySat Sep 15, 2012 4:11 am by tsuyngam

» Bai tap Java can ban (Phan I )
[Toturial] Textbox EmptySat Sep 15, 2012 4:08 am by tsuyngam

» Một số bài tập C# căn bản
[Toturial] Textbox EmptyThu Dec 15, 2011 1:58 pm by nguyenhoduykhang

» Xem thông tin máy tính bằng c#
[Toturial] Textbox EmptyTue Nov 08, 2011 8:19 am by namcongtu288

» My First Browser Tree Program in VB.NET
[Toturial] Textbox EmptyFri Aug 12, 2011 5:50 pm by kimthaohg85

» Giúp em bài C++ này với
[Toturial] Textbox EmptySun Jul 31, 2011 12:19 pm by kubin

» GIUP DO XAY DUNG BO GO TIENG VIET CODE C#
[Toturial] Textbox EmptySun Jul 24, 2011 8:40 pm by phonui82

» CHÀO TẤT CẢ CÁC THÀNH VIÊN TRONG DIỄN ĐÀN
[Toturial] Textbox EmptyTue Jul 19, 2011 9:28 am by phonui82

Đăng Nhập

Quên mật khẩu



April 2024
MonTueWedThuFriSatSun
1234567
891011121314
15161718192021
22232425262728
2930     

Calendar Calendar


You are not connected. Please login or register

[Toturial] Textbox

Go down  Thông điệp [Trang 1 trong tổng số 1 trang]

1[Toturial] Textbox Empty [Toturial] Textbox Mon Feb 22, 2010 11:43 am

Tesulakata

Tesulakata
Thành viên
Thành viên

Textbox

How to: Select Text in the Windows Forms TextBox Control
< làm thế nào để : lựa chọn text trong điều khiển TextBox ở windows Forms >

Bạn có thể chọn văn bản trong lập trình điều khiển Windows Forms TextBox. Ví dụ, nếu bạn tạo một chức năng để tìm kiếm văn bản cho một chuỗi cụ thể, bạn có thể chọn văn bản để trực quan visually cảnh báo người đọc về vị trí của chuỗi hàng.

To select text programmatically
1. Set the SelectionStart property to the beginning of the text you want to select.
The SelectionStart property is a number that indicates the insertion point within the string of text, with 0 being the left-most position. If the SelectionStart property is set to a value equal to or greater than the number of characters in the text box, the insertion point is placed after the last character.
2. Set the SelectionLength property to the length of the text you want to select.
The SelectionLength property is a numeric value that sets the width of the insertion point. Setting the SelectionLength to a number greater than 0 causes that number of characters to be selected, starting from the current insertion point.
3. (Optional) Access the selected text through the SelectedText property.
The code below selects the contents of a text box when the control's Enter event occurs. The TextBox1_Enter event handler must be bound to the control; for more information, see How to: Create Event Handlers at Run Time for Windows Forms.
Để chọn văn bản trong lập trình


1. Đặt thuộc tính SelectionStart để bắt đầu ô text bạn muốn chọn.
Thiết lập các thuộc tính SelectionStart để bắt đầu của văn bản bạn muốn chọn.
Các thuộc tính SelectionStart là một số đó chỉ ra điểm chèn trong chuỗi các văn bản, với 0 là trái-vị trí nhất. Nếu tài sản SelectionStart được thiết lập là một giá trị bằng hoặc lớn hơn số ký tự trong hộp văn bản, điểm chèn được đặt sau khi ký tự cuối cùng.

2. Thiết lập các thuộc tính SelectionLength đến chiều dài của văn bản bạn muốn chọn.
Các thuộc tính SelectionLength là một giá trị số mà bộ chiều rộng của điểm chèn. Đặt SelectionLength cho một số lớn hơn 0 gây ra rằng số ký tự được lựa chọn, bắt đầu từ điểm chèn hiện hành.

3. (Tùy chọn) Truy cập vào các văn bản được lựa chọn thông qua các thuộc tính SelectedText.

Đoạn code dưới đây sẽ lựa chọn các nội dung của một hộp văn bản khi sự kiện của phím Enter xẩy ra. The handler TextBox1_Enter sự kiện phải được ràng buộc để kiểm soát; cho biết thêm thông tin, xem như thế nào: Tạo sự kiện Handlers tại thời gian chạy (Run Time) dành cho Windows Forms.




private void textBox1_Enter(object sender, System.EventArgs e){
textBox1.SelectionStart = 0;
textBox1.SelectionLength = textBox1.Text.Length;
}

II- How to: Put Quotation Marks in a String (Windows Forms)
< Làm thế nào để dấu “” trong một chuỗi ( Windows Forms) >
Đây là 1 ví dụ :
private void InsertQuote(){
textBox1.Text = "She said, \"You deserve a treat!\" ";
}

 thêm \” nội dung text \” là ok ^^
III - How to: Create a Read-Only Text Box (Windows Forms)
< Tạo ô TextBox chỉ đọc >

IV – How to: Create a Password Text Box with the Windows Forms TextBox Control
< Tạo textbox password – ô nhập mật khẩu ấy >
Vd:
private void InitializeMyControl()
{
// Set to no text.
textBox1.Text = "";
// The password character is an asterisk.
textBox1.PasswordChar = '*';
// The control will allow no more than 14 characters.
textBox1.MaxLength = 14;
}


V – How to: Control the Insertion Point in a Windows Forms TextBox Control
< Làm thế nào để kiểm soát điểm chèn ( Insertion Point ) trong Windows Forms TextBox>
When a Windows Forms TextBox control first receives the focus, the default insertion within the text box is to the left of any existing text. The user can move the insertion point with the keyboard or the mouse. If the text box loses and then regains the focus, the insertion point will be wherever the user last placed it.
In some cases, this behavior can be disconcerting to the user. In a word processing application, the user might expect new characters to appear after any existing text. In a data entry application, the user might expect new characters to replace any existing entry. The SelectionStart and SelectionLength properties enable you to modify the behavior to suit your purpose.
Trong một số trường hợp , sử dụng Behavior có thể gây khó khăn ( bổi rối, disconcerting ) với người dùng. Một ứng dụng xử lý từ ngữ, người sử dụng có thể trông đợi 1 kí tự mới sau khi có văn bản xuất hiện ( existing). Trong ứng dụng về dữ liệu, người dùng có thể trông đợi 1 kí tự, sự kiện thay thế nào đó xayar ra. Thuộc tính SelectionStart và SelectionLength cho phép biến đổi các hành vi (behavior) nhằm phù hợp với mục đích (purpose) của bạn…
Example
private void textBox1_Enter(Object sender, System.EventArgs e) {
textBox1.SelectionStart = 0;
textBox1.SelectionLength = 0;
}



VI – How to: Bind Data to the MaskedTextBox Control
< Điền dữ liệu vào MaskedTextBox >
You can bind data to a MaskedTextBox control just as you can to any other Windows Forms control. However, if the format of your data in the database does not match the format expected by your mask definition, you will need to reformat the data. The following procedure demonstrates how to do this using the Format and Parse events of the Binding class to display separate phone number and phone extension database fields as a single editable field.
Bạn có thể dữ liệu kết vào một điều khiển MaskedTextBox cũng giống như bạn có thể đến bất kỳ điều khiển khác Forms Windows. Tuy nhiên, nếu các định dạng dữ liệu của bạn trong cơ sở dữ liệu không phù hợp với định dạng mặt nạ dự kiến theo định nghĩa của bạn, bạn sẽ cần phải định dạng dữ liệu. Thủ tục sau đây chứng tỏ làm thế nào để làm điều này bằng cách sử dụng các dạng và Parse sự kiện của lớp đóng để hiển thị số điện thoại riêng và cơ sở dữ liệu điện thoại mở rộng các lĩnh vực như là một lĩnh vực có thể chỉnh sửa duy nhất.
The following procedure requires that you have access to a SQL Server database with the Northwind sample database installed.
Thủ tục sau khá quan trọng để bạn có quyền truy cập vào cơ sở dữ liệu SQL với dữ liệu mẫu của Northwind
To bind data to a MaskedTextBox control
1. Create a new Windows Forms project.
Tạo một dự án Windows Forms
2. Drag two TextBox controls onto your form; name them FirstName and LastName.
Kéo 2 TextBox vô form. Tên như sau :
3. Drag a MaskedTextBox control onto your form; name it PhoneMask.
Kéo một cái MaskedTextBox vô form nữa. tên như sau :
4. Set the Mask property of PhoneMask to (000) 000-0000 x9999.
Đặt thuộc tính Mask của PhoneMask từ :
5. Add the following namespace imports to the form.
Thêm vào đoạn namespace vô form:
Binding currentBinding, phoneBinding;
DataSet employeesTable = new DataSet();
SqlConnection sc;
SqlDataAdapter dataConnect;

private void Form1_Load(object sender, EventArgs e)
{
DoMaskBinding();
}

private void DoMaskBinding()
{
try
{
sc = new SqlConnection("Data Source=CLIENTUE;Initial Catalog=NORTHWIND;Integrated Security=SSPI");
sc.Open();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return;
}

dataConnect = new SqlDataAdapter("SELECT * FROM Employees", sc);
dataConnect.Fill(employeesTable, "Employees");

// Now bind MaskedTextBox to appropriate field. Note that we must create the Binding objects
// before adding them to the control - otherwise, we won't get a Format event on the
// initial load.
try
{
currentBinding = new Binding("Text", employeesTable, "Employees.FirstName");
firstName.DataBindings.Add(currentBinding);

currentBinding = new Binding("Text", employeesTable, "Employees.LastName");
lastName.DataBindings.Add(currentBinding);

phoneBinding =new Binding("Text", employeesTable, "Employees.HomePhone");
// We must add the event handlers before we bind, or the Format event will not get called
// for the first record.
phoneBinding.Format += new ConvertEventHandler(phoneBinding_Format);
phoneBinding.Parse += new ConvertEventHandler(phoneBinding_Parse);
phoneMask.DataBindings.Add(phoneBinding);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
return;
}
}


VII – Walkthrough: Working with the MaskedTextBox Control
Tasks illustrated in this walkthrough include:
• Initializing the MaskedTextBox control
• Using the MaskInputRejected event handler to alert the user when a character does not conform to the mask
• Assigning a type to the ValidatingType property and using the TypeValidationCompleted event handler to alert the user when the value they're attempting to commit is not valid for the type
For a full working version of the MaskedTextBox control that demonstrates advanced features such as validation using custom data types, see MaskedTextBox Control Sample.
Creating the Project and Adding a Control
To add a MaskedTextBox control to your form
1. Open the form on which you want to place the MaskedTextBox control.
2. Drag a MaskedTextBox control from the Toolbox to your form.
3. Right-click the control and choose Properties. In the Properties window, select the Mask property and click the ... (ellipsis) button next to the property name.
4. In the Input Mask dialog box, select the Short Date mask and click OK.
5. In the Properties window set the BeepOnError property to true. This property causes a short beep to sound every time the user attempts to input a character that violates the mask definition.

Alert the User to Input Errors
Add a balloon tip for rejected mask input
1. Return to the Toolbox and add a ToolTip to your form.
2. Create an event handler for the MaskInputRejected event that raises the ToolTip when an input error occurs. The balloon tip remains visible for five seconds, or until the user clicks it.



VIII

IX
X
XI
XII
XIII
XIV
XV
XVI
XVII
XVIII
XIX
XX

https://programmer.4umer.com

Về Đầu Trang  Thông điệp [Trang 1 trong tổng số 1 trang]

Permissions in this forum:
Bạn không có quyền trả lời bài viết