Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

option button alignment  and VB5

Posted on 2000-02-20
5
Medium Priority
?
236 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 120 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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

886 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