Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / Controls / July 2008



Tip: Looking for answers? Try searching our database.

User Control - Out on Memory

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Timbo - 12 Jul 2008 18:16 GMT
Hi there,

I'm using VB6 and have written an ActiveX control in my VB project.  It is
quite small but has 66 picture boxes (using a control array) on it, however
only 1 of them is ever visible at anyone time - the main picture boxes
'picture' property is changed to a picture from one of the control arrays
depending on some properties.

This control is used to replace a conventional VB button. I am using this
control at least 15 times on any given form.  At run time, opening 1 form
with these control on seems to work, however when I try to open another form
simultaneously and am running into Runtime Error 7 - 'Out of Memory' errors.

I was under the impresstion that ActiveX controls where designed exactly for
the purpose I am using them for - to keep code and funtionality contained in
one place.

Do Picture boxes have a particularly high overhead with memory (even though
each picture is less than 1k)?  the compiled OCX is 116kb?  Please let me
know if I'm missing any other information you need to kmow.

If anyone can shed any light on what might be going on it would be greatly
appreciated.

TIA

Tim
BeastFish - 12 Jul 2008 18:56 GMT
Why 66?  To replicate a standard button, you should only need a few...
focus, no focus, clicked down, disabled.  Even if you're doing a hover
effect, that should only add another 1 or 2.

> Hi there,
>
[quoted text clipped - 23 lines]
>
> Tim
Timbo - 12 Jul 2008 20:15 GMT
Yes, I'm thinking maybe my approach is wrong here.  Basically I have, say,
30 pre-defined pictures that can be chosen as a property, then the control
displays the right picture.

Another way would be to pass the actual picture (GIF file) into a property
of the control.  Is this possible? - if so how would I create the property
to enable a picture to be passed into it.

Regards

Tim

> Why 66?  To replicate a standard button, you should only need a few...
> focus, no focus, clicked down, disabled.  Even if you're doing a hover
[quoted text clipped - 35 lines]
>>
>> Tim
BeastFish - 12 Jul 2008 20:56 GMT
Sure.  Off the top of my head, in the UC's (General)(Declarations)...

Public PictureFocus As Picture

...gives you a "PictureFocus" pic property in the UC's property window,
which you can also assign in app code.  You'd also want to add to the
ReadProperties and WriteProperties...

ReadProperties:
   Set PictureFocus = PropBag.ReadProperty("PictureFocus", Nothing)

WriteProperties:
   Call PropBag.WriteProperty("PictureFocus", PictureFocus, Nothing)

To tidy it up, you can swap the pics within the UC's code accordingly, like
on a mousedown, EnterFocus, etc.  One way is to throw a sub or function in
the UC...

Private Sub SetThePicture(ByRef The_Picture As Picture)
   Set UserControl.Picture = The_Picture
   UserControl.Refresh
End Sub

... and call it in your UC code...

Private Sub UserControl_EnterFocus()
   Call SetMyPicture(PictureFocus)
End Sub

Just some basic "off the top of my head" examples.  You'd likely need to
expand on these depending on your needs.  Like if you need to autosize, just
add something like this to your SetThePicture sub/function...

   UserControl.Width = UserControl.ScaleX(UserControl.Picture.Width, _
                vbHimetric, UserControl.ScaleMode)
   UserControl.Height = UserControl.ScaleY(UserControl.Picture.Height, _
                vbHimetric, UserControl.ScaleMode)

BTW, to get your UC/OCX to behave like a standard command button, you'd want
to remove the DoubleClick from it...

Private Declare Function GetClassLong Lib "user32" Alias "GetClassLongA" _
   (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetClassLong Lib "user32" Alias "SetClassLongA" _
   (ByVal hWnd As Long, ByVal nIndex As Long, _
   ByVal dwNewLong As Long) As Long
Private Const GCL_STYLE = (-26)
Private Const CS_DBLCLKS = &H8

Private Sub UserControl_Initialize()
   Dim MyStyle As Long
   MyStyle = GetClassLong(Me.hWnd, GCL_STYLE)
   MyStyle = MyStyle And Not CS_DBLCLKS ' remove DoubleClick
   SetClassLong Me.hWnd, GCL_STYLE, MyStyle
End Sub

> Yes, I'm thinking maybe my approach is wrong here.  Basically I have, say,
> 30 pre-defined pictures that can be chosen as a property, then the control
[quoted text clipped - 47 lines]
> >>
> >> Tim
Larry Serflaten - 12 Jul 2008 21:55 GMT
> Yes, I'm thinking maybe my approach is wrong here.  Basically I have, say,
> 30 pre-defined pictures that can be chosen as a property, then the control
> displays the right picture.

I'd agree, an array of  66 Pictureboxes would not be the optimal approach
in that case.

> Another way would be to pass the actual picture (GIF file) into a property
> of the control.  Is this possible? - if so how would I create the property
> to enable a picture to be passed into it.

There are several ways to accomplish that same effect.  As was already
pointed out, you could have a Picture type property.  But, there are other
methods you can use to provide pre-defined images, such as drawing
the image as needed, or composing the image from individual elements,
or even providing one large image that has 30 different cells you can
copy from.

Taking a cue from a form's MouseIcon, and MousePointer, it may be
nice to have a list of pre-defined images, plus the means to allow the
user to supply their own....

LFS
Timbo - 12 Jul 2008 23:31 GMT
Thanks for your all your comments.  I am now using and Image box and passing
the picture into the control.  All working perfectly - happy days!

Cheers

>> Yes, I'm thinking maybe my approach is wrong here.  Basically I have,
>> say,
[quoted text clipped - 23 lines]
>
> LFS
Kevin Provance - 13 Jul 2008 03:05 GMT
Why even bother with a picture box at all?  A long time ago I wrote my own
button control using pictureboxes and it was a memory nightmare.  Eventually
I moved everything to API a drew everything via the hDC.  Lightened things
up a bit.

| Why 66?  To replicate a standard button, you should only need a few...
| focus, no focus, clicked down, disabled.  Even if you're doing a hover
[quoted text clipped - 33 lines]
| >
| > Tim
Galen Somerville - 12 Jul 2008 20:04 GMT
> Hi there,
>
[quoted text clipped - 24 lines]
>
> Tim

One picture box should do it. Then those properties you mentioned would be
applied to the picturebox.

Galen
mayayana - 12 Jul 2008 20:14 GMT
> Do Picture boxes have a particularly high overhead with memory (even though
> each picture is less than 1k)?  the compiled OCX is 116kb?  Please let me
> know if I'm missing any other information you need to kmow.

  Each PictureBox has an hWnd. You should just use a
single PBox per control and switch the image. Better
yet, use an Image control, which doesn't have an hWnd.
One very lightweight way to do it is to use simply an
Image control with a picture of a button in it. On
MouseDown (if Image is enabled) do:

 Image1.Appearance = 1
 Image1.BorderStyle = 1

On MouseUp do:

 Image1.Appearance = 0
 Image1.BorderStyle = 0

 I've also created Opera/Mac style buttons that "glow"
on mouse hover by creating a UserControl with an
Image control on it. The Image gets moved slightly on click,
to simulate button press. The glow, and also disabled
appearance, were done by showing or hiding two shapes,
one set to MergePen and one set to MaskPen for DrawMode.
The images in the buttons are "3-D" pictures of silver
buttons. I put the text on each button image and then
have a Picture property for the UC, in order to load an
image into each button created. There's an hWnd for the
UC (which allows for a subclass to catch events) but no
hWnd for the Image or Shapes.

  That design was resulted from some experimentation
in which I was trying to get the leanest possible button
control that would still, nevertheless, look like an
improvement on a Windows button. (One downside,
though, is that a button with an embedded image of the
button text doesn't lend itself well to internationalization.)
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.