views:

132

answers:

4

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

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.

A: 

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.

iandisme
+2  A: 

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.

Cyril Gupta
This sounds very interesting. How did you handle images? Save them to the temp directory and point the <img> tags there? Or is there a more elegant way?
Dave
I did put them in a specific folder in the app. I think that's a perfectly elegant approach to that.
Cyril Gupta
Although I didn't end up ultimately going the web-browser route, this is a fascinating idea I had never thought of and I appreciate the idea. This may come in quite handy on another project!
Dave
+4  A: 

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.

Chris Porter
For a smaller data set, this might work quite well. But I'd run out of window handles long before I got close to loading the FlowLayoutPanels. Thousands of words times several user controls per word = too much. Maybe a "virtual" version of this, keeping track of the scroll position...
Dave
I missed the "thousands of words" part of the original question. I will update my answer with another possible solution.
Chris Porter
A virtual version of the nested custom controls with FlowLayoutPanel is going to work.
Dave
The virtual approach sounds like an interesting twist. I'd love to see how the result turns out.
Chris Porter
A: 

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

Coder 42