Solved

option button alignment  and VB5

Posted on 2000-02-20
5
227 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Access query that references subform 5 48
passing a value with stream reader AFTER a ";" 3 83
VB6 - Compare and highlight cell not the same 3 56
Excel Automation VBA 19 102
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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…
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…

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