本文整理汇总了C#中System.Windows.Forms.BindingSource类的典型用法代码示例。如果您正苦于以下问题:C# BindingSource类的具体用法?C# BindingSource怎么用?C# BindingSource使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BindingSource类属于System.Windows.Forms命名空间,在下文中一共展示了BindingSource类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: Main
//引入命名空间
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace BindingSourceExamples
{
public class Form1 : Form
{
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.Run(new Form1());
}
public Form1()
{
this.Load += new EventHandler(Form1_Load);
}
private TextBox textBox1;
private Button button1;
private ListBox listBox1;
private BindingSource binding1;
void Form1_Load(object sender, EventArgs e)
{
listBox1 = new ListBox();
textBox1 = new TextBox();
binding1 = new BindingSource();
button1 = new Button();
listBox1.Location = new Point(140, 25);
listBox1.Size = new Size(123, 160);
textBox1.Location = new Point(23, 70);
textBox1.Size = new Size(100, 20);
textBox1.Text = "Wingdings";
button1.Location = new Point(23, 25);
button1.Size = new Size(75, 23);
button1.Text = "Search";
button1.Click += new EventHandler(this.button1_Click);
this.ClientSize = new Size(292, 266);
this.Controls.Add(this.button1);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.listBox1);
MyFontList fonts = new MyFontList();
for (int i = 0; i < FontFamily.Families.Length; i++)
{
if (FontFamily.Families[i].IsStyleAvailable(FontStyle.Regular))
fonts.Add(new Font(FontFamily.Families[i], 11.0F, FontStyle.Regular));
}
binding1.DataSource = fonts;
listBox1.DataSource = binding1;
listBox1.DisplayMember = "Name";
}
private void button1_Click(object sender, EventArgs e)
{
if (binding1.SupportsSearching != true)
{
MessageBox.Show("Cannot search the list.");
}
else
{
int foundIndex = binding1.Find("Name", textBox1.Text);
if (foundIndex > -1)
listBox1.SelectedIndex = foundIndex;
else
MessageBox.Show("Font was not found.");
}
}
}
public class MyFontList : BindingList<Font>
{
protected override bool SupportsSearchingCore
{
get { return true; }
}
protected override int FindCore(PropertyDescriptor prop, object key)
{
// Ignore the prop value and search by family name.
for (int i = 0; i < Count; ++i)
{
if (Items[i].FontFamily.Name.ToLower() == ((string)key).ToLower())
return i;
}
return -1;
}
}
}
开发者ID:.NET开发者,项目名称:System.Windows.Forms,代码行数:96,代码来源:BindingSource
注:本文中的System.Windows.Forms.BindingSource类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论