xsharp.eu • Winforms, GDI+ and basic conceptual fightings
Page 1 of 1

Winforms, GDI+ and basic conceptual fightings

Posted: Wed Jan 15, 2025 8:21 am
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 11 times

Re: Winforms, GDI+ and basic conceptual fightings

Posted: Wed Jan 15, 2025 8:26 am
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

Re: Winforms, GDI+ and basic conceptual fightings

Posted: Wed Jan 15, 2025 10:45 am
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.

Re: Winforms, GDI+ and basic conceptual fightings

Posted: Wed Jan 15, 2025 11:15 am
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 4 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.

Re: Winforms, GDI+ and basic conceptual fightings

Posted: Wed Jan 15, 2025 2:38 pm
by FFF
Thx Chris for the files, will study.

While on it, i get an

Code: Select all

error XS0507: 'DemoPictureBox.OnPaint(System.Windows.Forms.PaintEventArgs)': cannot change access modifiers when overriding 'protected' inherited member 'System.Windows.Forms.PictureBox.OnPaint(System.Windows.Forms.PaintEventArgs)'	135,1	GDI_plus_demo.prg	DemoPictureBox:OnPaint
on this line
METHOD OnPaint(e AS PaintEventArgs) AS VOID CLASS DemoPictureBox

This i also saw recently in another application - i have no clue, what is wrong here.