You could use the WinForm Grid control to achieve that, or any 3rd Party Grid or List components.
The WPF ListBox with a data template could also achieve a similar behavior.
You could use the WinForm Grid control to achieve that, or any 3rd Party Grid or List components.
The WPF ListBox with a data template could also achieve a similar behavior.
If this is a web application:
Is this data editable in the page, or is it for display purposes only? If the former, consider making each item a link to an new editor page that would edit one block at a time.
If you are only displaying the data with no edit capability, use a repeater control to output an HTML table. Take a look at
http://quickstarts.asp.net/QuickStartv20/aspnet/doc/ctrlref/data/repeater.aspx
The repeater binds to any datasource - a List<>, Array, DataTable, etc - and iterates through the contents, and displays the data for each row according to the template you specify in the aspx. The
If this is a winForms application
Ask yourself why your application isn't web based. There are (in my very humble opinion) very few apps these days that are better suited to winForms implementation. Graphics editors, compilers, etc are good examples. A reporting engine, however, would most likely be better suited to a web implementation. YMMV.
If you're still set on using WinForms, a better solution may be to use a label or other handle-free control for your text. Link to another form if you need to edit each entry. Any page that has thousands of textboxes will provide limited usability.
You could use a third-party control for this (maybe), but here are some reasons why this is potentially a bad idea:
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:
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. :)
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.
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.
Will the DataRepeater from the Visual Basic PowerPack work for you? It is a download for VS2k5 and installed with VS2k8. If not, check the TemplateListBox at www.codeproject.com/KB/cpp/TemplateListBox.aspx and the ContinousControl at blogs.vbcity.com/hotdog/archive/2006/10/26.aspx.
Without knowing more about the sort of data, I think you want a user control which will be the "repeated" bit. You can use a TableLayout container control (or a FlowLayout perhaps?) and add / remove the items from the table as required.
If your data is tabular, perhaps with a parent / child relationship, I would say you should use a grid control. I don't agree with the statement of another answer here that you should steer clear of third-party controls. They will save you time very quickly - some, like Janus' GridEx control, costs relatively little (a few hundred quid) and will save you hours - which, if you work in a commercial environment, can translate to much more than the cost of the control. Plus they look much better and offer better functionality than the standard WinForms Grid control.
I don't know the nature of the datum you wish to display, but for fast accomplishment, the System.Windows.Forms.DataGridView does the job well and is embedded in .Net Framework 2.0.
If you're used to work with Linq to SQL Classes, if you're using SQL Server as the datastore, just create your DBML diagram and:
This only requires about ten lines of code and a few Windows Forms design-time. I hope I didn't forget anything crucial. :-P
Please let know whether it helps!
You may want to publish an EditingControl property to your object if you wrote it yourself, and create a new instance for each instance of your class retrived from the database.
someObject.GetList().ForEach((so) => {
ConstructorInfo ctor = so.EditingControl.GetType().GetConstructor(new Type[] { });
var editingControl = ctor.Invoke(new object[] { });
editingControl.Name = "someName" + ++counter.ToString();
editingControl.Location = new Point(posX, posY);
editingControl.Width = someWidth;
editingControl.Height = someHeight;
editingControl.DataSource = so;
myForm.Controls.Add(editingControl);
});
Well, I hope you may get the idea. This is not very optimal as a solution, but rather good anyway, in my humble point of view.
Hope this helps!
To me it seems like a great exercise in controls that are self painted. Instead of creating textboxes, override/subscribe to OnPaint event and use Graphics object to DrawString() in appropriate places, DrawRectange() to have rectangles around them. If you know the position for your textboxes, existing code will be fairly easy to convert.
Some advice:
Feel free to comment with further questions...