【问题标题】:how to determine the mouse pointer is on tablelayoutpanel cell border c#如何确定鼠标指针在 tablelayoutpanel 单元格边框上 c#
【发布时间】:2023-02-10 06:19:00
【问题描述】:
我在 Windows 窗体上有 TableLayoutPanel。当指针在单元格边框上/附近时,我希望鼠标指针光标样式为交叉。
我尝试使用鼠标移动事件。我得到了鼠标点移动的单元格位置。但我无法使用这些信息,我被卡住了。怎样才能做到呢?
【问题讨论】:
标签:
c#
winforms
tablelayoutpanel
mouse-position
【解决方案1】:
如果我明白你的要求,只要你在 TableLayoutPanel 的单元格中有控件,所有需要做的就是为以下内容设置不同的光标:
- 主窗体(箭头)
- 表格布局面板(十字)
- 其中包含的控件(例如 Hand)
其他一切都应该自行发生。
public MainForm()
{
InitializeComponent();
// MainForm has ARROW
this.Cursor = Cursors.Arrow;
// TableLayoutPanel has CROSS
tableLayoutPanel.Cursor = Cursors.Cross;
for (int column = 0; column < tableLayoutPanel.ColumnCount; column++)
for (int row = 0; row < tableLayoutPanel.RowCount; row++)
{
tableLayoutPanel.Controls.Add(new Panel
{
BackColor = Color.LightGreen,
Anchor = (AnchorStyles)0xF,
Margin = new Padding(10),
// Controls in the table have HAND
Cursor = Cursors.Hand,
});
}
}