Solved

option button alignment  and VB5

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

Independent Software Vendors: 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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
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…

710 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