Copy Portion of Control Graphics into Another Graphics Object

I’m trying to create a custom scrollbar canvas to overlay over a listbox so only the thumb of the scrollbar is visible and the background is the current listbox background including the selected row but I can’t work out how to copy a portion of the listbox into the scrollbar canvas graphics object.

I tried placing “listbox.drawinto(g,0,0)” in the scrollbar canvas paint event but it just appears white every time.

This happens if the scrollbar canvas is either beside the right hand edge of the listbox or over it.

Any ideas?


This will not get your question answered more quickly, perhaps exactly the opposite. If someone on this forum had

  • read you question
  • understood your question in the context you meant
  • and had a proposed solution
    they would have already posted it

the fact that you have not recieved an answer (in oh gee, less than 24 hours) means

  • nobody yet read it (doubtful as this is an active forum)
  • nobody understood your question (most likely… as I have no clue what you’re attempting
  • nobody has a solution (hard to tell now isn’t)

So, perhaps,

  • restate you problem in more than a sentence
  • provide code showing what you are attempting (even a small sample project in zip file)
  • take some screen shots and describe what you expect to see, compared to what is seen
  • but don’t “bump”, its rude, disrespectful of the forum and its members, and may get you added to the personal blacklist of some

I scratched my head over the question but have to confess I did not understand even what that was all about, what was white, where, how, and why.

Hi Dave. Thanks for the post. I really think it’s quite a harsh reply to say that “bump” is rude. That was clearly never my intention and I have posted a lot here in the past and I am always polite and patient.

I only “bumped” because the past 24 hours has been very active on the forum and I felt my post had been lost in the forest.

Blacklist…really? Well, if that’s true then lesson learned. I will NEVER bump again. :slight_smile:

Anyway, I will try and post some pictures to explain the issue and also try to clarify a little more.

Instead of bumping, post more information, talk about what you tried, ask related questions. It will engage people who can help to participate to the conversation.

Denise… remember, this is a volunteer forum. And YES , bumping is VERY rude, it indicates that you believe your problem is more important than anyone elses, and indicates a level of entitlement that is (my opinion) not appropriate. Patience has its rewards.

Blacklist… yeah really… I know for a fact that various members here (myself included) won’t even bother to respond to certain unnamed people, due to their attiude and sense of entitlement. Because this is all volunteer (well I think Norman was conscripted), we are not obligated to respond to any topics, except those we wish to.

So the clearer you can state your problem, the more information you can provide, as well as indicating that you have at least attempted to determine a solution on your own will gain you much more favor.

In my response, I detailed why you may not have (and still have not) gotten anyone to point you in another direction


Yes, thanks, I understand. It’s just the first time anyone has ever slapped my wrist on any forum!

LOL… then obviously you have never been on the STACKOVERFLOW forum! :smiley:
there they’d rather slap you then attempt to answer a legit question.

Lol! Duly noted :slight_smile:

Ok. So in trying to create some pics to explain the problem but in so doing have actually managed to solve most of the original issue.

To recap: I am trying to make a custom scrollbar canvas and link it to a listbox. I placed the custom scrollbar canvas over the right edge of the listbox and made sure the scrollbar canvas was orderd at the front and that the listbox was ordered behind it.

I only wanted to be able to see the thumb image of the scrollbar with the listbox color behind it and now that actually works. The problem it seems was that I had doublebuffer = true in the customscrollbar canvas.

If I turn that off and draw directly to the graphics object in the cusomter scrollbar canvas paint event (and use a mask for the thumb image) the thumb image is displayed correctly and the listbox is seen behind it.

The only problem now is that you get a flicker (on Windows at least) because the double buffering has been disabled.

I’ve tried to manually double buffer the thumb image by creating a new pic the size of the entire scrollbar canvas and then drawing the thumb image to it and then drawing the parent pic to the graphics object but it still doesn’t reduce the flicker.

[code] Paint()

  Dim pic As New Picture(g.width,g.height,screen(0).depth)
  Dim p as new picture (thumbPic.Width, thumbPic.height, screen(0).depth)
  p.Graphics.DrawPicture thumbPic, 0, 0
  p.mask = thumbPicMask p, 0, 0 + scrollOffset
  pic.Transparent = 1
  g.drawpicture pic, 0, 0[/code]

The thumb always flickers on drag but the background is okay.

[quote=260124:@Denise Adams]Ok. So in trying to create some pics to explain the problem but in so doing have actually managed to solve most of the original issue.[quote]
See? :slight_smile:

So if I understand correctly, your custom canvas OVERLAPS the listbox? if so, that is probably the root of your problem, doublebuffered or not (I assume this is WINDOWS and not OSX?)… just for the heck of it is GDI+ turned on?,

If you insist on replacing the OS created scrollbar with something of your own, you might try to disable the scrollbars in the listbox completely, and put your scrollbar butted up to the edge (not overlapping), but then you have to send events to the listbox to get it to actually scroll in accordance with your custom control.

There is a catch : when GDI+ is turned on, there is no transparency.

good point

Thanks, Dave. Yes, on Windows 7. Scrollbar canvas overlaps listbox. Listbox scrollbars are off. It doesn’t flicker if I double buffer with the scrollbar beside the listbox or over it but with double buffer off and overlapping the listbox scroll thumb images glitches on drag.

Michel: Thanks. GDI+ is turned on but the transparency works with it on or off and it glitches either way. Doesn’t make a difference whether the canvas transparent is on or off or if canvas erasebackground is on or of either.