-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathControlExtentions.cs
54 lines (48 loc) · 1.84 KB
/
ControlExtentions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace DigitalPlatform.CommonControl
{
/// <summary>
/// TableLayoutPanel 扩展方法
/// </summary>
public static class TableLayoutPanelExtension
{
// 重新调整所有 TextBox 的高度
public static void ResetAllTextBoxHeight(this TableLayoutPanel panel)
{
// 如果没有这一句,在不断宽/窄变换 tablelayoutpanel 宽度的时候,内容区下面的空白区域会逐渐变大
panel.Height = 0;
panel.SuspendLayout();
foreach (Control control in panel.Controls)
{
if (control is AutoHeightTextBox && control.Visible == true)
{
(control as AutoHeightTextBox).SetHeight();
}
}
panel.ResumeLayout(false);
panel.PerformLayout();
}
// http://stackoverflow.com/questions/7142138/tablelayoutpanel-getcontrolfromposition-does-not-get-non-visible-controls-how-d
// TableLayoutPanel GetControlFromPosition does not get non-visible controls. How do you access a non-visible control at a specified position?
public static Control GetAnyControlAt(this TableLayoutPanel panel, int column, int row)
{
{
Control control = panel.GetControlFromPosition(column, row);
if (control != null)
return control;
}
foreach (Control control in panel.Controls)
{
var cellPosition = panel.GetCellPosition(control);
if (cellPosition.Column == column && cellPosition.Row == row)
return control;
}
return null;
}
}
}