473,809 Members | 2,763 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 OnPaintBackgrou nd(PaintEventAr gs pevent)
{
base.OnPaintBac kground(pevent) ;
paintArrow();
}

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

Bitmap b = LibXIE.img.Down Arrow;

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

G.DrawImageUnsc aled(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 2760
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.edu wrote in message
news:11******** **************@ l12g2000cwl.goo glegroups.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 OnPaintBackgrou nd(PaintEventAr gs pevent)
{
base.OnPaintBac kground(pevent) ;
paintArrow();
}

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

Bitmap b = LibXIE.img.Down Arrow;

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

G.DrawImageUnsc aled(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.edu wrote in message
news:11******** *************@j 72g2000cwa.goog legroups.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
1618
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 importing and that all the imports are not applicable. Specifially, All I want to do now is insert a bmp I have drawn into a windows application. The image clases from the demos are completely unexplanatory about how to do this. The "images"...
1
6320
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" name="nametxt" value="valtxt" alt="text" title="txt" src="images/button.gif">
15
31816
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 help. Regards
2
1760
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 something.. any thoughts ? I've tried to override the OnPaint() events without any success (probably due to a lack of knowlegde in owner drawn controls.. :O) btw, is there a way to "subclass" or override a method without having to create a new...
3
6395
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 asp:Button allowing me to do this. Basically, the buttons are Text buttons except that there there is a small image icon before every button text. I am thinking about using Custom Control but I'm not sure if it is really necessary for my purpose....
11
12471
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 oHtmlTextWriter As System.Web.UI.HtmlTextWriter = New System.Web.UI.HtmlTextWriter(oStringWriter)
3
3940
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 a frame is drawn around it with resize and rotate buttons. Now it happened to me that I replaced these buttons (32x32) with larger images (48x48). The filenames were not changed, I only copied the new images over the old ones. Then I reloaded the...
2
19500
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 will be writing this article intended for those who are in the same level, or maybe lower, of my technical knowledge. I would be using layman's words, or maybe, my own words as how I understand them, hoping, you will understand it the same way that...
0
2897
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 will be writing this article intended for those who are in the same level, or maybe lower, of my technical knowledge. I would be using layman's words, or maybe, my own words as how I understand them, hoping, you will understand it the same way that...
0
9721
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9601
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10635
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10378
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9198
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7653
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4332
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3013
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.