Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET C#4.0
How can i create a button that have a image and a text on it??
Posted 7-Dec-12 3:40am
Comments
joshrduncan2012 at 7-Dec-12 10:03am
   
You have to give us more information. What IDE are you using? What is your intended use for this button creation?
Annnaa at 7-Dec-12 10:06am
   
i am using vs 2010 and i am working on a web app
i want to create for example a 'save' button..
& i want it to have a image and the text 'SAVE'
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Add This CSS to your HTML in a STYLE tag or better yet put it in a .css file and reference it in a Link tag:
 
.saveBtn
 {
   background: url('/img/disk.png');
   background-position:center;
   background-repeat:no-repeat;
}
 

Here is the HTML input object. The CSS references it by the class name 'saveBtn'
 
<input type=button id="btnSave" class="saveBtn" value="Save"/>
  Permalink  
v4
Comments
Annnaa at 7-Dec-12 10:35am
   
what assembly reference should i add?
BC @ CV at 7-Dec-12 11:12am
   
Assembly reference is irrelevant. The above CSS will add the picture to the background of any Input element, which is the HTML element output by the ASP Button object. You could and probably should use a class name to reference it instead though. I will update the solution so its more clear what you should do.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Button btn = new Button();
btn.Image = new Bitmap("btn.png");  // image
btn.Location = new System.Drawing.Point(120, 10);
btn.Name = "MyCustomBtn";
btn.Text = "I'm a Custom Button.";  // text
tabControl1.Controls.add(btn);  // add custom to tab control..
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 383
1 Richard Deeming 180
2 ChauhanAjay 176
3 Sergey Alexandrovich Kryukov 171
4 Yogesh Kumar Tyagi 165
0 Sergey Alexandrovich Kryukov 6,252
1 OriginalGriff 5,498
2 CPallini 2,473
3 Richard MacCutchan 1,627
4 Abhinav S 1,530


Advertise | Privacy | Mobile
Web01 | 2.8.140821.2 | Last Updated 7 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100