[Closed] ,NET button alpha
Is there any way to make a .NET button respect the alpha of a tif image?
If an image contains alpha channel, it is used when you add it to a button.
If what you need instead is the button to automatically use the alpha channel of its image as the button region, I believe there is no building .Net Property or Method that handles it.
In that case here are some options I can think of:
- Build your own .Net control.
- Manually build the region of the button.
- Parse the image alpha channel and automatically build the region.
- Find a library that already does it for you.
- Overwrite the mouse events and detect whether the cursor is over an alpha==0 pixel or alpha!=0 and trigger your action.
Perhaps DevExpress has some control that allows you to do this?
I agree. How would you approach it?
Defining the control region at runtime based on the image alpha is not very efficient.
Perhaps overriding the mouse events and getting the image pixel alpha to trigger them.
how big is the image, and what is the purpose of the UI?
couldn’t you just convert to a .png on the fly to display on the button?
This works right away. Could the issue be in another place like yous OS/settings, .tif file?
(
source = dotnetobject "System.Drawing.Bitmap" @"C:\bt_01.tif"
bmp = dotnetobject "System.Drawing.Bitmap" source.Width source.Height
graph = (dotnetclass "System.Drawing.Graphics").fromImage bmp
graph.DrawImage source 0 0 source.Width source.Height
graph.dispose()
source.Dispose()
form = dotnetobject "MaxCustomControls.Maxform"
form.ClientSize = dotnetobject "System.Drawing.Size" 120 120
bt_01 = dotnetobject "Button"
bt_01.Bounds = dotnetobject "System.Drawing.Rectangle" 20 20 80 80
bt_01.FlatStyle = bt_01.FlatStyle.Flat
bt_01.FlatAppearance.MouseOverBackColor = bt_01.FlatAppearance.MouseOverBackColor.Yellow
bt_01.Image = bmp
form.Controls.Add bt_01
form.ShowModeless()
)
That’s a new one on me.
rollout pngtest "" width:155 height:232
(
local uiColor = ((dotnetclass "managedservices.CUIupdater").getinstance()).getcontrolcolor()
dotnetcontrol btn1 "button" pos:[7,5] width:68 height:71
dotnetcontrol btn2 "button" pos:[80,5] width:68 height:71
dotnetcontrol btn3 "button" pos:[7,80] width:68 height:71
dotnetcontrol btn4 "button" pos:[80,80] width:68 height:71
dotnetcontrol btn5 "button" pos:[7,155] width:68 height:71
dotnetcontrol btn6 "button" pos:[80,155] width:68 height:71
on pngtest open do
(
icondir = pathconfig.appendpath (getdir #maxroot) @"UI_ln\Resources\Light\Icons\Modeling"
icons = getfiles ( icondir + @"\\*.png")
for i = 1 to 6 do
(
btn = pngtest.controls[i]
btn.flatstyle = btn.flatstyle.flat
btn.FlatAppearance.BorderSize = 0
btn.backcolor = uiColor
btn.image = (dotnetclass "system.drawing.image").fromFile icons[i]
)
)
)
createdialog pngtest
OK, I see. Thnx. By the way, does anyone know how to scale the bitmaps in a .net window when the window is resized. I’ve researched this one and the consensus seems to be that it can’t be done