本文整理汇总了C#中ListBox类的典型用法代码示例。如果您正苦于以下问题:C# ListBox类的具体用法?C# ListBox怎么用?C# ListBox使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ListBox类属于命名空间,在下文中一共展示了ListBox类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InitializeControls
public override void InitializeControls()
{
var lb = new ListBox(new Rectangle(0, 0, 800, 600),
ScreenManager.Content.Load<APNGTexture>(@"images\eagss.png"),
ScreenManager.Content.Load<APNGTexture>(@"images\thumb.png"));
lb.Items.Add(new ListBoxItem(""));
AddControl(lb);
var s = new Slider(new Vector3(300, 100, 400), false,
ScreenManager.Content.Load<APNGTexture>(@"images\thumb.png"),
ScreenManager.Content.Load<APNGTexture>(@"images\thumb_hover.png"))
{
ThumbLocation = 1f,
};
s.OnDrag += sender =>
{
DebugScreen.Output(sender.ThumbLocation.ToString());
};
AddControl(s);
base.InitializeControls();
}
示例2: MainForm
public MainForm ()
{
//
// _listBox
//
_listBox = new ListBox ();
_listBox.DisplayMember = "Name";
_listBox.Location = new Point (8, 8);
_listBox.Size = new Size (100, 60);
_listBox.ValueMember = "Value";
Controls.Add (_listBox);
//
//
//
_clearButton = new Button ();
_clearButton.Location = new Point (140, 30);
_clearButton.Text = "Clear";
_clearButton.Click += new EventHandler (ClearButton_Click);
Controls.Add (_clearButton);
//
// MainForm
//
ClientSize = new Size (240, 80);
Location = new Point (300, 100);
StartPosition = FormStartPosition.Manual;
Text = "bug #81788";
Load += new EventHandler (MainForm_Load);
}
示例3: FillLbCounty
public static void FillLbCounty(ListBox lb,string baseSite)
{
using (System.Net.WebClient wc = new System.Net.WebClient()) {
string html = wc.DownloadString(baseSite+"state_link_page.html");
//Check if page is meant to contain archived caches
Regex ar = new Regex(@"archived-GLX");
if (ar.IsMatch(html)) {
//parse country/county name and link to glx, both terms separated by non-greedy match .*?
//previous version: @"cachelink[^>]+href[^>]+\.html[^>]+>([^<]*)<.*?<a[^>]+href=""([^""]*\.glx)""",
Regex rgc = new Regex(
@"<tr(?:\n|.)*?<td.*?CacheList.*?(?:\n|.)*?/td>(?:\n|.)*?<td[^>]*>([^<]*)</td>(?:\n|.)*?<a[^>]*cachelink[^>]+href[^>]+\.html[^>]+>(?:\n|.)*?<a[^>]+href=""([^""]*\.glx)"""
,RegexOptions.Singleline);
MatchCollection mc = rgc.Matches(html);
foreach (Match m in mc) {
//htmldecode translates html entities
LbLink cl = new LbLink(m.Groups[2].Value,
System.Net.WebUtility.HtmlDecode(m.Groups[1].Value));
lb.Items.Add(cl);
}
if (lb.Items.Count>0) {
lb.SelectedIndex=0;
}
} else {
System.Windows.Forms.MessageBox.Show("Sorry: The directory of archived Caches on xylanthrop.de is of unknown format.");
}
}
}
示例4: ToolsListBox_SelectedItemChanged
private void ToolsListBox_SelectedItemChanged(object sender, ListBox<ListBoxItem>.SelectedItemEventArgs e)
{
if (selectedTool != null)
{
selectedTool.OnDeselected();
//if (selectedTool.ControlPanels != null)
// foreach (var pane in selectedTool.ControlPanels)
// {
// foreach (var control in pane.Controls)
// {
// Remove(control);
// }
// }
}
if (e.Item != null)
{
selectedTool = (ITool)e.Item;
EditorConsoleManager.ToolName = selectedTool.Title;
//EditorConsoleManager.AllowKeyboardToMoveConsole = true;
Panels.CharacterPickPanel.SharedInstance.HideCharacter = false;
Panels.CharacterPickPanel.SharedInstance.HideForeground = false;
Panels.CharacterPickPanel.SharedInstance.HideBackground = false;
selectedTool.OnSelected();
Panels.CharacterPickPanel.SharedInstance.Reset();
}
}
示例5: cargarLista
protected void cargarLista(ListBox lista)
{
lista.DataSource = CursoDao.ObtenerTodo();
lista.DataValueField = "id_curso";
lista.DataTextField = "nombre";
lista.DataBind();
}
示例6: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
sysManager = new SystemExerciseManager();
routManager = new routineManager();
logManager = new LoggedExerciseManager();
lb = (ListBox)this.Parent.FindControl("lbRoutines");
if (Session["loggedExerciseID"] != null)
{
loggedExerciseID = (int)Session["loggedExerciseID"];
}
if (!IsPostBack)
{
Session.Abandon();
pnlSets.Visible = false;
}
if (lb != null && lb.SelectedIndex > -1)
{
routineID = Convert.ToInt32(lb.SelectedItem.Value);
GridView1.DataSource = routManager.getLoggedExercises(userID, routineID);
GridView1.DataBind();
pnlSets.Visible = false;
}
}
示例7: DataContexts_Should_Be_Correctly_Set
public void DataContexts_Should_Be_Correctly_Set()
{
var items = new object[]
{
"Foo",
new Item("Bar"),
new TextBlock { Text = "Baz" },
new ListBoxItem { Content = "Qux" },
};
var target = new ListBox
{
Template = new FuncControlTemplate(CreateListBoxTemplate),
DataContext = "Base",
DataTemplates = new DataTemplates
{
new FuncDataTemplate<Item>(x => new Button { Content = x })
},
Items = items,
};
target.ApplyTemplate();
var dataContexts = target.Presenter.Panel.Children
.Cast<Control>()
.Select(x => x.DataContext)
.ToList();
Assert.Equal(
new object[] { items[0], items[1], "Base", "Base" },
dataContexts);
}
示例8: DataContexts_Should_Be_Correctly_Set
public void DataContexts_Should_Be_Correctly_Set()
{
using (UnitTestApplication.Start(TestServices.MockPlatformRenderInterface))
{
var items = new object[]
{
"Foo",
new Item("Bar"),
new TextBlock { Text = "Baz" },
new ListBoxItem { Content = "Qux" },
};
var target = new ListBox
{
Template = ListBoxTemplate(),
DataContext = "Base",
DataTemplates = new DataTemplates
{
new FuncDataTemplate<Item>(x => new Button { Content = x })
},
Items = items,
};
Prepare(target);
var dataContexts = target.Presenter.Panel.Children
.Cast<Control>()
.Select(x => x.DataContext)
.ToList();
Assert.Equal(
new object[] { items[0], items[1], "Base", "Base" },
dataContexts);
}
}
示例9: ShowDialog
public static string ShowDialog(string baseSite,string text, string caption)
{
Form prompt = new Form();
string resultURL="";
prompt.Width = 600;
prompt.Height = 420;
prompt.Text = caption;
Label textLabel = new Label() { Left = 10, Top=10, Width=580, Text=text };
ListBox lbCounty = new ListBox() { Left = 10, Top=40, Width=250, Height = 340, DisplayMember = "Label" };
Button confirmation = new Button() { Text = "Ok", Left=370, Width=100, Top=350 };
Button cancel = new Button() { Text = "Cancel", Left=480, Width=100, Top=350 };
confirmation.Click += (sender, e) => {
if(lbCounty.SelectedItem!=null) {resultURL=lbCounty.SelectedItem.ToString();}
prompt.Close();
};
lbCounty.DoubleClick += (sender, e) => { confirmation.PerformClick();};
cancel.Click += (sender, e) => { resultURL = "";prompt.Close(); };
prompt.Controls.Add(confirmation);
prompt.Controls.Add(cancel);
prompt.Controls.Add(textLabel);
prompt.Controls.Add(lbCounty);
FillLbCounty(lbCounty,baseSite);
prompt.ShowDialog();
return resultURL;
}
示例10: mnuHelpTopics
public mnuHelpTopics(string name)
: base(name)
{
this.Size = new Size(185, 220);
this.MenuDirection = Enums.MenuDirection.Vertical;
this.Location = new Point(10, 40);
lblHelpTopics = new Label("lblHelpTopics");
lblHelpTopics.Location = new Point(20, 0);
lblHelpTopics.Font = FontManager.LoadFont("PMU", 36);
lblHelpTopics.AutoSize = true;
lblHelpTopics.Text = "Help Topics";
lblHelpTopics.ForeColor = Color.WhiteSmoke;
lstHelpTopics = new ListBox("lstHelpTopics");
lstHelpTopics.Location = new Point(10, 50);
lstHelpTopics.Size = new Size(this.Width - lstHelpTopics.X * 2, this.Height - lstHelpTopics.Y - 10 - 30);
lstHelpTopics.BackColor = Color.Transparent;
lstHelpTopics.BorderStyle = SdlDotNet.Widgets.BorderStyle.None;
btnShowHelp = new Button("btnShowHelp");
btnShowHelp.Location = new Point(10, lstHelpTopics.Y + lstHelpTopics.Height + 5);
btnShowHelp.Size = new Size(100, 30);
btnShowHelp.Text = "Load Topic";
Skins.SkinManager.LoadButtonGui(btnShowHelp);
btnShowHelp.Click += new EventHandler<MouseButtonEventArgs>(btnShowHelp_Click);
this.AddWidget(lblHelpTopics);
this.AddWidget(lstHelpTopics);
this.AddWidget(btnShowHelp);
LoadHelpTopics();
}
示例11: GetListBoxSelValueInComma
public string GetListBoxSelValueInComma(ListBox Listbox1)
{
string selectedItem = "";
if (Listbox1.Items.Count > 0)
{
if (Listbox1.SelectedValue.ToString() == "0")
{
for (int i = 0; i < Listbox1.Items.Count; i++)
{
if (selectedItem == "")
selectedItem = Listbox1.Items[i].Value;
else
selectedItem += "\",\"" + Listbox1.Items[i].Value;
}
}
else
{
for (int i = 0; i < Listbox1.Items.Count; i++)
{
if (Listbox1.Items[i].Selected)
{
if (selectedItem == "")
selectedItem = Listbox1.Items[i].Value;
else
selectedItem += "\",\"" + Listbox1.Items[i].Value;
}
}
}
}
selectedItem = "\"" + selectedItem + "\"";
return selectedItem;
}
示例12: HelloForm
public HelloForm()
{
this.Text = "Hello Form";
this.StartPosition = FormStartPosition.CenterScreen;
this.FormBorderStyle = FormBorderStyle.FixedDialog;
this.ControlBox = true;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.BackColor = Color.Red;
lb = new ListBox();
lb.Left = 5;
lb.Width = this.Width - 20;
lb.Top = this.Height/6;
lb.Font = new Font(lb.Font, FontStyle.Bold);
for (int i = 0; i < strLines.Length; ++i)
{
lb.Items.Add(strLines[i]);
}
lb2 = new ListBox();
lb2.Left = 5;
lb2.Width = this.Width - 20;
lb2.Top = this.Height - 140;
lb2.Font = new Font(lb.Font, FontStyle.Bold);
_items.Add("One"); // <-- Add these
_items.Add("Two");
_items.Add("Three");
lb2.DataSource = _items;
this.Controls.Add(lb);
this.Controls.Add(lb2);
}
示例13: ListWithListBoxItems
public ListWithListBoxItems()
{
Title = "List with ListBoxItem";
ListBox lstbox = new ListBox();
lstbox.Height = 150;
lstbox.Width = 150;
lstbox.SelectionChanged += ListBoxOnSelectionChanged;
Content = lstbox;
PropertyInfo[] props = typeof(Colors).GetProperties();
foreach (PropertyInfo prop in props)
{
Color clr = (Color)prop.GetValue(null, null);
bool isBlack = .222 * clr.R + .707 * clr.G + .071 * clr.B > 128;
ListBoxItem item = new ListBoxItem();
item.Content = prop.Name;
item.Background = new SolidColorBrush(clr);
item.Foreground = isBlack ? Brushes.Black : Brushes.White;
item.HorizontalContentAlignment = HorizontalAlignment.Center;
item.Padding = new Thickness(2);
lstbox.Items.Add(item);
}
}
示例14: RemoteSwitchGUI
public RemoteSwitchGUI()
{
Text = "Remote Switch GUI 1.0.1";
Size = new Size(300, 500);
MinimumSize = new Size(260, 200);
panel = new Panel();
panel.Parent = this;
panel.Height = 40;
panel.Dock = DockStyle.Top;
listBox = new ListBox();
listBox.Parent = this;
listBox.Dock = DockStyle.Fill;
listBox.BringToFront();
buttonAOn = CreateButton("A On", 10, (1 << 0) | (1 << 2));
buttonAOff = CreateButton("A Off", 70, (1 << 0) | (1 << 3));
buttonBOn = CreateButton("B On", 130, (1 << 1) | (1 << 2));
buttonBOff = CreateButton("B Off", 190, (1 << 1) | (1 << 3));
Load += delegate(object sender, System.EventArgs e)
{
Thread thread = new Thread(delegate() { Connect(); });
thread.IsBackground = true;
thread.Start();
};
}
示例15: Initialize
protected override void Initialize()
{
base.Initialize();
//create a bunch of UI elements and link them to the state
ScrollPanel panel = new ScrollPanel(0, 0, 0, 400, 640, this);
panel.SetBackgroundColor(Color4.Red);
ScrollPanel panel2 = new ScrollPanel(420, 10, 0, 350, 500, this);
panel.SetContentDimensions(800, 800);
panel2.SetContentDimensions(400, 400);
Button button = new Button(10, 50, 0, 100, 100, "button.png", "button", this);
TextField field = new TextField(10, 10, 0, 100, this);
ListBox listBox = new ListBox(120, 10, 0, 200, 150, 10, this);
DropDownBox dropDown = new DropDownBox(50, 420, 0, 100, this);
TextBox textBox = new TextBox(10, 10, 0, 400, 400, this);
RadioButton radio = new RadioButton(200, 420, 0, this);
panel.AddControl(panel2);
panel.AddControl(dropDown);
panel.AddControl(textBox);
panel.AddControl(radio);
panel2.AddControl(button);
panel2.AddControl(field);
panel2.AddControl(listBox);
this.AddControl(panel);
}