单个EventArgs用于多个ComboBox [英] Single EventArgs for multiple ComboBoxes

查看:83
本文介绍了单个EventArgs用于多个ComboBox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我创建了一个ComboBox,其DrawMode为OwnerDrawVariable。有2个事件处理程序

Hi,
I have created a ComboBox with DrawMode as OwnerDrawVariable. There are 2 event handlers

this.comboBox3.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.AllcomboBox_DrawItem);
           this.comboBox3.MeasureItem += new System.Windows.Forms.MeasureItemEventHandler(this.AllcomboBox_MeasureItem);







以下是






Those are the following

private void AllcomboBox_MeasureItem(object sender, System.Windows.Forms.MeasureItemEventArgs e)
        {
            ComboBox cBox = (ComboBox)sender;
           //My code...
        }
private void AllcomboBox_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
        {
            ComboBox cBox = (ComboBox)sender;
           //My code...

        }





这个ComBoBox工作得很好。当我有另一个ComBoBox时,我添加了一个新的事件参数,如何为我表格中的所有组合框制作一个常见的 EventArgs



请帮助



It worked fine for this ComBoBox. When i have another ComBoBox, i added a new event args for that, How can i make a common EventArgs for all the comboboxes in my form.

Please help

推荐答案

访问这里...





如何在C#中编写多个组合框的单个事件 [ ^ ]
visit here...


How To Write Single Event For Multiple ComboBoxes In C#[^]






请检查一下。



粗线更改的代码行。



Hi,

Please check this.

Bolded the changed code lines.

private void AllcomboBox_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
        {
            ComboBox cBox = (ComboBox)sender;
            DataRowView drv = (DataRowView)cBox.Items[e.Index];
            string name = drv[0].ToString();
            Font myFont = new System.Drawing.Font("Comic Sans", 11);
            e.DrawBackground();
            e.DrawFocusRectangle();
            using (Brush textBrush = new SolidBrush(e.ForeColor))
            {
                Rectangle bounds = e.Bounds;
                using (StringFormat format = new StringFormat())
                {
                    format.LineAlignment = StringAlignment.Center;
                    format.Alignment = StringAlignment.Near;
                    e.Graphics.DrawString(name, cBox.Font, textBrush, bounds, format);
                }
            }
 
        }


这篇关于单个EventArgs用于多个ComboBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆