Command button properties

Hi there

I have several command buttons which I need to set certain properties.

I already have some code that aligns the caption on the command button to the left, this is:

Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Const GWL_STYLE = (-16)

lngOldValue = GetWindowLong(cmd_btn1.hWnd, GWL_STYLE)
SetWindowLong cmd_btn1.hWnd, GWL_STYLE, lngOldValue Or &H100

How do I set the background and foreground colours etc???

By simply typing "cmd_btn1.BackColor = RGB(148, 185, 226)", then I essentially overwrite what I have done in the above code and hence my caption returns to centre.

I don't really understand what GWL_STYLE is and I am assuming that I somehow have to incorporate my colour scheme using this method somehow?

Any help would be great!!!

Cheers

Andy
Colly321Asked:
Who is Participating?
 
edwardiiiConnect With a Mentor Commented:
Hi, Colly321.

This does seem somewhat involved.  For example, to set the ForeColor of a command button, see this URL:

     http://vbnet.mvps.org/index.html?code/subclass/buttoncolour.htm

This link also discusses this topic, and itself links to a 3rd party solution:

     http://www.mcse.ms/message293460.html (http://www.lebans.com/cmdbutton.htm)

Or, along shijusn's comment, go with the Style Property of "Graphical" and show an image on the command button (e.g. with the image being a snapshot of text that is aligned and colored as you wish).
0
 
Shiju SasidharanAssoc Project ManagerCommented:
Change Style Propery of button to
   1 -Graphical
and try
0
 
Colly321Author Commented:
Nah thats not it - it allows me to change the colours etc, but I no longer can set the caption to be left justified???
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

 
Colly321Author Commented:
Hi edwardiii

I think it comes down to either:

1. Colouring the background and accepting the caption is going to be aligned centre

or

2. Aligning the caption left, and accepting the standard windows colour.

I personally don't want to create images, which although they may look nice, they create more work in the long run, especially if the text needs changing on them?

Your 2 links aren't really what I want?

Cheers

Andy
0
 
edwardiiiCommented:
A third option, with the (http://www.lebans.com/cmdbutton.htm) link as an example, is to obtain a third-party button code, which will allow you to do everything you want.  Short of third-party code, you may be able to get the ForeColor API to work in tandem with your existing Left-alignment code, but setting BackColor hasn't been addressed at all.

Leave this post up for a while; another expert may provide exactly what you need.  You may even contact the page admin (bingie) to verify.  But thus far, everything I'm scanning online seems to indicate the fastest, easiest way to get what you want is to acquire a third-party solution as with lebans.com:)
0
 
Mikal613Commented:
www.fpoint.com

USe there command buttons. Anything you can ever dream of doing with a button is there.
0
 
SethiCommented:
Here are a few excellent free XP controls that I use and the command button is too good. You can give it an XP or a classic look as well:
http://home.pages.at/vbmaster/Downloads.html
http://www.innovasys.com/
0
 
Colly321Author Commented:
Hi guys

Thanks for all your help, I have pretty much given up on this - there are ways to do both my requests, but it is pretty tricky to acheive both.

I think that the best way to think about it is to remember that it is a Windows program - not a Director style CD-ROM!!!!

My clients like the fancy graphics etc which I think is not always the best method of doing things!!!

Cheers

Andy
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.