当前位置: 首页>>代码示例>>C#>>正文


C# ListBox.SetSelected方法代码示例

本文整理汇总了C#中ListBox.SetSelected方法的典型用法代码示例。如果您正苦于以下问题:C# ListBox.SetSelected方法的具体用法?C# ListBox.SetSelected怎么用?C# ListBox.SetSelected使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ListBox的用法示例。


在下文中一共展示了ListBox.SetSelected方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: MainDialog

    public MainDialog()
    {
        leftPadCol1 = 11;
        leftPadCol2 = 181;
        leftPadCol3 = 311;

        Text="Mouse";
        StartPosition = FormStartPosition.Manual;
        Location = new Point(100, 100);
        Size = new Size(600, 400);

        Closed += new EventHandler(MainDialog_Closed);

        //left column
        m_LB = new ListBox();
        m_LB.Items.Clear();
        m_LB.IntegralHeight = false;
        m_LB.Location = new Point(leftPadCol1, 10);
        m_LB.Size = new Size(160, 190);
        m_LB.Items.AddRange(new object[]{"Red", "Orange", "Yellow", "Green", "Blue", "Indigo", "Violet"});
        m_LB.SelectionMode = SelectionMode.One;
        m_LB.SetSelected(1, true);
        m_LB.SelectedIndexChanged += new EventHandler(LB_SelIndChanged);
        Controls.Add(m_LB);

        m_B_Create = new Button();
        m_B_Create.Text = "Create";
        m_B_Create.Location = new Point(5, 20);
        m_B_Create.Size = new Size(100, 24);
        m_B_Create.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
        m_B_Create.Click += new System.EventHandler(B_C_Create);
        m_B_Create.BackColor = Color.Green;
        Controls.Add(m_B_Create);

        m_B_Edit = new Button();
        m_B_Edit.Text = "Edit";
        m_B_Edit.Location = new Point(5, 50);
        m_B_Edit.Size = new Size(100, 24);
        m_B_Edit.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
        m_B_Edit.Click += new System.EventHandler(B_C_Edit);
        m_B_Edit.BackColor = Color.Blue;
        Controls.Add(m_B_Edit);

        m_B_Delete = new Button();
        m_B_Delete.Text = "Delete";
        m_B_Delete.Location = new Point(5, 80);
        m_B_Delete.Size = new Size(100, 24);
        m_B_Delete.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
        m_B_Delete.Click += new System.EventHandler(B_C_Delete);
        m_B_Delete.BackColor = Color.Red;
        Controls.Add(m_B_Delete);

        m_GB_Button = new GroupBox();
        m_GB_Button.Text = "Edit list";
        m_GB_Button.Location = new Point(leftPadCol1, 211);
        m_GB_Button.Size = new Size(110, 110);
        m_GB_Button.Controls.AddRange(new Control[] {m_B_Create, m_B_Edit, m_B_Delete});
        Controls.Add(m_GB_Button);

        //middle column
        m_LabelName = new Label();
        m_LabelName.Text = "Name";
        m_LabelName.Name = "LabelName";
        m_LabelName.Location = new Point(leftPadCol2, 10);
        m_LabelName.Size = new Size(120, 16);
        m_LabelName.TextAlign = ContentAlignment.MiddleLeft;
        m_LabelName.Font = new Font("Arial", 10F, FontStyle.Italic | FontStyle.Bold);
        m_LabelName.ForeColor = Color.FromArgb(0, 0, 0);
        Controls.Add(m_LabelName);

        m_LabelColor = new Label();
        m_LabelColor.Text = "Color";
        m_LabelColor.Name = "LabelColor";
        m_LabelColor.Location = new Point(leftPadCol2, 40);
        m_LabelColor.Size = new Size(120, 16);
        m_LabelColor.TextAlign = ContentAlignment.MiddleLeft;
        m_LabelColor.Font = new Font("Arial", 10F, FontStyle.Italic | FontStyle.Bold);
        m_LabelColor.ForeColor = Color.FromArgb(0, 0, 0);
        Controls.Add(m_LabelColor);

        m_LabelSite = new Label();
        m_LabelSite.Text = "Web Site";
        m_LabelSite.Name = "LabelSite";
        m_LabelSite.Location = new Point(leftPadCol2, 130);
        m_LabelSite.Size = new Size(120, 16);
        m_LabelSite.TextAlign = ContentAlignment.MiddleLeft;
        m_LabelSite.Font = new Font("Arial", 10F, FontStyle.Italic | FontStyle.Bold);
        m_LabelSite.ForeColor = Color.FromArgb(0, 0, 0);
        Controls.Add(m_LabelSite);

        //right column
        m_TBName = new TextBox();
        m_TBName.Text = "";
        m_TBName.Location = new Point(leftPadCol3, 10);
        m_TBName.Size = new Size(120, 16);
        m_TBName.Multiline = false;
        m_TBName.MaxLength = 1000;
        m_TBName.ScrollBars = ScrollBars.Both;
        m_TBName.WordWrap = false;
        m_TBName.TextChanged += new EventHandler(TB_TextChanged);
//.........这里部分代码省略.........
开发者ID:alrykov,项目名称:Lab2,代码行数:101,代码来源:DialogBasedApp.cs

示例2: MainDialog

    public MainDialog()
    {
        Text="Dialog based application";
        StartPosition = FormStartPosition.Manual;
        Location = new Point(100, 100);
        Size = new Size(700, 400);

        Closed += new EventHandler(MainDialog_Closed);

        m_Label = new Label();
        m_Label.Text = ".Net Framevork";
        m_Label.Name = "Label1";
        m_Label.Location = new Point(16, 16);
        m_Label.Size = new Size(120, 16);
        m_Label.TextAlign = ContentAlignment.MiddleCenter;
        m_Label.Font = new Font("Arial", 10F, FontStyle.Italic | FontStyle.Bold);
        m_Label.ForeColor = Color.FromArgb(255, 0, 0);
        Controls.Add(m_Label);

        m_LLabel = new LinkLabel();
        m_LLabel.Name = "Label2";
        //m_LLabel.Text = "www.microsoft.com";
        m_LLabel.Text = "text.txt";
        m_LLabel.Location = new Point(16, 40);
        m_LLabel.Size = new Size(120, 16);
        m_LLabel.TextAlign = ContentAlignment.MiddleCenter;
        m_LLabel.LinkClicked += new LinkLabelLinkClickedEventHandler(L2_LClicked);
        Controls.Add(m_LLabel);

        m_B = new Button();
        m_B.Text = "Push me";
        m_B.Location = new Point(18, 70);
        m_B.Size = new Size(100, 24);
        m_B.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
        m_B.Click += new System.EventHandler(B_C);
        Controls.Add(m_B);

        m_TB = new TextBox();
        m_TB.Text = "";
        m_TB.Location = new Point(140, 16);
        m_TB.Size = new Size(160, 190);
        m_TB.Multiline = true;
        m_TB.MaxLength = 1000;
        m_TB.ScrollBars = ScrollBars.Both;
        m_TB.WordWrap = false;
        m_TB.TextChanged += new EventHandler(TB_TextChanged);
        Controls.Add(m_TB);

        m_RB_Red = new RadioButton();
        m_RB_Red.Text = "Red";
        m_RB_Red.Checked = false;
        m_RB_Red.Location = new Point(16, 16);
        m_RB_Red.Size = new Size(80, 20);
        m_RB_Red.Click += new System.EventHandler(RB_Click);
        m_RB_Red.Click += new System.EventHandler(RB_Click_Mes);

        m_RB_Green = new RadioButton();
        m_RB_Green.Text = "Green";
        m_RB_Green.Checked = true;
        m_RB_Green.Location = new Point(16, 36);
        m_RB_Green.Size = new Size(80, 20);
        m_RB_Green.Click += new System.EventHandler(RB_Click);

        m_RB_Blue = new RadioButton();
        m_RB_Blue.Text = "Blue";
        m_RB_Blue.Checked = false;
        m_RB_Blue.Location = new Point(16, 56);
        m_RB_Blue.Size = new Size(80, 20);
        m_RB_Blue.Click += new System.EventHandler(RB_Click);

        m_B.BackColor = Color.Green;

        m_GB_Color = new GroupBox();
        m_GB_Color.Text = "Choose color";
        m_GB_Color.Location = new Point(18, 100);
        m_GB_Color.Size = new Size(100, 80);
        m_GB_Color.Controls.AddRange(new Control[] {m_RB_Red, m_RB_Green, m_RB_Blue});
        Controls.Add(m_GB_Color);

        m_TT = new ToolTip();
        m_TT.AutomaticDelay = 300;
        m_TT.ShowAlways = true;
        m_TT.SetToolTip(m_B, "pressing the button will display message box");

        m_LB = new ListBox();
        m_LB.Items.Clear();
        m_LB.IntegralHeight = false;
        m_LB.Location = new Point(310, 16);
        m_LB.Size = new Size(160, 90);
        m_LB.Items.AddRange(new object[]{"Red", "Orange", "Yellow", "Green", "Blue", "Indigo", "Violet"});
        m_LB.SelectionMode = SelectionMode.MultiSimple;
        m_LB.SetSelected(1, true);
        m_LB.SelectedIndexChanged += new EventHandler(LB_SelIndChanged);
        Controls.Add(m_LB);

        m_CLB = new CheckedListBox();
        m_CLB.Items.Clear();
        m_CLB.IntegralHeight = false;
        m_CLB.Location = new Point(310, 110);
        m_CLB.Size = new Size(160, 90);
//.........这里部分代码省略.........
开发者ID:alrykov,项目名称:lectures,代码行数:101,代码来源:DialogBasedApp.cs


注:本文中的ListBox.SetSelected方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。