tips
[Top] [All Lists]

Putting your Default and Cancel buttons in their place

To: "REALbasic Tips" <realbasic-tips at lists dot realsoftware dot com>
Subject: Putting your Default and Cancel buttons in their place
From: Geoff Perlman <geoff at realsoftware dot com>
Date: Tue, 13 Jun 2000 11:02:39 -0500
When building a dialog box, the Mac standard is to position the OK button in the lower right corner and the Cancel button (if there is one) to the left of the OK button. Special note: Notice I said "OK" and not "default" as the
default button should be the action the user will most likely wish to
perform or in the case of actions that would cause data loss, the action
that prevents data loss.

The Windows standard for button placement is exactly the opposite of the Mac (surprise, surprise). In the Windows world, the Cancel button is positioned in the lower right corner and the OK button is positioned to its left. This means that if you want your dialog boxes to look correct on both platforms, you will need to add some code to reposition your Cancel and OK buttons when your application is running on Win32. To make this easier, I've written a
method that will handle this for you. The method, called
"Win32ButtonSwitcher", takes as parameters your OK and Cancel button names (not the caption, the name of the control). You simply call this method in
the Open event of the window. Here's the method:

Sub Win32ButtonSwitcher(CancelButton as Pushbutton, OKButton as Pushbutton)
   dim OKtop, OKleft, cancelTop, cancelLeft as integer

   #if targetWin32 then
   cancelTop = CancelButton.top
   cancelLeft = CancelButton.left
   OKtop = OKButton.top
   OKleft = OKButton.left

   CancelButton.top = OKtop
   CancelButton.left = OKleft
   OKButton.top = cancelTop
   OKButton.left = cancelLeft
   #endif
End Sub

I've enclosed a module that includes this method to make installing it into
your projects easier.
--

Geoff Perlman
President & CEO
REAL Software, Inc.
http://www.realsoftware.com
mailto:geoff at realsoftware dot com
Phone: 512-263-1233 x711
Fax:   512-263-1441

Attachment: ButtonSwitcher.sit
Description: Macintosh archive

<Prev in Thread] Current Thread [Next in Thread>
  • Putting your Default and Cancel buttons in their place, Geoff Perlman <=