Winforms, GDI+ and basic conceptual fightings

This forum is meant for anything you would like to share with other visitors
Post Reply
FFF
Posts: 1601
Joined: Fri Sep 25, 2015 4:52 pm
Location: Germany

Winforms, GDI+ and basic conceptual fightings

Post by FFF »

After years of avoiding this, i finally want to tackle some graphic output. Searching, i found a lamentable loss of docs for anything a bit more complicated than "DrawLine"...
Attached a sample of a booking plan, what should in the end be viewable and printable.
* Textblock, horizontally centered, pegged to the upper border
* Blocks of rows of rectangles, number of rectangles might differ for every row
* Each rectangle has a number inside
* Each row has "outside" a row number, ideally "not rotated"
* Each block has a naming letter, not rotated
* in the end all of them should be placed together and scaled to fit onto a given page format.

Basically my question is, how to dynamically handle multiple placings of somewhat rotated "Building blocks". Naturally, i might accept restrictions, calculating everything "by hand", but there has to be a better way.

I think i meanwhile grasped the concept of transformations more or less, but i struggle how to proceed. Would it get easier using panels?

(Chris, i remember you presented some GDI samples back in VN days, but can't find them anymore, is there a place to get them?)
VVK_VanBeethoven_Plan.pdf
(48.12 KiB) Downloaded 10 times
Regards
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
User avatar
wriedmann
Posts: 3798
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Re: Winforms, GDI+ and basic conceptual fightings

Post by wriedmann »

Hi Karl,
if you like to do that in Windows forms, I would build my own helper class that is built over DrawLine.
After all, what you need is a collection of lines.
Basically your objects are all rectangles with some caracteristics:
- width and length
- rotation
- origin
- available or not (X)
- text
So I would start with this...

Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
FFF
Posts: 1601
Joined: Fri Sep 25, 2015 4:52 pm
Location: Germany

Re: Winforms, GDI+ and basic conceptual fightings

Post by FFF »

Wolfgang,
that's the easy part...
What puzzles me, is the "assembly" of the parts. For placement, i need bounding boxes, for rotation a useful origin for each part, and i still seem to misunderstand the effects of ResetTransform.
Regards
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
User avatar
Chris
Posts: 5044
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Re: Winforms, GDI+ and basic conceptual fightings

Post by Chris »

Hi Karl,

My old session (for vulcan) was included in 2023's session material, in the folder "Old sessions", but I'm attaching it also here:

2005. Programming GDI+ in Vulcan.NET.zip
(385.93 KiB) Downloaded 2 times

Regarding rotation, have a look in the GDI+ demo code, in the method DrawWave(). Basically you need to

- Save current state with Graphics:BeginContainer()
- Move the painting coordinates to the center of the object (collection of lines etc) that you want to draw rotated with TranslateTransform()
- Rotate the painting axis with RotateTransform()
- Do the drawing
- Restore the default drawing state with EndContainer()

This will draw everything rotated, but if you need to do some parts not rotated, then I'm afraid you will need to do some math calculation on where you should draw normally those parts.
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
Post Reply