Solved

option button alignment  and VB5

Posted on 2000-02-20
5
226 Views
Last Modified: 2010-05-02
Does anybody know how can I set alignment property of Option Button at run time in VB5 ?

Thanks ...
0
Comment
Question by:Maximka
5 Comments
 
LVL 14

Expert Comment

by:mcrider
ID: 2539501
You can't... It is one of those read only properties... BUT, what you can do is have 2 option buttons, one left justified and the other right justified.

Then set the following properties for the one you want to use:

    Option1.Visible = True
    Option1.Enabled = True

and set the other one like this:

    Option2.Visible = False
    Option2.Enabled = False


Cheers!
0
 
LVL 3

Expert Comment

by:paulstamp
ID: 2539520
You could do as mcrider suggests, but that not ideal because it means having to have two option buttons in place of one, and to handle the click events in both. You might also conceivably have problems with the buttons being in the same group.

I would do it this way : have no caption for the option button and place a label control (with autosize set to true) next to the button.

Depending on whether you simply want to (a) change the alignment of the caption, or (b) switch the position of the caption relative to the button :

a) set the alignment property of the label

or

b) change the left property of the label itself:

If Label1.Left > Option1.Left Then
    Label1.Left = Option1.Left - Label1.Width - 90
Else
    Label1.Left = Option1.Left + Option1.Width + 90
End If


Hope this helps

0
 
LVL 15

Accepted Solution

by:
ameba earned 30 total points
ID: 2540952
This code will switch option button alignment

' add option button, paste this code
Option Explicit
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Const GWL_STYLE = (-16)
Private Const BS_LEFTTEXT = &H20&

Private Sub Form_Click()
    Dim style As Long
    style = GetWindowLong(Me.Option1.hwnd, GWL_STYLE)
    If style And BS_LEFTTEXT Then
        style = style Xor BS_LEFTTEXT ' left alignment
    Else
        style = style Or BS_LEFTTEXT ' right alignment
    End If
    style = SetWindowLong(Me.Option1.hwnd, GWL_STYLE, style)
    Me.Option1.Refresh
End Sub
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2541335
Yea ameba!
0
 
LVL 1

Author Comment

by:Maximka
ID: 2541460
Thank You very much dear ameba !!!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question