Solved

option button alignment  and VB5

Posted on 2000-02-20
5
219 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

762 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now