核心提示:winform笔记:1.combobox 数据绑定。comboBox.DisplayMember = 需要读取的列1(name); //显示到comboBox的值comboBox.ValueMembe...
winform笔记:1.combobox 数据绑定。
comboBox.DisplayMember = "需要读取的列1(name)"; //显示到comboBox的值 comboBox.ValueMember = "需要读取的列2(id)"; //comboBox真正的值 comboBox.DataSource = ds.Tables["虚拟列名"];//绑定数据源
2.FlowLayoutPanel支持鼠标滚轮滚动
FlowLayoutPanel控件不直接支持MouseWheel事件.即滚动滚轮也不会响应.所以必须手动来支持响应滚轮.
FlowLayoutPanel控件继承于Panel控件,Panel控件也是直接不支持MouseWheel事件
你可以添加MouseWheel事件,然后写上支持滚动的功能.也可以直接重写该控件.这样可以复用该控件.
如果只支持MouseWheel事件,还是不一定在滚动滚轮的时候,就能引发MouseWheel事件.所以,必须让鼠标停留在控件上时,让控件处于输入焦点状态.这是,滚动滚轮就可以引发MouseWheel事件了.
//添加两个事件
autoLayout.Click += AutoLayout_Click;
autoLayout.MouseWheel += AutoLayout_MouseWheel;
private void AutoLayout_Click(object sender, EventArgs e)
{
// 在点击事件中获取焦点
autoLayout.Focus();
}
private void AutoLayout_MouseWheel(object sender, MouseEventArgs e)
{
if (e.Delta < 0)
{
if (this.VerticalScroll.Maximum > this.VerticalScroll.Value + 50)
this.VerticalScroll.Value += 50;
else
this.VerticalScroll.Value = this.VerticalScroll.Maximum;
}
else
{
if (this.VerticalScroll.Value > 50)
this.VerticalScroll.Value -= 50;
else
{
this.VerticalScroll.Value = 0;
}
}
}
3.ListViewItem和ListViewSubItem关系
item.Text = i.TITLE;
item.SubItems.Add(i.CONTENT);
item.SubItems.Add(i.ID);
// SubItems[0]=item.Text,取数据的时候要注意
// content就是SubItems[1]
4.如何移除自身
控件的Parent方法可以拿到父控件
private void Button_Click(object sender, EventArgs e)
{
Button button = (Button)sender;
button.Parent.Controls.Remove(button);
}


