组合框文本和图像? [英] Combobox Text and Images ?

查看:81
本文介绍了组合框文本和图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经搜索了几天,以将图像和文本正确地添加到组合框.目前,我尝试使用的代码仅显示图像,而没有告诉我在程序加载时列出的逻辑驱动器.为什么会这样?

这是我截至目前使用的代码

I have been searching for days now to properly add Images and text to a combobox. Currently the code I am trying to use only displays the image without the logical drives that I have told it to list at program load. Why is this happening?

here is the code Im using as of right now

Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ComboBox1.Items.Add(System.IO.Directory.GetLogicalDrives)
        Dim items(Me.ImageList1.Images.Count - 1) As String
        For i As Int32 = 0 To Me.ImageList1.Images.Count - 1
            items(i) = "Item " & i.ToString
        Next
        Me.ComboBox1.Items.AddRange(items)
        Me.ComboBox1.DropDownStyle = ComboBoxStyle.DropDownList
        Me.ComboBox1.DrawMode = DrawMode.OwnerDrawVariable
        Me.ComboBox1.ItemHeight = Me.ImageList1.ImageSize.Height
    End Sub
    Private Sub ComboBox1_DrawItem(ByVal sender As Object, ByVal e As System.Windows.Forms.DrawItemEventArgs) Handles ComboBox1.DrawItem
        If e.Index <> -1 Then
e.Graphics.DrawImage(Me.ImageList1.Images(e.Index) _
,e.Bounds.Left, e.Bounds.Top)
        End If
    End Sub
    Private Sub ComboBox1_MeasureItem(ByVal sender As Object, ByVal e As System.Windows.Forms.MeasureItemEventArgs) Handles ComboBox1.MeasureItem
        e.ItemHeight = Me.ImageList1.ImageSize.Height
        e.ItemWidth = Me.ImageList1.ImageSize.Width
    End Sub
End Class



请帮助我了解我所缺少的内容.

非常感谢您的帮助.



Please help me in knowing what Im missing.

Thank you very much for your help.

推荐答案

您好,

当前的组合框控件无法沿数据显示图标.您需要编写自己的组合框控件,使其能够在其中显示图标.
下面是一个示例:
图像组合框控件 [
Hello,

Showing icon along data is not possible with the current combo box control. You need to write your own combo box control capable of showing icons in it.
Below is an example:
Image ComboBox Control[^]

Hope this answers your question


如果您对System.Windows.Forms的了解已经到头了,那就太麻烦了. :-)
您应该在内容模型(
http://msdn.microsoft.com/en-us/library/bb613548.aspx [ ^ ])是如此自由,以至于这种事情不自然.
当切换到WPF可以让您非常常规地使用该功能时,为什么要扩大Forms的限制并几乎滥用它呢?

那呢?

—SA
If you have gone so far with System.Windows.Forms, you gone too far. :-)
You should switch to WPF where the content model (http://msdn.microsoft.com/en-us/library/bb613548.aspx[^]) is so liberal that such things are more than natural.
Why pushing the limits of Forms and almost abusing it, when a switch to WPF will give you a very regular use of the feature?

How about that?

—SA


这篇关于组合框文本和图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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