Getting VScrollBar properties from within an OnPaint method

D

Daisy

I've got a custom control that works fine, it's DockStyle is set to Fill for
the panel it's in.

I've just added a VScrollBar docked Right in the panel. It appears, and
works fine, however in the OnPaint method of my custom control, I need to
know where the scrollbar is, so I can paint the relevant part of my control.

Since the ScrollBar exists in my MainForm, and the customcontrol is a class
of it's own, I can't figure out how to get at it. I was looking at the
Container property on each control, trying to get back to the MainForm,
which I could then get at it from, but apart from not working, that also
only seems to work if you know the index for the control in it's container,
and not if you know the name.

How should I achieve this?
 
N

Nicholas Paldino [.NET/C# MVP]

Daisy,

This design is flawed. If you want your control to know where the
scrollbar is, then the form should pass the scrollbar to the control in some
manner so that it can do what it needs to do with it. Either that, or the
control itself should be responsible for displaying the scrollbars, so that
it would know where they are.

Hope this helps.
 
D

Daisy

This design is flawed. If you want your control to know where the
scrollbar is, then the form should pass the scrollbar to the control in some
manner so that it can do what it needs to do with it. Either that, or the
control itself should be responsible for displaying the scrollbars, so that
it would know where they are.

I thought so!

I'll try attaching scrollbars inside my control. It's DockStyle is set to
Fill, I assume I can just dock scrollbars to the right/bottom from inside my
control?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top