本文整理汇总了C#中System.Windows.Forms.CheckedListBox.GetItemCheckState方法的典型用法代码示例。如果您正苦于以下问题:C# CheckedListBox.GetItemCheckState方法的具体用法?C# CheckedListBox.GetItemCheckState怎么用?C# CheckedListBox.GetItemCheckState使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.CheckedListBox
的用法示例。
在下文中一共展示了CheckedListBox.GetItemCheckState方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CheckedListBoxPropertyTest
public void CheckedListBoxPropertyTest ()
{
Form myform = new Form ();
myform.ShowInTaskbar = false;
myform.Visible = true;
CheckedListBox mychklistbox = new CheckedListBox ();
ArrayList checked_items = new ArrayList (2);
ArrayList checked_pos = new ArrayList (2);
mychklistbox.Items.Add ("test1", true);
checked_items.Add ("test1"); checked_pos.Add (0);
mychklistbox.Items.Add ("test2");
mychklistbox.Items.Add ("test3", true);
checked_items.Add ("test3"); checked_pos.Add (2);
mychklistbox.Visible = true;
myform.Controls.Add (mychklistbox);
Assert.AreEqual (checked_items.Count, mychklistbox.CheckedIndices.Count, "#1");
Assert.AreEqual (checked_items.Count, mychklistbox.CheckedItems.Count, "#2");
foreach (object o in mychklistbox.CheckedItems)
{
Assert.IsTrue (checked_items.Contains (o),"#3");
checked_items.Remove (o);
}
Assert.AreEqual (0, checked_items.Count);
for (int i = 0; i < mychklistbox.Items.Count; ++i)
{
if (checked_pos.Contains (i))
Assert.AreEqual (CheckState.Checked, mychklistbox.GetItemCheckState (i),"#4");
else
Assert.IsFalse (CheckState.Checked == mychklistbox.GetItemCheckState (i),"#5");
}
Assert.AreEqual (false, mychklistbox.CheckOnClick, "#6");
Assert.AreEqual (3, mychklistbox.Items.Count, "#7");
Assert.AreEqual (SelectionMode.One, mychklistbox.SelectionMode, "#8");
Assert.AreEqual (false , mychklistbox.ThreeDCheckBoxes, "#9");
myform.Dispose ();
}
示例2: getCheckedItemsInCheckedListBox
/*
* Returns a list of the a checked characters in the passed in checked list box
*/
private List<int> getCheckedItemsInCheckedListBox(CheckedListBox checkedListbox)
{
List<int> checkedItems = new List<int>();
// Get all checked items in checkbox list
for (int i = 0; i < checkedListbox.Items.Count; i++)
{
if (checkedListbox.GetItemCheckState(i) == CheckState.Checked)
{
checkedItems.Add(i);
}
}
return checkedItems;
}
示例3: SetItemCheckStateTest
public void SetItemCheckStateTest ()
{
Form myform = new Form ();
myform.ShowInTaskbar = false;
myform.Visible = true;
CheckedListBox mychklistbox = new CheckedListBox ();
mychklistbox.Items.Add ("test1");
mychklistbox.Items.Add ("test2");
mychklistbox.Items.Add ("test3");
mychklistbox.Visible = true;
myform.Controls.Add (mychklistbox);
mychklistbox.SetItemCheckState (0,CheckState.Checked);
mychklistbox.SetItemCheckState (1,CheckState.Indeterminate);
mychklistbox.SetItemCheckState (2,CheckState.Unchecked);
Assert.AreEqual (CheckState.Checked, mychklistbox.GetItemCheckState (0), "#19");
Assert.AreEqual (CheckState.Indeterminate, mychklistbox.GetItemCheckState (1), "#20");
Assert.AreEqual (CheckState.Unchecked, mychklistbox.GetItemCheckState (2), "#21");
myform.Dispose ();
}
示例4: SetItemCheckedTest
public void SetItemCheckedTest ()
{
Form myform = new Form ();
myform.ShowInTaskbar = false;
myform.Visible = true;
CheckedListBox mychklistbox = new CheckedListBox ();
mychklistbox.Items.Add ("test1");
mychklistbox.Items.Add ("test2");
mychklistbox.Visible = true;
myform.Controls.Add (mychklistbox);
mychklistbox.SetItemChecked (0,true);
mychklistbox.SetItemChecked (1,false);
Assert.AreEqual (CheckState.Checked, mychklistbox.GetItemCheckState (0), "#17");
Assert.AreEqual (CheckState.Unchecked, mychklistbox.GetItemCheckState (1), "#18");
myform.Dispose ();
}
示例5: GetItemCheckStateTest
public void GetItemCheckStateTest ()
{
Form f = new Form ();
f.ShowInTaskbar = false;
f.Visible = true;
CheckedListBox mychklistbox = new CheckedListBox ();
mychklistbox.Items.Add ("test1",true);
mychklistbox.Items.Add ("test2",CheckState.Indeterminate);
mychklistbox.Items.Add ("test3");
mychklistbox.Visible = true;
f.Controls.Add (mychklistbox);
Assert.AreEqual (CheckState.Checked, mychklistbox.GetItemCheckState (0), "#14");
Assert.AreEqual (CheckState.Indeterminate, mychklistbox.GetItemCheckState (1), "#15");
Assert.AreEqual (CheckState.Unchecked, mychklistbox.GetItemCheckState (2), "#16");
f.Dispose ();
}
示例6: GetStringsFromCheckedListBox
private string[] GetStringsFromCheckedListBox(CheckedListBox checkedListBox)
{
string[] checkedItems = new string[checkedListBox.Items.Count];
for (int index = 0; index < checkedListBox.Items.Count; ++index)
{
string selectedItemName = checkedListBox.Items[index] as string;
checkedItems[index] = string.Format(CultureInfo.InvariantCulture, "{0},{1}", selectedItemName,
Convert.ToString((checkedListBox.GetItemCheckState(index) == CheckState.Checked), CultureInfo.InvariantCulture));
}
return checkedItems;
}
示例7: UserCKChangeSet
/// <summary>
/// 角色选择状态改变
/// </summary>
private string UserCKChangeSet(CheckedListBox checkbox)
{
string checkStr = "";
if (checkbox.Items.Count > 0)
{
for (int i = 0; i < checkbox.Items.Count; i++)
{
if (checkbox.GetItemCheckState(i) == CheckState.Checked)
{
checkbox.SelectedIndex = i;
checkStr += checkbox.SelectedValue + ",";
}
}
}
return checkStr;
}
示例8: copyPanelItems
private void copyPanelItems(Tuple<string, Func<int, int, int>, int, int, int, int, int>[] panelSrc,
CheckedListBox listSrc,
Tuple<string, Func<int, int, int>, int, int, int, int, int>[] panelDest,
CheckedListBox listDest)
{
for (int a = 0; a < panelSrc.Length; a++)
{
if (panelSrc[a] != null)
{
// copy panel item
panelDest[a] = new Tuple<string,Func<int,int,int>,int,int,int,int,int>(
panelSrc[a].Item1, panelSrc[a].Item2, panelSrc[a].Item3, panelSrc[a].Item4, panelSrc[a].Item5, panelSrc[a].Item6, panelSrc[a].Item7);
// copy checked item list
listDest.SetItemCheckState(a, listSrc.GetItemCheckState(a));
}
else
{
panelDest[a] = null;
}
}
}
示例9: DualChListMouseEvent
/// <summary>
/// Left mouse click: check/uncheck the item.
/// Middle mouse click: remove item.
/// Right mouse click: send item from chList1 to chList2.
/// </summary>
/// <param name="chList1"> The handled checkedListBox. </param>
/// <param name="chList2"> The dual checkedListBox. </param>
/// <param name="e"> The mouse click event. </param>
public static void DualChListMouseEvent(CheckedListBox chList1, CheckedListBox chList2, MouseEventArgs e, Point mousePosition, bool useDual = true)
{
if (e.Button == System.Windows.Forms.MouseButtons.Right)
{
for (int i = 0; i < chList1.Items.Count; i++)
{
if (i != 0 || useDual)
{
if (chList1.GetItemRectangle(i).Contains(chList1.PointToClient(mousePosition)))
{
chList2.AddOrderedFromBottom(chList1.GetText(i), chList1.GetItemChecked(i));
chList1.Items.RemoveAt(i);
}
}
}
}
else if (e.Button == System.Windows.Forms.MouseButtons.Middle)
{
for (int i = 0; i < chList1.Items.Count; i++)
{
if (i != 0 || useDual)
{
if (chList1.GetItemRectangle(i).Contains(chList1.PointToClient(mousePosition)))
{
chList1.Items.RemoveAt(i);
}
}
}
}
else if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
for (int i = 0; i < chList1.Items.Count; i++)
{
if (chList1.GetItemRectangle(i).Contains(chList1.PointToClient(mousePosition)))
{
switch (chList1.GetItemCheckState(i))
{
case CheckState.Checked:
chList1.SetItemCheckState(i, CheckState.Unchecked);
break;
case CheckState.Indeterminate:
case CheckState.Unchecked:
chList1.SetItemCheckState(i, CheckState.Checked);
break;
}
}
}
}
}