需要帮助创建控件来显示数据控件、数据

2023-09-03 01:07:11 作者:终究一场空

我写一个需要显示在一个不错的格式化用户友好的方式结果列表的.NET WinForms应用程序。以下是我希望显示的数据。

I am writing a .NET WinForms application that needs to display a list of results in a nice formatted user-friendly fashion. Here's how I'm hoping to display the data.

该表必须支持数据的像样的数目(> = 200个独立的数据块),并需要相当快的。我不确定要做到这一点最简单的方法,我希望为一些指导和建议。我创建了一个快速原型的自定义控件,仅仅用了一堆文本框堆放在彼此顶部。它的工作还算不错,但Windows上运行了手柄的文本框的速度太快了。我可以创建一个自定义的文本框控件,但它会耗费时间,我想知道是否有其他解决方案的建议?谢谢你。

The table must support a decent amount of data(>= 200 individual "data blocks"), and needs to be fairly fast. I'm unsure of the easiest way to accomplish this and I was hoping for some direction and advice. I created a quick prototype custom control that simply used a bunch a text boxes stacked on top of each other. It worked fairly well but Windows runs out of handles for the textboxes too quickly. I could create a custom textbox control, but it would be time consuming and I was wondering if there are any recommendations for alternative solutions? Thanks.

推荐答案

您可以使用这个(可能)第三方控件,但这里有一些原因,这可能是一个坏主意:

You could use a third-party control for this (maybe), but here are some reasons why this is potentially a bad idea:

第三方控件花钱 第三方控件往往吸 第三方控件需要您分发至少一个额外的DLL,比你通常无法控制 即使第三方控件能够最终做到你需要什么,它会带你一些时间和精力来弄清楚如何使用它,以及如何锤成您所需要的形状

有关任何不寻常的(就像你在做什么),编写自己的用户控件是最好的方式,为这些(及其他)的原因:

For anything out of the ordinary (like what you're doing), writing your own UserControl is the best way to go, for these (among others) reasons:

在编写自己的用户控件是遥遥领先的最开心的事情,你可以在净做 您将不得不学会一些事情要做到这一点很好,但你获得的知识是立即转移到其他问题和项目(而无论你了解如何使用Initrode的无限Wonderfulness Gridifier将只帮助你使用特定的控制) 会有什么额外的分发与应用程序 完全控制源$ C ​​$ C 永远免费(与道歉Evony) 天空才是极限 - 与任何第三方控件,您最终将运行到的东西,它只是不能做,但如果你这样做你自己,你可以从字面上做任何你想要

您特定的问题(你的问题很好的描述,由于图形)是很容易做到的一个主要自绘用户控件(有两个文本框甩在了混合)。你需要从System.Drawing.Graphics对象的唯一方法是DrawRectangle的,FillRectangle,MeasureString和的DrawString。你甚至不会需要任何文档,智能感知会给你你需要的一切。

Your particular problem (well described in your question, thanks to the graphics) is quite easy to do as a mostly owner-drawn UserControl (with a TextBox or two thrown in the mix). The only methods you'll need from the System.Drawing.Graphics object are DrawRectangle, FillRectangle, MeasureString and DrawString. You won't even need any documentation, as Intellisense will give you everything you need.

如果您遇到麻烦,我会写为你的巧克力饼干。 :)

If you run into trouble, I'll write it for you for a chocolate chip cookie. :)

更新:既然你需要的文字都是可选的,这使得这种方法稍微复杂一点。实现自己的文本框类型的功能是在花火一个巨大的痛苦,但相对简单的解决办法是增加一个真正的多线文本框上的任何含文本的矩形的顶部,当用户点击它,并把该矩形的文本(pre-选择)到文本框。当这个临时文本框失去焦点(引发LostFocus),你画编辑的文本转换成矩形,并删除文本框。这样,你只有一个文本框,在你的用户控件的时候。

Update: since you need the text to all be selectable, that makes this approach a bit more complicated. Implementing your own Textbox-type functionality is a gigantic pain in the petard, but a relatively simple solution is to add a real multi-line Textbox over top of any text-containing rectangle when the user clicks on it, and to put the rectangle's text (pre-selected) into the Textbox. When this temporary Textbox loses focus (LostFocus), you draw the edited text into the rectangle and delete the Textbox. This way you only have one Textbox at a time in your UserControl.

这个版本将花费你两块饼干。

This version will cost you two cookies.

更新2 :这是一个简单的应用程序的演示如何使用单一的文本框,使您的整个控制选择和编辑。这里是源$ C ​​$ C 。

Update 2: Here is a simple application that demonstrates how to use a single TextBox to make your entire control selectable and editable. And here is the source code.

 
精彩推荐
图片推荐