我剛開始使用 Visual Studio 和 Windows 表單應用程式開發 C#。我正在嘗試創建一個計算器,我想知道是否可以更改禁用按鈕上的游標型別,我不知道該怎么做,請幫助我,謝謝!
編輯:這是我試圖做的代碼,它只有在按鈕啟用時才有效......
private void txt_current_operation_MouseHover(object sender,EventArgs e) {
txt_current_operation.Cursor=Cursors.Hand;
}
uj5u.com熱心網友回復:
破解答案
假設 Button 包含在 Form 中,您可以處理 Form 的 MouseMove 事件并從那里更改游標:
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
Rectangle rc = txt_current_operation.RectangleToScreen(txt_current_operation.ClientRectangle);
this.Cursor = rc.Contains(Cursor.Position) ? Cursors.Hand : Cursors.Default;
}
如果 Button 包含在 Panel 或 Form 之外的其他容器中,那么您將改為更改為該容器的 MouseMove 事件。
示范:

轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/454318.html
