How do I write a form editor?

I am trying to write a print layout editor in VB6 or VB.Net and I am looking for some help articles to help me get started.

The idea is that the editor will be used to define printable "areas" for invoice or operator calculations, allowing the user to draw a field for customer address, invoice number, lines, totals, etc. The program will then figure out how to translate the sizes and positions of the various boxes into print locations for storage in a layout definition file that is later used by the account system to print various reports. Please note that for various reasons (mainly because the account system is not Windows) placing text in Word or similar products and printing them is not an option. Of course I can edit the document layout file manually, but it is not very user friendly.

As you can imagine, search for "form editor", "layout editor", etc. brings many hundreds of irrelevant results. The depressing thing is that I saw a very relevant article but lost the bookmark.

I hope someone has some pointers.


Thanks, this sounds more complicated than I imagined. I am very sorry that I cannot find the original article that I lost as it was pretty clear how to do it in vb.net.

Since this is a layout for a printable I find it quite difficult to reduce the complexity - I really need to store the size and position of each printable area, as well as font, alignment, and color information, and possibly a filename for the graphic if a logo is required. The layout of the layout definition file is completely under my control.

0


source to share


2 answers


First of all, you must know the language / API you are using well and in fact you really need to tell if you are using Windows.Forms, WPF, GTK #, etc. Make sure you are very good.

Then you have to come up with a format for the form editor to store the forms. Typically form editors use XML. If you also want to follow this trend, you REALLY should learn a good XML interface for VB.

Finally, plan your steps carefully:



  • Do you want to use the custom textbox controls provided by your API, or do you want to draw them manually (if so, you need to learn the drawing API)?
  • Make sure you are familiar with the layout definition file format.

Now it's time to start the proof of concept: create a simple editor that can load / save forms and add buttons to them. This will probably be the hardest step. You may have to deal with events and a few other things, but in the end it will work (if not, then you can ask again). Finally, just add the functionality you want such as outputting the layout definition file, new controls, move / resize controls, etc.

If you need anything else (including more specific instructions), just ask.

+1


source


I remember how I developed this particular kind of printout form editor in vb6, about 10 years ago iirc. not sure if I can still find sources sadly: indeed, I found this question because I need to write another one, and I was hoping to find some code to get started rather than doing it from scratch again. anyway, the way I did it, more or less, was as follows:

  • One custom control for the page background, displaying a light grid and responding to mouse events (for example, displaying a menu on right-clicking);
  • each field was a self-contained custom element without a window, also displaying a light grid, one cell for each (fixed width) char. it also reacted to mouse events so that it could be moved and changed; when I say windowless, I mean "not having hwnd", a kind of optimization that allowed multiple reference instances to be hosted without worrying about impacting resources; if you are going to use .net you don't care, but if you are using vb6 it matters:
  • one property grid like vb6 showing the properties of the selected field (s). in my case, I could set the text style (condensed, expanded, bold) and the expression used at runtime to extract the value to print;
  • Loading the layout file will resize the page and create a margin control for each field in the file;
  • saving wrote out the page properties (size, name, etc.), then enumerated the collection of fields and wrote out their properties;
  • I didn't use xml because the file format was already fixed since it was used by the engine that did the actual printing; xml will make my life easier, no need to write your own parser for the data file format.
  • It only needed to handle dot matrix printers, but luckily I didn't cut any corners and I could easily adapt it to handle more accurate field placement and sizes as well. i mean just, i resisted the temptation to use row and column coordinates and used twips instead; he thought a little about math, but definitely didn't know about rocket.


Overall, it was not that difficult, and it turned out to be very nice, it was a bit like a "crystal report" form editor.
I remember taking a while to get the data correct, eg. snapping the grid at different character widths, resizing margins when changing text styles like shrunk or widened without jumping around due to rounding errors, things like that. don't let that scare you, keep in mind that you don't have to take care of everything from the beginning, just be careful not to block the opportunity to do it later.

currently I would not recommend vb6 much unless what you know best and do not need to create an .exe that does not depend on the .NET Framework installed on the target machines.
if you decide to go with .net instead, i think it would be nice to learn wpf if you don't know it already, it makes some impressive graphics even more than windows.forms.

0


source







All Articles