首页->文章内容
如何给commbox控件赋值
[编辑:pinglan] [点击:1750] [回应:0] [上传时间:2018-9-28 17:23:10]

如何给commbox控件赋值

---C# ComboBox赋值时的问题

 //InitializeComponent();

            this.comboBox2.Items.Add("sdd");//赋值

            this.comboBox2.SelectedIndex = 0;//设置下标

 

            this.comboBox2.Items.Add("hsdhd");//赋值

            this.comboBox2.SelectedIndex = 1;//下标

 

            this.comboBox2.SelectedIndex = 1;//默认显示hsdhd

 

combobox显示值的问题不是一个事件而是在窗体加载时显示,所以不应该写在事件里。

 

+++56sbldq180925 1

 

设计思路是:当按下鼠标左键,自动触发已设置好的点击事件。

c#点击鼠标左右键,触发事件》

--- c#定义鼠标左右键事件

这个是点击button按钮的事件

form_load

button1.MouseDown += new MouseEventHandler(button1_MouseDown);

然后写事件处理函数:

void button1_MouseDown(object sender, MouseEventArgs e)

{

if (e.Button == MouseButtons.Right)

{

MessageBox.Show("right");//执行赋值

}

if(e.Button==MouseButtons.Left)

{

//do left-click thing!

}

}

有没有点击空处的事件,即,只需获取现在的鼠标坐标后,就执行

--- C#捕捉Ctrl + 鼠标左键

MouseClick 事件

// Ctrl+鼠标左键

if (e.Button == MouseButtons.Left && Control.ModifierKeys == Keys.Control)

{

}

那么下个问题就是搜下:MouseClick 事件

C#中,MouseDown事件与MouseClick事件有什么区别没?

MouseDown事件当鼠标按下去时就触发,MouseClick事件只有当鼠标按下又松起的时候才会触发。

上面的只是能显示设定窗口内的坐标,实际上,我们想得到的是整个屏幕任意位置的坐标。

--- C#获取全屏鼠标坐标

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Drawing;

using System.Threading;

namespace ConsoleApplication1

{

  class Program

  {

    static void Main(string[] args)

    {

      ///获取桌面大小

      //Rectangle rect = System.Windows.Forms.SystemInformation.VirtualScreen;

      //int width = rect.Width;

      //int height = rect.Height;

      ///循环取点

      while (true) {

        Point p = System.Windows.Forms.Cursor.Position;

        Console.WriteLine(p.X + ":" + p.Y);

        Thread.Sleep(100);

        Console.Clear();

      }

    }

  }

}

这样,也是只能点击窗口内的坐标。




乐 排 行 板 . 版 权 所 有

京ICP备12001047号-3