Visit our new web pagesWe have launched a new extended set of web pages at www.alvechurchdata.co.uk. These old pages will stay on the server because people still have links to them but they will not be updated. The new version of this page is at www.alvechurchdata.co.uk/hints-and-tips/acccentre.html. |
||
Home About us Development Training Support |
Centre controls on the screenYour Access forms might be running on all sorts of different computers with different sizes of screen. The controls might look good when you design the form but they'll all be crowded on the left-hand side if the user maximises the form on a larger screen. The code below is my solution. I've kept it simple by restricting the user's choices:
Put this code in the form's Open method:
Private Sub
Form_Open(Cancel
As Integer)
Dim intOrigWidth As Integer ' Original form width Dim intOffSet As Integer ' Distance to move each control intOrigWidth = Me.WindowWidth DoCmd.Maximize intOffset = (Me.WindowWidth - intOrigWidth) / 2 '-- Freeze the screen to prevent flickering Me.Painting = False For Each ctl In Me.Controls ctl.Left = ctl.Left + intOffset Next ctl '-- Show all the changes at once Me.Painting = True End Sub Set the following properties:
You end up with a form that looks like this:
ProblemsA better solution would be to write much more code to move and resize the controls as the user changes the size of the form. This gets difficult because some controls (like textboxes) must stay the same height whereas others (like listboxes) must get larger as the form gets taller. Restricting myself to horizontal movement kept it simple. If the form includes containers like Tabbed Controls or Option Groups then you'll need to add extra code to handle them. Use the ControlType property inside the loop to detect these controls. |
Hints & tips
The textbox class in Visual FoxPro 9 has a new Autocomplete
property which shows the user the previous values that have
been entered in that textbox.
More...
|