在我的C#winforms应用程序中,我有一个数据网格.当datagrid重新加载时,我想将滚动条设置回用户设置的位置.我怎样才能做到这一点?
编辑:我正在使用旧的winforms DataGrid控件,而不是较新的DataGridView
两个标签都有AutoSizetrue 和TextAlignMiddleCenter。
label2 如何也能显示平滑的边框?
这是处理程序Form.Load(...)&的测试代码Form.Paint(...):
int _cornerRadius = 10;
Point _locationLabel2;
// Form.Load(...)
private void Form3_Load(object sender, EventArgs e)
{
// Step 1: Cut the label regions (seems to be ok, result is the same for both labels)
GraphicsPath graphicsPath = _getRoundPath(label1.ClientRectangle, _cornerRadius);
label1.Region = new Region(graphicsPath);
graphicsPath = _getRoundPath(label2.ClientRectangle, _cornerRadius);
label2.Region = new Region(graphicsPath);
_locationLabel2 = this.PointToClient(label2.Parent.PointToScreen(label2.Location));
}
// Form.Paint(...)
private void Form3_Paint(object sender, PaintEventArgs e)
{
using (Pen pen = …Run Code Online (Sandbox Code Playgroud) List<string> testList = new List<string>();
testList.Add("A");
testList.Add("A");
testList.Add("C");
testList.Add("d");
testList.Add("D");
Run Code Online (Sandbox Code Playgroud)
此查询区分大小写:
// Result: "A"
List<String> duplicates = testList.GroupBy(x => x)
.Where(g => g.Count() > 1)
.Select(g => g.Key)
.ToList();
Run Code Online (Sandbox Code Playgroud)
它如何看起来不区分大小写?(结果:"A","d")
我正在尝试使用SortedList与不区分大小写的字符串比较.以下是有效的:
SortedList mySL = new SortedList(new CaseInsensitiveComparer());
mySL.Add("key_1", "val_1");
mySL.Add("key_2", "val_2");
mySL.Add("key_3", "val_3");
if (mySL.ContainsKey("KEY_1"))
MessageBox.Show("is there"); // message appears
else
MessageBox.Show("not found");
Run Code Online (Sandbox Code Playgroud)
但这不是:
public class MySL : SortedList
{
// The only constructor
public MySL(IComparer comparer) {}
...
}
MySL sl = new MySL(new CaseInsensitiveComparer());
sl.Add("key_1", "val_1");
sl.Add("key_2", "val_2");
sl.Add("key_3", "val_3");
if (sl.ContainsKey("KEY_1"))
MessageBox.Show("is there");
else
MessageBox.Show("not found"); // message appears
Run Code Online (Sandbox Code Playgroud)
有人能看出什么问题吗?