有两个独立列的组合框的任何方式? [英] Any way for a combo box with two separate columns?

查看:63
本文介绍了有两个独立列的组合框的任何方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个选项,我可以用并行方式查看组合框中的大量选项!抱歉我的英文不好,但我用照相馆解释我的想法。



http://i.stack.imgur.com/214Q0.png



再次上面的图片是由photoshop完成的,不是用vb :)



我用这个代码两个显示项目组合框和集中标题项目





I'm looking for an option with which I can view large amount of options in combobox in parallel way !!! sorry for my bad english , but i use photo shop to explain my idea .

http://i.stack.imgur.com/214Q0.png

again the above pic was done by photoshop not with vb :)

I use this code two display items in combobox and centralize header items


Private Sub ComboBox3_DrawItem(sender As Object, e As DrawItemEventArgs) Handles ComboBox3.DrawItem

    If Not e.Index < 0 Then

        e.DrawBackground()
        Dim text As String = CType(sender, ComboBox).Items(e.Index).ToString()

        If text.StartsWith("=") Then

            Dim f As New Font(CType(sender, ComboBox).Font, FontStyle.Bold)
            TextRenderer.DrawText(e.Graphics, text, e.Font, e.Bounds, Color.Maroon)

        Else

            Dim f As New Font(CType(sender, ComboBox).Font, FontStyle.Regular)
            TextRenderer.DrawText(e.Graphics, text, e.Font, New Point(e.Bounds.X, e.Bounds.Y), Color.Black)

        End If

    End If

End Sub





上面的代码工作正常,但我无法在多列中绘制项目。



所以,任何帮助????在此先感谢:)



再次抱歉我的英语不好

推荐答案

为什么使用组合框?一个众所周知的多列控件是 System.Windows.Forms.ListView

http://msdn.microsoft.com/en-us/library/system.windows.forms。 listview%28v = vs.110%29.aspx [ ^ ]。



还有其他一些可能性。您可以使用两个与事件绑定的组合框并进行相应的排列,您可以创建一个自定义控件,这实际上并不太难。

例如,请参阅此CodeProject文章:多列组合框 [ ^ ]。







Why using a combo box? A well-known multi-column control is System.Windows.Forms.ListView:
http://msdn.microsoft.com/en-us/library/system.windows.forms.listview%28v=vs.110%29.aspx[^].

There are some other possibilities. You can use two combo boxes bound with events and arranged appropriately, you can create a custom control, which would not really be too hard to make.
See, for example, this CodeProject article: Multi-Column ComboBox[^].



dr_aliragab问:
dr_aliragab asked:

...任何提示创建自定义控件?

…any hint to create a custom control?

我是我还没有确信这是必要的,因为我们没有深入讨论你所需的功能,但我们假设你需要它。



首先,你应该创建一个数据结构保存此控件中的数据,即其数据模型。首先,你需要引入选择的概念,它总是内在的控制。



现在,要渲染图形,定义列,它们的标题,项目的位置,取决于控件大小,您需要覆盖虚拟方法 System.Windows.Forms.Control.OnPaint 。我的意思是:如果你想让控件的用户处理这个事件的可能性,不仅仅是处理 Paint 事件。在这种情况下,当您调用 base.OnPaint 时将调用该事件。

事件参数参数将为您提供 ClipRectangle (这样您就可以了解渲染时的控件大小,只知道其客户端部分)和您将使用类 System.Drawing.Graphics 的实例绘制控件上的所有内容。



请请参阅:

http://msdn.microsoft.com/en-us/library/system.windows.forms.control.onpaint(v = vs.110).aspx [ ^ ],

http: //msdn.microsoft.com/en-us/library/system.windows.forms.control.paint(v=vs.110).aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/system.windows.forms.painteventargs%28v=vs.110%29.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/system.drawing.graphics(v = vs.110).aspx [ ^ ]。



现在,如果您只需要一个滚动条(两列的常见滚动),您可以通过从 System.Windows.Forms.ScrollableControl <派生控件来简单地使用默认滚动/ code>:

http://msdn.microsoft.com/en-us/library/system.windows.forms.scrollablecontrol%28v=vs.110%29.aspx [ ^ ]。



在其他更复杂的情况下,您需要明确添加滚动条作为控件的子项:http://msdn.microsoft.com/en-us/ library / system.windows.forms.scrollbar%28v = vs.110%29.aspx [ ^ ]。



顶部其中,要定义所有功能,您需要处理鼠标和键盘事件,几乎所有这些事件或大多数事件。您将需要使用此处理操作选择(首先),滚动,导航和编辑项目,如果需要和允许。



请记住几乎所有通过用户输入执行的操作应该通过编程操作的方法加倍,例如选择,依此类推。



在所有这些处理程序方法中,每次更改数据模型时都需要使视图无效,这需要更改视图。这是通过 Control.Invalidate 方法完成的:

http://msdn.microsoft.com/en-us/library/system.windows.forms.control.invalidate%28v = vs.110%29.aspx [ ^ ]。



这就是一般特征中的所有内容。 />


-SA

I'm not still convinced that this is necessary as we did not discuss your required features in depth, but let's assume you need it.

First, you should create a data structure to hold data in this control, its data model. First of all, you need to introduce the concept of "selection", which is always inner to the control.

Now, to render graphics, define the columns, their headers, location of items, depending on control size, you need to override the virtual method System.Windows.Forms.Control.OnPaint. I mean it: not just handling the Paint event, if you want to leave the possibility to handle this event by the control's user. In this case, the event will be invoked when you call base.OnPaint. The
event arguments parameter will give you ClipRectangle (this way you know the control size at the moment of rendering, and only its client part) and the instance of the class System.Drawing.Graphics you will use to draw everything on the control.

Please see:
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.onpaint(v=vs.110).aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.paint(v=vs.110).aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.painteventargs%28v=vs.110%29.aspx[^],
http://msdn.microsoft.com/en-us/library/system.drawing.graphics(v=vs.110).aspx[^].

Now, if you need only one scroll bar (common scrolling for both columns) you can simply use default scrolling by deriving your control from System.Windows.Forms.ScrollableControl:
http://msdn.microsoft.com/en-us/library/system.windows.forms.scrollablecontrol%28v=vs.110%29.aspx[^].

In other, more complex cases, you would need to add scroll bars explicitly as children of your control: http://msdn.microsoft.com/en-us/library/system.windows.forms.scrollbar%28v=vs.110%29.aspx[^].

On top of that, to define all the functionality, you would need to handle mouse and keyboard events, pretty much all of them, or most. You will need to use this handling to operate selection (first of all), scroll, navigate and edit item if needed and allowed.

Keep in mind that nearly all the operations performed via user input should be doubled by the method for programmatic manipulations, such as Select, and so on.

From within all these handler methods, you need to invalidate the view each time you change you data model the way it requires the change of view. This is done via the Control.Invalidate methods:
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.invalidate%28v=vs.110%29.aspx[^].

That's all, in the very general features.

—SA


我认为组合框感谢不可能
i think not possible wth the combo box thankuu


我认为转移到WPF是个好主意。你可以将任何控制操作到你想要的程度。



自从我转移到WPF后,一切都很简单。
I think it is a good idea to shift to WPF. You will be able to manipulate any control to the level of of your desire.

Ever since I have shifted to WPF, everything is simple.


这篇关于有两个独立列的组合框的任何方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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