473,385 Members | 1,309 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Image drawn on custom button subclass does not show up

Hey,

I am trying to subclass a button to create a control similar to the
Firefox/IE dropdown button. My first step is to draw the 'down arrow'
on the button. I overrided the OnPaint method thusly:
protected override void OnPaintBackground(PaintEventArgs pevent)
{
base.OnPaintBackground(pevent);
paintArrow();
}

void paintArrow()
{
Graphics G = CreateGraphics();

Bitmap b = LibXIE.img.DownArrow;

//Draw the down arrow centered and to the right
Point arrowPoint = new Point(
Width - b.Width - padding,
Height / 2 - b.Height / 2);

G.DrawImageUnscaled(b, arrowPoint);
}

However, the arrow only shows up when I resize the borders of the
button (in the form designer). When the button is drawn the paintArrow
event is called (I can add debugging and see it being called), but the
arrow does not show up.

Are there other methods I have to override? Or am I doing something
wrong?

Thanks,
Nathan

Dec 5 '06 #1
4 2742
See the #1 most asked GDI+ FAQ question.

--
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.

"Nathan Baker" <na*****@vt.eduwrote in message
news:11**********************@l12g2000cwl.googlegr oups.com...
Hey,

I am trying to subclass a button to create a control similar to the
Firefox/IE dropdown button. My first step is to draw the 'down arrow'
on the button. I overrided the OnPaint method thusly:
protected override void OnPaintBackground(PaintEventArgs pevent)
{
base.OnPaintBackground(pevent);
paintArrow();
}

void paintArrow()
{
Graphics G = CreateGraphics();

Bitmap b = LibXIE.img.DownArrow;

//Draw the down arrow centered and to the right
Point arrowPoint = new Point(
Width - b.Width - padding,
Height / 2 - b.Height / 2);

G.DrawImageUnscaled(b, arrowPoint);
}

However, the arrow only shows up when I resize the borders of the
button (in the form designer). When the button is drawn the paintArrow
event is called (I can add debugging and see it being called), but the
arrow does not show up.

Are there other methods I have to override? Or am I doing something
wrong?

Thanks,
Nathan

Dec 5 '06 #2
Bob,

Thanks for your reply. However, I do not believe that question applies
to this case:
* I am not using a picturebox
* I am using the onpaint event
* I am not doing any drawing outside of the paint method (I do my
drawing in the drawArrow method, which is called by the paint method)

If I missed something when reading the article then please point it out
to me.

Thanks again,
Nathan

Bob Powell [MVP] wrote:
See the #1 most asked GDI+ FAQ question.
Dec 6 '06 #3
Bob,

I read over the FAQ entry again, and I noticed something I had missed
before: I was calling CreateGraphics myself instead of using the
pevent.Graphics field. I changed my code to use this instead, and it
works fine now.

Sorry for asking a question that was covered in the FAQ, and thanks for
pointing me in the right direction.

Nathan

Dec 6 '06 #4
;-)

--
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.

"Nathan Baker" <na*****@vt.eduwrote in message
news:11*********************@j72g2000cwa.googlegro ups.com...
Bob,

I read over the FAQ entry again, and I noticed something I had missed
before: I was calling CreateGraphics myself instead of using the
pevent.Graphics field. I changed my code to use this instead, and it
works fine now.

Sorry for asking a question that was covered in the FAQ, and thanks for
pointing me in the right direction.

Nathan

Dec 6 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: JDevine | last post by:
I am going through the painfull process of learning wxPython. Sincer there is nearly no documentation, I am learning from the demos. Unfortunately, I have realized these demos do some specialized...
1
by: Mike Albrecht | last post by:
Hello Group, Pardon any cross posting. We wanted to replace the standard submit buttons on a web form with custom 'image' buttons. Here's the code I used: <input type="image"...
15
by: Anand Ganesh | last post by:
HI All, I have an Image. I want to clip a portion of it and copy to another image. How to do this? I know the bounding rectangle to clip. Any suggestions please. Thanks for your time and...
2
by: Zoury | last post by:
Hi there! :O) I'm trying to stick a 16x16 pixels image on a 24x24 pixels button. The image is never centered properly no matter what alignment i sets. there is always a little margin or...
3
by: David | last post by:
Hi, I am very new in the asp.net realm so this may be a very simple question for most of you. I want to put a little image icon in every button on my web form but there is no attribute in...
11
by: nuhura01 | last post by:
Hi.. I have a button to preview image using the following code, which preview the image in html page: Dim oStringWriter As System.IO.StringWriter = New System.IO.StringWriter Dim...
3
by: kayahr | last post by:
Hi there, I have a strange problem in Internet Explorer (IE6 and IE7). I'm writing a JavaScript application which allows the user to edit a photo composition. So when the user selects a photo then...
2
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
0
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.