Scrolling and drawing with GDI+ and Windows Forms

  • Thread starter Thread starter Arun Bhalla
  • Start date Start date
A

Arun Bhalla

I've been dealing with this problem off and on for the past couple weeks,
and I'm stumped.

I have a Panel that I've been using as a desktop for my app, and on this
desktop are many custom controls I've also extended from Panel. I'm trying
to draw arrows between some of the custom controls. That has worked fine
until I had to deal with scrolling. I'd like for the arrows to be drawn
correctly on this virtual desktop, so if a custom control is barely outside
the viewport, the arrow should be pointing in exactly that custom control's
direction. Alas, I have arrows pointing in the wrong direction.

One of the problems is that the Location property doesn't seem to take into
account the virtual location, after scrolling. So, it seems that two
different controls can both be at Location (100, 0), even if they might be
1000 pixels apart in the virtual space. Somehow Windows Forms knows to
display only the controls that belong in that viewport, but I can't figure
out how to extract the virtual coordinates... and using them with DrawLine()
would be even more useful.

PointToScreen() and PointToClient() don't seem to help. AutoScrollPos seems
to be the way to go, maybe, but I haven't been able to do anything useful
with it.

Does anyone have any tips and tricks for working with GDI+ and custom
controls on a scrollable control (Panel)?

Thanks,
Arun
 
It's a legacy issue. :-)

I think in a few months I'll overhaul everything to do just that (and add
custom borders! something Swing has had for years), but for the next few
months we'll be stuck with what we have now. We've been using approximately
10 buttons per panel, and approximately 20 panels on a larger panel. This
worked fine in Java, but it has all become less than stellar in Windows
Forms. Perhaps it's not what Microsoft intended, but some serious
shortcomings in Windows Forms have been exposed in this way.

Arun
 
Two questions:-

1. Have you found .Net Forms to be basically stable? I have got weird
unreproducable bugs in 100% managed code which is worrying. Am I alone?

2. How would you compare Swing to .Net Forms? My feeling is that to do
anything serious in .Net you need to make low level winApi calls.

Anthony
 
I've found some weird bugs, as well, but I'm not sure whose fault it is.
I'm in a particular context -- an Explorer bar / band object using Windows
Forms -- and I've found a couple bugs that can't be replicated elsewhere, as
in normal applications. For instance, I can't use a Toolbar after opening a
CommonDialog (e.g. OpenDialog). The buttons on the Toolbar just stop
working. I've managed to work around in less than ideal ways, though.

While Forms seem to be faster in performance than Swing, Swing seems to be
much more mature. As far as I can tell, Windows Forms is a huge step
forward for GUI programming in Windows... Finally a truly object-oriented
GUI library! But in order to take advantage of anything but the basic
characteristics of controls, controls need to be extended or make Win32 API
calls. There's still way more power in the Win32 API than in Windows Forms.
It's not really clear to me, but it seems like Microsoft intended Windows
Forms for one-off applets/applications and very basic B2B applications. I
can only hope that Windows Forms in .NET 2.0 will be vastly improved. Swing
was rather nice in that pretty much anything could be a component of pretty
much anything else. There was a lot of sense to it. The Sun developers
must have read Design Patterns.

Arun
 
Back
Top