[英]winforms - how to move a picturebox within a tableLayoutPanel?
[英]How do you let the arrow keys move your focus around in WinForms TableLayoutPanel?
似乎默認是向上和向左鍵轉到上一個tabstop,向下/向右鍵轉到下一個tabstop。 我有一個TableLayoutPanel,每個都有一個按鈕。 是否有一種簡單的方法可以使箭頭鍵將單元格中的按鈕聚焦到TableLayoutPanel中的相應方向而不是僅僅跟隨tabstops?
是沒有問題。 只需創建自己的TableLayoutPanel覆蓋並讓它處理光標鍵即可獲得所需內容。 在項目中添加一個新類並粘貼下面顯示的代碼。 編譯。 將新面板從工具箱頂部拖放到表單上,替換舊表單。
using System;
using System.Windows.Forms;
class MyLayoutPanel : TableLayoutPanel {
protected override bool ProcessCmdKey(ref Message msg, Keys keyData) {
var ctl = this.FindForm().ActiveControl;
if (ctl.Parent == this) {
int col = this.GetColumn(ctl);
int row = this.GetRow(ctl);
if (keyData == Keys.Left && col > 0) {
var newctl = this.GetControlFromPosition(col - 1, row);
if (newctl != null) newctl.Focus();
return true;
}
// etc..
}
return base.ProcessCmdKey(ref msg, keyData);
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.