From: Webbiz on
I'm at my end trying to figure this out.

This is something that has been working just fine for a couple years
now. But all of a sudden, I get this "Can't create AutoRedraw image"
when I click on a button that runs this routine:

Public Sub InitializeTextBox(TBox As TextBox, _
Optional FormOrPictureBox As Variant)

If IsMissing(FormOrPictureBox) Then
Set FontContainer = TBox.Parent
Else
Set FontContainer = FormOrPictureBox
End If

If TypeOf FontContainer Is Form Or _
TypeOf FontContainer Is PictureBox Then

With TBox
Set FontContainer.font = .font
MaxWidth = .Container.ScaleWidth - .left
MinWidth = FontContainer.TextWidth("XX")
HeightOfLine = FontContainer.TextHeight("X")
.height = HeightOfLine
.width = MinWidth
End With

Else

Err.Clear
Err.Raise 10001, "InitializeTextBox Subroutine", _
"You did not pass either a Form or " & _
"PictureBox into the FormOrPictureBox " & _
"argument for the InitializeTextBox " & _
"subroutine."
End If


End Sub


THE ERROR breaks at:

MinWidth = FontContainer.TextWidth("XX")

I'm not able to figure out why.

Any suggestions?

Webbiz
From: Webbiz on
On Wed, 09 Sep 2009 22:28:07 -0500, Webbiz <nospam(a)forme.thanks.com>
wrote:

>I'm at my end trying to figure this out.
>
>This is something that has been working just fine for a couple years
>now. But all of a sudden, I get this "Can't create AutoRedraw image"
>when I click on a button that runs this routine:
>
>Public Sub InitializeTextBox(TBox As TextBox, _
> Optional FormOrPictureBox As Variant)
>
> If IsMissing(FormOrPictureBox) Then
> Set FontContainer = TBox.Parent
> Else
> Set FontContainer = FormOrPictureBox
> End If
>
> If TypeOf FontContainer Is Form Or _
> TypeOf FontContainer Is PictureBox Then
>
> With TBox
> Set FontContainer.font = .font
> MaxWidth = .Container.ScaleWidth - .left
> MinWidth = FontContainer.TextWidth("XX")
> HeightOfLine = FontContainer.TextHeight("X")
> .height = HeightOfLine
> .width = MinWidth
> End With
>
> Else
>
> Err.Clear
> Err.Raise 10001, "InitializeTextBox Subroutine", _
> "You did not pass either a Form or " & _
> "PictureBox into the FormOrPictureBox " & _
> "argument for the InitializeTextBox " & _
> "subroutine."
> End If
>
>
>End Sub
>
>
>THE ERROR breaks at:
>
>MinWidth = FontContainer.TextWidth("XX")
>
>I'm not able to figure out why.
>
>Any suggestions?
>
>Webbiz

I don't get it. How could this have been working all this time and
then suddenly, today, doing the same thing I do with it every day,
decide it is no longer going to work? Even old copies of my compiled
application now fails when I activate this tool.

Out of curiousity, went in and placed .AutoRefresh = False right at
the point of entry of this where this routine is called and the
problem went away. I couldn't find it affecting anything else, so I'll
leave it in there for now.

But does anyone have any idea what could have changed that would cause
this to just now decide to stop working?




From: Mike Williams on
"Webbiz" <nospam(a)forme.thanks.com> wrote in message
news:rdsga5l3sn47pcc40flsk40et0drs8saqn(a)4ax.com...

> I'm at my end trying to figure this out. This is something
> that has been working just fine for a couple years now.
> But all of a sudden, I get this "Can't create AutoRedraw
> image" when I click on a button that runs this routine:
> [only the relevant lines shown here]
> Set fontcontainer = FormOrPictureBox
> With TBox
> Set FontContainer.font = .font
> MaxWidth = .Container.ScaleWidth - .left
> MinWidth = FontContainer.TextWidth("XX")
> HeightOfLine = FontContainer.TextHeight("X")
> .height = HeightOfLine
> .width = MinWidth
> End With
> THE ERROR breaks at:
> MinWidth = FontContainer.TextWidth("XX")

It would appear that the FormOrPictureBox (presumably a PictureBox because
of its apparent size) is quite large and that its Autoredraw property is set
to True. An Autoredraw PictureBox can of course be set to as large a size as
you like (up to a maximum of 1683 x 1683 pixels) without producing any
errors until you do something to it that causes VB to attempt to set up its
Autoredraw memory image, at which time it will produce a "Can't Create
Autoredraw Image" if it cannot find a large enough contiguous block of
memory in which to store it.

So, the first time your code attempts to draw something into it (Line, Pset,
Print, etc) or the first time you do something else which causes VB to
attempt to create the Autoredraw image (such as using the TextWidth funtion
on it) will be the line at which the error occurs. That's why your error is
happenning on the MinWidth = FontContainer.TextWidth("XX") line rather than
on any previous lines of code (in this routine or elsewhere) that actually
set the size of FormOrPictureBox.

My first question to you would be do you actually need this PictureBox to be
of such a large size, and do you also need its Autoredraw property to be
True? It would also be advisable to check the actual pixel size of the
PictureBox (at an appropriate point in your code). Is it roughly what you
expect it to be, or is it considerably larger? If the latter then have you
got a problem elsewhere in your code related to one or more of the various
controls you are using having a ScaleMode that does not match with others
that are related to it? ScaleMode errors such as this can often be
responsible for controls being set up to a size very much larger (or
smaller) than the size you have in mind.

It is not really surprising that this code has run fine before and is only
now starting to produce errors. It may be that you have made some change to
your code that causes the size to change from what you are expecting, or
perhaps you are using Autoredraw now when you were not before, or it may
simply be that your code has been "sailing too close to the wind" for quite
some time (as far as the contiguous memory block requirements such as
Autoredraw requires are concerned) and the various things you have recently
added have now "taken it over the edge". Anyway, the size of the PictureBox
and whether it really needs to be Autoredraw are the first places to look
for the cause of your problem.

Mike




From: Webbiz on
On Thu, 10 Sep 2009 10:02:59 +0100, "Mike Williams"
<Mike(a)WhiskyAndCoke.com> wrote:

>"Webbiz" <nospam(a)forme.thanks.com> wrote in message
>news:rdsga5l3sn47pcc40flsk40et0drs8saqn(a)4ax.com...
>
>> I'm at my end trying to figure this out. This is something
>> that has been working just fine for a couple years now.
>> But all of a sudden, I get this "Can't create AutoRedraw
>> image" when I click on a button that runs this routine:
>> [only the relevant lines shown here]
>> Set fontcontainer = FormOrPictureBox
>> With TBox
>> Set FontContainer.font = .font
>> MaxWidth = .Container.ScaleWidth - .left
>> MinWidth = FontContainer.TextWidth("XX")
>> HeightOfLine = FontContainer.TextHeight("X")
>> .height = HeightOfLine
>> .width = MinWidth
>> End With
>> THE ERROR breaks at:
>> MinWidth = FontContainer.TextWidth("XX")
>
>It would appear that the FormOrPictureBox (presumably a PictureBox because
>of its apparent size) is quite large and that its Autoredraw property is set
>to True. An Autoredraw PictureBox can of course be set to as large a size as
>you like (up to a maximum of 1683 x 1683 pixels) without producing any
>errors until you do something to it that causes VB to attempt to set up its
>Autoredraw memory image, at which time it will produce a "Can't Create
>Autoredraw Image" if it cannot find a large enough contiguous block of
>memory in which to store it.
>
>So, the first time your code attempts to draw something into it (Line, Pset,
>Print, etc) or the first time you do something else which causes VB to
>attempt to create the Autoredraw image (such as using the TextWidth funtion
>on it) will be the line at which the error occurs. That's why your error is
>happenning on the MinWidth = FontContainer.TextWidth("XX") line rather than
>on any previous lines of code (in this routine or elsewhere) that actually
>set the size of FormOrPictureBox.
>
>My first question to you would be do you actually need this PictureBox to be
>of such a large size, and do you also need its Autoredraw property to be
>True?

Hello Mike. Been a long time. :-)

Large size? Yes. It's the chart window and takes up virtually all the
space on the form. And the form is usually maximized. And if it is
relevant, my display is 22inch flat. (actually a couple of them
side-by-side, but I've not stretched this app beyond the one monitor.)

Autoresize? You got me there. I've never really gotten a good handle
on this particular property. You worked with me on this issue a few
years ago, you may recall. With all that was discussed, and all that
has to done on this picturebox, I cannot recall why it is set one way
or the other.

>It would also be advisable to check the actual pixel size of the
>PictureBox (at an appropriate point in your code). Is it roughly what you
>expect it to be, or is it considerably larger? If the latter then have you
>got a problem elsewhere in your code related to one or more of the various
>controls you are using having a ScaleMode that does not match with others
>that are related to it? ScaleMode errors such as this can often be
>responsible for controls being set up to a size very much larger (or
>smaller) than the size you have in mind.

No size in mind as mentioned. Just fill the form and the form fills
the display.

>
>It is not really surprising that this code has run fine before and is only
>now starting to produce errors. It may be that you have made some change to
>your code that causes the size to change from what you are expecting, or
>perhaps you are using Autoredraw now when you were not before, or it may
>simply be that your code has been "sailing too close to the wind" for quite
>some time (as far as the contiguous memory block requirements such as
>Autoredraw requires are concerned) and the various things you have recently
>added have now "taken it over the edge". Anyway, the size of the PictureBox
>and whether it really needs to be Autoredraw are the first places to look
>for the cause of your problem.
>
>Mike

I would have suspected a change in code, but that's impossible when
now my backed up older compiled exe also hits this snag now.

Anyway, in another post I mention placing .AutoRedraw = False at the
point of entry to the routines that are triggered by the button event.
It seems to be working okay right now, so I'll keep an eye on any
adverse effects.

Thanks Mike.

Webbiz
From: Dave O. on

"Webbiz" <nospam(a)forme.thanks.com> wrote in message
news:a13ia51he83d0pasgmt4h7lpbmfq3dmfrm(a)4ax.com...
> On Thu, 10 Sep 2009 10:02:59 +0100, "Mike Williams"
> <Mike(a)WhiskyAndCoke.com> wrote:

>> ScaleMode errors such as this can often be
>>responsible for controls being set up to a size very much larger (or
>>smaller) than the size you have in mind.
>
> No size in mind as mentioned. Just fill the form and the form fills
> the display.

How?
pic.width = form.width?
pic.width = form.scalewidth?
If either's the case you *really* do need to check for scalemode errors.

An easy way to test: Make the picture box a contrasting colour then in the
sizing routine, subtract a number like 15 from the height and width, you
should have a line of form visible right & bottom, if not there is something
wrong.

Dave O.


 |  Next  |  Last
Pages: 1 2 3 4
Prev: Permissions again
Next: simple stopwach program