ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

winform 各种小功能

2022-08-03 09:01:40  阅读:160  来源: 互联网

标签:功能 各种 Items Add 添加 cbox ImageList Find winform


1.  实现待查询功能的combox
 private void Frm_Main_Load(object sender, EventArgs e)
        {
            cbox_Find.Items.Clear();//清空ComboBox集合
            cbox_Find.Items.Add("C#编程词典");//向ComboBox集合添加元素
            cbox_Find.Items.Add("C#编程宝典");//向ComboBox集合添加元素
            cbox_Find.Items.Add("C#视频学");//向ComboBox集合添加元素
            cbox_Find.Items.Add("C#范例宝典");//向ComboBox集合添加元素
            cbox_Find.Items.Add("C#从入门到精通");//向ComboBox集合添加元素
            cbox_Find.Items.Add("C#范例大全");//向ComboBox集合添加元素
        }

        private void btn_Begin_Click(object sender, EventArgs e)
        {
            cbox_Find.AutoCompleteMode = //设置自动完成的模式
                AutoCompleteMode.SuggestAppend;
            cbox_Find.AutoCompleteSource = //设置自动完成字符串的源
                AutoCompleteSource.ListItems;
        }

2  在combox下拉列表中显示图片

        private ImageList G_ImageList;//声明ImageList字段


        private void cbox_DisplayPictures_DrawItem(object sender, DrawItemEventArgs e)
        {
            if (G_ImageList != null)//判断ImageList是否为空
            {
                Graphics g = e.Graphics;//得到绘图对象
                Rectangle r = e.Bounds;//得到绘图范围
                Size imageSize = G_ImageList.ImageSize;//获取图像大小
                if (e.Index >= 0)//判断是否有绘制项
                {
                    Font fn = new Font("宋体", 10, FontStyle.Bold);//创建字体对象
                    string s = cbox_DisplayPictures.Items[e.Index].ToString();//得到绘制项的字符串
                    DrawItemState dis = e.State;
                    if (e.State == (DrawItemState.NoAccelerator | DrawItemState.NoFocusRect))
                    {
                        e.Graphics.FillRectangle(new SolidBrush(Color.LightYellow), r);//画条目背景
                        G_ImageList.Draw(e.Graphics, r.Left, r.Top, e.Index);//绘制图像
                        e.Graphics.DrawString(s, fn, new SolidBrush(Color.Black),//显示字符串
                            r.Left + imageSize.Width, r.Top);
                        e.DrawFocusRectangle();//显示取得焦点时的虚线框
                    }
                    else
                    {
                        e.Graphics.FillRectangle(new SolidBrush(Color.LightGreen), r);//画条目背景
                        G_ImageList.Draw(e.Graphics, r.Left, r.Top, e.Index);//绘制图像
                        e.Graphics.DrawString(s, fn, new SolidBrush(Color.Black),//显示字符串 
                            r.Left + imageSize.Width, r.Top);
                        e.DrawFocusRectangle();//显示取得焦点时的虚线框 
                    }
                }
            }
        }

        private void btn_Begin_Click(object sender, EventArgs e)
        {
            btn_Begin.Enabled = false;//停用开始按钮
            cbox_DisplayPictures.DrawMode = DrawMode.OwnerDrawFixed;//设置绘制元素方式
            cbox_DisplayPictures.DropDownStyle = //设置组合框样式
                ComboBoxStyle.DropDownList;
            cbox_DisplayPictures.Items.Add("小车");//添加项
            cbox_DisplayPictures.Items.Add("卡车");//添加项
            cbox_DisplayPictures.Items.Add("工具");//添加项
            cbox_DisplayPictures.Items.Add("朋友");//添加项
            G_ImageList = new ImageList();//创建ImageList对象
            G_ImageList.Images.Add(global::PicturesInComboBox.Properties.Resources.a);//添加图片
            G_ImageList.Images.Add(global::PicturesInComboBox.Properties.Resources.b);//添加图片
            G_ImageList.Images.Add(global::PicturesInComboBox.Properties.Resources.c);//添加图片
            G_ImageList.Images.Add(global::PicturesInComboBox.Properties.Resources.d);//添加图片
        }

3.实现气泡提示窗口

        private void clewButton_Click(object sender,EventArgs e)
        {
            this.notifyIcon1.Visible = true;//设置提示控件可见
            this.notifyIcon1.ShowBalloonTip(1000,"当前时间:",DateTime.Now.ToLocalTime().ToString(),ToolTipIcon.Info);//显示气泡提示
        }

        private void closeButton_Click(object sender,EventArgs e)
        {
            this.notifyIcon1.Visible = false;//设置提示控件不可见
        }

        private void notifyIcon1_MouseMove(object sender,MouseEventArgs e)
        {
            this.notifyIcon1.ShowBalloonTip(1000, "当前时间:", DateTime.Now.ToLocalTime().ToString(), ToolTipIcon.Info);//显示气泡提示
        }

 

标签:功能,各种,Items,Add,添加,cbox,ImageList,Find,winform
来源: https://www.cnblogs.com/for-easy-fast/p/16545773.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有