Bitmaps as buttons?

  • Thread starter Thread starter Flashster
  • Start date Start date
F

Flashster

I want to create buttons in the shape of bitmaps - i.e. without a square
around them.

How would I do this?

Thanks,

Flash
 
Flashster said:
I want to create buttons in the shape of bitmaps - i.e. without a square
around them.


Create a class which inherits from 'Button'. Then create a 'Region' object
of appropriate shape and assign it to the control's 'Region' property at
runtime, and override the control's 'OnPaint' method to draw the bitmap onto
the button.
 
Is there a way of specifying the 'Region' using a mask of the bitmap or
similar method?
I would prefer not to have to draw the region programmatically for each and
every point on a button shape if possible.
 
You could also use a picture box for the button...it has click events.
--
Dennis in Houston


Flashster said:
Is there a way of specifying the 'Region' using a mask of the bitmap or
similar method?
I would prefer not to have to draw the region programmatically for each and
every point on a button shape if possible.
 
Hi Dennis,

The problem with using the picture box is again that its square. If I have
an irregular shaped bitmap that changes color when the mouse moves over it
(for example) then a transparent square behind it will cause the bitmap to
change colour even when the mouse cursor is not over it (i.e. it will be
over the transparent square but not the bitmap shpae that the user sees).

What I need is a similar technique as is used to shape forms - i.e. use some
sort of masking shape.

Anyone any suggestions?? Surely there's a way of doing this besides drawing
each point in a Region to match the bitmap?

Dennis said:
You could also use a picture box for the button...it has click events.
 
Flasher,

You make me curious, how do you want to make non square buttons without to
tell what the region should be of that button. You can use the bitmap
solution, however I would not to that because you are than direct in trouble
with a W98/Me or with more than 24bits screen color setting, and those who
don't have today still not 32bits are probalby not so interested in your
shaped button.

Just my thought,

Cor
 
Hi Cor.

The application I am developing is for a very specific set of people. It
will only be run on Windows XP or possibly Windows 2000, and the graphics on
the user interface are to match a similar application (written on an
entirely different platform, using different technology).

I clearly need to specify the region of the button, but wondered if there
was any way of doing it besides drawing the bitmap shape, point by point.

If using some sort of mask (i.e transparency) would cause problems in 24 bit
displays (as I think you are saying) , then am I right in assuming that
drawing the region point by point (as suggested in Herfried's earlier
message) would avoid this problem and display correctly on any system?

I just hoped there was an easier way to specifiy a region, perhaps by using
a masking bitmap.
 
Hi Cor,

Thanks for that. I see that you can use a string as a graphicspath which
acts like a mask, but it still doesn't allow me to use a bitmap (i.e. I can
use a string or draw the points of a shape). Correct me if I have
interpreted your code or what you are saying wrongly.

Whilst I was looking at your code, Mick Doherty has sent a link to some code
that does draw a 'transparent' control based on the color of the bottom left
pixel being the transparent color. This is close to what I mean - I need to
code this into a button control.

Take a look and see what I mean:
http://www.dotnetrix.co.uk/custom.html

Thanks,

Flashster
 
Mick,

Thanks for that. I just need to get that to work as a button class and I'm
away. Will let you know the code I end up using,

Flashster

"Mick Doherty"
 
See the article in the GDI+ FAQ on how to extract a region from a bitmap.
Then use the resulting region to greate a shape for your button.


--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
Flashster,

I am sure that especially Bob (which is the number one GDI+ guy on these
newsgroup knows much more from this than me). I saw the sample from Mick as
well after sending my post and it shows good. It looks that it need some
distilating, however that gives the liqueur of the job.

I am strugling forever as well with regions, however it is not difficult as
it seems, that is all I wanted to say.

It takes probably for you and me some more time than for Bob and Mick but
don't go around it, for me it is always much easier than I am afraid of.

:-)

Cor
 
Thanks Bob - very useful page. Same 'scanning with rectangles' technique as
Mick suggested. Some very useful other stuff on there too. Will take a good
look later,

Thanks!

Flash
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Editing an indexed PixelFormat 1
screen cap multi monitor problem 2
GDI color depth? 5
Compressed Bitmap 3
tracing a line in a bitmap? 3
Winforms Question 9
Icon vs BitMap 2
Shape Arrays VBA 0

Back
Top