LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Make a flat button

Solved!
Go to solution

CVI offers a wide but limited set of controls to choose from: besides experimenting with Windows theme and system colors on/off, you may want to follow other paths.

 

Consider for example this picture:

Buttons.jpg

As you can see, among the classic-style buttons CVI offers a square flat button that you may want to consider, but there are several caveats to evaluate before choosing it:

  • It is a toggle button, i.e. a two-state control: to simulate a regular button you must at least add some code to turn it off on EVENT_COMMIT event. Additionally, this means that the control operate on the click-on mouse state, while regular buttons operate on the click-up: it is not a trivial detail
  • The button maintains the black outline
  • If you put the button label within the button area, the control cannot be operated if clicking is on the label. That means that either the lable is out of the control as in my example or the label is very little with respect to control area thus leaving enough area to operate (but still clicking exactly on the lable won't operate the button) or you use EVENT_LEFT_CLICK or EVENT_LEFT_CLICK_UP instead of EVENT_COMMIT event in the control callback

 

Going further and with a little imagination you could arrive at this result:

Buttons2.jpg

Here you can see truly flat button compared with a native-style button. The flat button is really a set of two controls made with a little magic:

  • Create a dummy panel with windows visual style disabled
  • Place a classic-style button on it and paint it in transparent color
  • Copy the button and paste it on your actual panel: it doesn't matter the state of Windows Visual Style attribute, but Conform to Sytem Colors must be unchecked
  • Create a text message on the panel, disable Size to Text, delete the text and paint it with the color you want as the background for the flat button
  • Dimension the text message and the button the same size and place the latter on top of the text message et voilà

I leave you the UIR file with those solution for you to experiment.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 11 of 11
(2,433 Views)