复杂的 .Net 2.0 Windows 窗体控件:从哪里开始?

发布于 2024-08-13 07:02:34 字数 1166 浏览 7 评论 0原文

为了为我正在开发的 .Net 2.0 Winforms 应用程序创建一个方便的 UI,我需要一个控件,我确信它超出了任何标准控件的“开箱即用”行为。我想要实现的目标的模型如下:

模拟 http:// www.claware.com/images/temp/mockup.png

本质上,应用程序的这一部分尝试将部落语言中的单词解析为音节(没有可参考的字典;任何和所有 unicode 字符都是可能的。)当用户走到这一步时,他已经用他的语言和一些其他配置定义了元音/辅音。然后是一个迭代过程:(1) 应用程序根据某些规则猜测语言中存在哪些音节,(2) 用户完善猜测,选择正确的解析或手动解析单词,(3) 应用程序“学习”根据用户的反馈并做出更明智的猜测,(4) 重复,直到数据“足够好”可以继续。

该控件需要呈现每个单词(灰色标题),然后是所有音节中断猜测(带有点分隔单词部分的白色区域。)还有一种手动输入解析的方法,它将显示文本区域和保存按钮(位于模型的底部)。当用户将鼠标悬停在猜测上时,背景会发生变化并出现“接受/拒绝”按钮。单击“接受”或输入手动解析,将从列表中删除整个单词。单击拒绝按钮只会删除该项目。

我绝不是 100% 相信上面的格式,但我认为您可以大致了解我需要的格式类型和功能控制。该控件还将垂直滚动——最初可能有数千个单词。

我向经验丰富的 WinForms 开发人员提出的问题是:从哪里开始?我真的非常非常希望留在 .Net 核心框架内并扩展现有控件,而不是第三方控件。 (冒着发起宗教战争的风险:是的,我患有 NIH 综合症,但这是一个基于许多快速修复解决方案的有意识的决定,但第三方控制的长期问题。)我在哪里可以获得最多的东西“物有所值”并且最少重新发明轮子?列表视图?列表框?可滚动控件?我是否需要一直返回到“控制”并手动绘制所有内容?我感谢您提供的任何帮助!

[编辑]感谢大家的想法。对于我的目的来说,最优雅的解决方案似乎是创建一个由 FlowLayoutPanel 和 VScrollBar 组成的自定义控件。 FlowLayoutPanel 可以包含用于每个单词的自定义控件的实例。但 FlowLayoutPanel 是虚拟的,即它只包含那些可见的实例(以及一些“刚刚超出滚动范围”)。 VScrollBar 事件确定需要加载的内容。需要编写一些代码,但还不错,而且似乎运行良好。

In order to make a convenient UI for an .Net 2.0 Winforms application I am working on, I have need for a control that I'm pretty sure goes beyond the "out of the box" behavior of any standard control. A mock-up of what I'm trying to achieve follows:

Mock up http://www.claware.com/images/temp/mockup.png

Essentially, this part of the application attempts to parse words into syllables from tribal languages (no dictionary to refer to; any and all unicode characters are possible.) By the time the user gets this far, he has already defined the vowels / consonants in his language and some other configuration. There is then an iterative process of (1) the application guesses which syllables exist in the language based on some rules, (2) the user refines the guesses, selecting the correct parsings or manually parsing a word, (3) the application "learns" from the user's feedback and makes smarter guesses, (4) repeat until the data is "good enough" to move on.

The control needs to present each word (the grey headers), then all the syllable break guesses (the white areas with dots separating the parts of words.) There is also a way to manually enter a parsing, which will display a text area and save button (at the bottom of the mockup.) When the user hovers over a guess, the background changes and "accept / reject" buttons appear. Clicking on the accept, or entering a manual parsing, removes the entire word from the list. Clicking the reject button removes just that item.

I'm by no means 100% sold on the formatting I have above, but I think you can get a general idea of the types of formatting and functional control I need. The control will also scroll vertically--there may be thousands of words initially.

My question for you experienced WinForms developers is: where to start? I would really, really like to stay within the .Net core framework and extend an existing control as opposed to a third-party control. (At the risk of starting a religious war: yes, I suffer from NIH-syndrome, but it's a conscious decision based on a lot of quick-fix solutions but long-term problems with 3rd party controls.) Where can I get the most "bang for my bucK" and the least reinventing the wheel? ListView? ListBox? ScrollableControl? Do I need to go all the way back to Control and paint everything manually? I appreciate any help that could be provided!

[Edit] Thanks everyone for the ideas. It seems like the most elegant solution for my purposes is to create a custom control consisting of a FlowLayoutPanel and a VScrollBar. The FlowLayoutPanel can contain instances of the custom controls used for each word. But the FlowLayoutPanel is virtual, i.e. it only contains those instances which are visible (and some "just out of scroll"). The VScrollBar events determine what needs to be loaded. A bit of code to write, but isn't too bad and seems to work well.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

战皆罪 2024-08-20 07:02:34

我会查看 TableLayoutPanel 和 FlowLayoutPanel 控件。这些将使您能够以垂直方式轻松地组织一系列控件。然后我将创建一个由一个标签和 2 个按钮组成的 UserControl。 UserControl 将公开诸如文本之类的属性以及为单击按钮而公开的事件。对于列表中的每个条目,您将创建 UserControl 的一个实例,分配文本值并处理单击事件。该实例将以正确的顺序放置在“表/流程”面板中。这两个布局面板都允许在其他项目之间插入项目,以便您可以动态地从列表中添加/删除项目。

编辑:
考虑到您尝试渲染的内容的长度,我会考虑使用 DataGridView 并进行一些自定义渲染,以使其按照您希望的方式工作。使用 DGV 的渲染事件,您可以合并列、更改背景颜色(例如突出显示深灰色线条)、打开/关闭按钮以及将网格更改为行的编辑模式,以允许修改或插入新值。此方法可以轻松处理大型数据集,并且您可以非常轻松地直接绑定到它们。

I would look at the TableLayoutPanel and FlowLayoutPanel controls. These will let you organize a series of controls with moderate ease in a vertical fashion. I would then create a UserControl that consists of a label and 2 buttons. The UserControl will expose properties like Text and events that are exposed for the button clicks.. For each entry in the list, you will create an instance of the UserControl, assign the text value, and handle the click events. The instance will be placed in the Table/Flow panel in the correct order. Both of those layout panels do allow for inserting items between other items so you can add/remove items from the list dynamically.

Edit:
Given the length of what you are trying to render, I would consider using the DataGridView and do some custom rendering to make it perform how you want it to work. Using the rendering events of the DGV you can merge columns, change background colors (like highlighting the dark gray lines), turn on/off the buttons, and handle changing the grid into edit mode for your rows to allow modification or inserting of new values. This method would easily handle large datasets and you could bind directly to them very easily.

醉酒的小男人 2024-08-20 07:02:34

好吧,这看起来确实像是您应该自己创建的自定义组件的候选者。您可以使用标准 .Net 绘图命令以及文本框和常规按钮控件来创建它。

现在您想知道从哪里开始。

创建 Windows 窗体控件库项目。
放入文本框和按钮控件。

面板绘制代码最好是通过代码来完成。这可以使用常规 GDI+ 命令来完成。

编辑:

这是另一个想法,我已经在自己的项目中实际使用并取得了巨大成功。

您可以在应用程序中使用网络浏览器控件,并将数据显示为 html。您可以根据文本框中的输入更新 Web 浏览器控件的源代码,然后单击 Web 浏览器控件中的链接将为您提供可以捕获以执行某些操作的事件。你的 CSS 会起作用。

我使用这种技术在我制作的名为“正确会计软件”的应用程序中构建了“桌面”。人们非常喜欢桌面,它是该应用程序中最受欢迎的功能之一。

Well, this certainly looks like a candidate for a custom component that you should be creating yourself. You can create this using standard .Net drawing commands along with a text-box, and a regular button control.

Now you want to find out where to start.

Create a Windows Forms Control Library project.
Drop in the textbox and the button control.

The panel drawing code should preferably be done by code. This can be done using the regular GDI+ commands.

Edit:

Here's another idea, and one that I've practically used in my own project with great success.

You could use a web-browser control in the app, and show your data as html. You could update the source of the web-browser control based on the input in the textbox, and clicking on the links in the web browser control will give you the event that you can trap to do some action. Your CSS will work.

I used this technique to build the 'desktop' in an app I made called 'Correct Accounting Software'. People loved the desktop so much that it is one of the best loved features of the app.

无语# 2024-08-20 07:02:34

我将这样做:

创建一个自定义控件。在此自定义控件中,在 LinkBut​​ton 顶部有一个 ListBox,单击 LinkBut​​ton 时可以将其让位于 TextBox。列表框的顶行将不可选择...您可能可以从那里获取其余的内容。当您获得单词列表时,为每个单词填充一个可滚动的控件:

(foreach String word in words){
   myScrollable.add(new MyComponent(word));
}

从那里,我不确定您想对框或数据做什么,但这是我对 UI 设置的最初想法。

Here's how I would do it:

Create a custom control. In this custom control, have a ListBox atop a LinkButton, and when the LinkButton is clicked you can make it give way to a TextBox. The ListBoxes will have the top row unselectable... you can probably get the rest from there. When you get your list of words, fill a Scrollable of some kind with one control for each word:

(foreach String word in words){
   myScrollable.add(new MyComponent(word));
}

From there, I'm not sure what you want to do with the boxes or the data, but that's my initial idea on the UI setup.

妥活 2024-08-20 07:02:34

使用 WebBrowser 控件并使用 DocumentStream 或 DocumentText 在其中生成 HTML 标记。

Use the WebBrowser control and generate the HTML markup into it using DocumentStream or DocumentText.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文