Bạn sẽ muốn PictureBox để tham gia vào trật tự tabbing và cho thấy rằng nó có trọng tâm. Phải mất một chút phẫu thuật nhỏ. Thêm một lớp mới vào dự án của bạn và dán mã được hiển thị bên dưới. Biên dịch. Thả điều khiển mới từ đầu hộp công cụ lên biểu mẫu của bạn. Triển khai sự kiện KeyDown.
using System;
using System.Drawing;
using System.Windows.Forms;
class SelectablePictureBox : PictureBox {
public SelectablePictureBox() {
this.SetStyle(ControlStyles.Selectable, true);
this.TabStop = true;
}
protected override void OnMouseDown(MouseEventArgs e) {
this.Focus();
base.OnMouseDown(e);
}
protected override void OnEnter(EventArgs e) {
this.Invalidate();
base.OnEnter(e);
}
protected override void OnLeave(EventArgs e) {
this.Invalidate();
base.OnLeave(e);
}
protected override void OnPaint(PaintEventArgs pe) {
base.OnPaint(pe);
if (this.Focused) {
var rc = this.ClientRectangle;
rc.Inflate(-2, -2);
ControlPaint.DrawFocusRectangle(pe.Graphics, rc);
}
}
}
Nguồn
2010-04-30 12:33:10
bằng ngôn ngữ phù thủy, muốn bạn làm điều đó? – Werewolve
@were: Tôi nghĩ bạn có thể giả sử C# hoặc VB.NET. Các cựu có vẻ là phổ biến hơn. Tuy nhiên, bản dịch * mã * phải là vấn đề nhỏ nhất. – Joey
C# và tôi có thể đọc vb tốt. Có lẽ tôi sẽ xem xét kéo đối tượng offscreen một giải pháp xóa. Để xấu tôi đã không nghĩ về nó ngay lập tức. –