Design view, size to fit, and form loading

M

MartinMCU

Hello all,

I have developed a database application with a moderate number of forms
(around 20). As part of each forms design, I have included a header section
with a label contral and a footer section with an image control. I have a
module that programatically sets various properties such as image souce, font
size, positions, etc that is called in each form's load event. So far, this
works great. However, each form already had the proper font set when the
label control in the header was sized. Thus, increasing the font size results
in clipping, defeating the entire purpose of my module. The whole point was
to be able to quickly and easily implement global graphic changes to the
application.

The problem I have with my module is this: upon calling
lblFormTitle.SizeToFit, the error number 2187 (This property is only
available in design view) is generated. I have set AllowDesignChanges to all
views, which does not solve the issue. I also tried to switch to designview
in the module code, which generated the error 2174 (You can't switch to a
different view at this time). This error makes sense, as otherwise, I think
an infinite loop would occur with the module switching to design view, then
switchng back to form view again, which calls the load event, which calls the
module, which calls... yeah, you get the idea. So, any thoughts? I have
considered building a separate routine that could be called only by a
developer to go through and programmatically alter the forms, but since it
only applies to main forms and not subforms, there doesn't seem to be a truly
elegant way of iterating through and doing this. Thanks,

Matt Martin
 
M

Marshall Barton

MartinMCU said:
I have developed a database application with a moderate number of forms
(around 20). As part of each forms design, I have included a header section
with a label contral and a footer section with an image control. I have a
module that programatically sets various properties such as image souce, font
size, positions, etc that is called in each form's load event. So far, this
works great. However, each form already had the proper font set when the
label control in the header was sized. Thus, increasing the font size results
in clipping, defeating the entire purpose of my module. The whole point was
to be able to quickly and easily implement global graphic changes to the
application.

The problem I have with my module is this: upon calling
lblFormTitle.SizeToFit, the error number 2187 (This property is only
available in design view) is generated. I have set AllowDesignChanges to all
views, which does not solve the issue. I also tried to switch to designview
in the module code, which generated the error 2174 (You can't switch to a
different view at this time). This error makes sense, as otherwise, I think
an infinite loop would occur with the module switching to design view, then
switchng back to form view again, which calls the load event, which calls the
module, which calls... yeah, you get the idea. So, any thoughts? I have
considered building a separate routine that could be called only by a
developer to go through and programmatically alter the forms, but since it
only applies to main forms and not subforms, there doesn't seem to be a truly
elegant way of iterating through and doing this. Thanks,


This is a very messy situation that certainly will not yield
to anything "elegant".

You've already seen the problems with using SizeToFit and
other design time changes that just make it clear that that
is not a viable approach.

You can use a bunch of code to calculate the control's Width
based on its runtime contents and display properties. The
core function is the TextHeightWidth function at
www.lebans.com Once you get the required width, you can
figure out the other control's Left, etc.
 
M

MartinMCU

Thanks! It's at least a start. There seems to be a bit of a glitch in the
height calculation, but I think I fixed it - it seems to be working anyways.
 

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