Jump to content

How to use image as button?


aic007

Recommended Posts

Hi all.I have a question regarding a button, which I have made in visual studio.knappcu8.jpgThe code is:Button button;Label lblSearch = new Label();txtSearch = new TextBox();button = new Button();button.Click += new EventHandler(button_Click);button.Text = "Søk";I have an image, named buttonImage, which I want to use instead of custom text. How can I accomplish that?Regards.

Link to comment
Share on other sites

  • 2 weeks later...

Thanks for the answer. I have another question, how can I decide the size of my fields in a gridview?To format the rows I use this code: this.gridView.RowStyle.CssClass="oddetallslinjer";but I don't know how to format the cells.. any ideas?

Link to comment
Share on other sites

Thanks for the answer. I have another question, how can I decide the size of my fields in a gridview?To format the rows I use this code: this.gridView.RowStyle.CssClass="oddetallslinjer";but I don't know how to format the cells.. any ideas?
If you want to change the size, for example, you can do as follows:this.gridview.RowStyle.Width = "100"this.gridview.RowStyle.Height = "200"(= size in pixels)or make a class in your stylesheet:.oddetallslinjer { background-color: Blue; }etc
Link to comment
Share on other sites

If you want to change the size, for example, you can do as follows:this.gridview.RowStyle.Width = "100"this.gridview.RowStyle.Height = "200"(= size in pixels)or make a class in your stylesheet:.oddetallslinjer { background-color: Blue; }etc
Hi Emiel.Thanks for answering.I get my fields like this:this.gridView.Columns.Add(GetColumn("Mobil nr, arbeid", null, "Mobil", true, true));From this code I will get "Mobil nr" displayed as the text of the field. Is there a way to specify the size of this field only?:-)
Link to comment
Share on other sites

Thanks. I'll look at it. :-)I have another question though. I used the ImageButton control to use a picture from css - file as a button, and it works, but I get a red cross on the button also in addition. The red cross looks like a red cross that you see when you are on a web site and can't see a picture.This is my code:ImageButton imgBtn;imgBtn = new ImageButton();imgBtn.Click += new ImageClickEventHandler(imgBtn_Click);imgBtn.CssClass = "SokKnappBilde";I suspect it has something to do with me not having defined any picture paths in this code, but do I need to do that?Is there a way to get rid of that red cross?This is how the button looks like. (see picture on the left)utennavnfk5.jpg

Link to comment
Share on other sites

Thanks. I'll look at it. :-)I have another question though. I used the ImageButton control to use a picture from css - file as a button, and it works, but I get a red cross on the button also in addition. The red cross looks like a red cross that you see when you are on a web site and can't see a picture.This is my code:ImageButton imgBtn;imgBtn = new ImageButton();imgBtn.Click += new ImageClickEventHandler(imgBtn_Click);imgBtn.CssClass = "SokKnappBilde";I suspect it has something to do with me not having defined any picture paths in this code, but do I need to do that?Is there a way to get rid of that red cross?This is how the button looks like. (see picture on the left)utennavnfk5.jpg
Yes try doing the same thing with a regular Button and ImageButton requires you to specify an image
Link to comment
Share on other sites

Hi.I have tried with a regular button, but it doesn't look good. utennavnuw3.jpgIt looks like an image attached on a button, but I want it to use image only as button. Any ideas how I can accheive that? This is my code:Button btn;btn = new Button();btn.Click += new EventHandler(btn_Click);btn.Text = "Søk";btn.CssClass = "SokKnappBilde";css:.SokKnappBilde{ float:left; margin:-22px 285px -3px 240px; background-image:url('../../../images/knapp-sok.PNG'); width:75px; height:20px;}:-)

Link to comment
Share on other sites

Hi again.I solved the problem by using ImageButton and then giving it an imageurl. imgBtn.CssClass = "SokKnappBilde";imgBtn.ImageUrl = "../../../knapp-sok.PNG";.SokKnappBilde{ float:left; margin:-24px 285px -3px 240px; width:75px; height:22px;}Thanks alot for giving me tips. Your assistance is most appreciated. I have another problem though, which I need to sort out. A problem regarding gridview.I get data from SQL, and need to decide the width of my columns, I want my cells to have static widht.This is my code:protected override void CreateChildControls(){try{this.gridView = new GridView();this.gridView.PageSize = 60;this.gridView.AllowSorting = true;this.gridView.AutoGenerateColumns = false;this.gridView.Sorting += new GridViewSortEventHandler(Grid_Sorting); this.gridView.PageIndexChanging += new GridViewPageEventHandler(gridView_PageIndexChanging);this.gridView.RowDataBound += new GridViewRowEventHandler(gridView_RowDataBound);/*Here I get my fields, and I want to change the width of theese fields*/this.gridView.Columns.Add(GetColumn("adresse", null, "Adresse", true, true));this.gridView.Columns.Add(GetColumn("telefon", null, "Tlf", true, true));//TableTable tbl = new Table();TableRow row1 = new TableRow();TableRow row2 = new TableRow();TableCell cell1 = new TableCell();TableCell cell2 = new TableCell();tbl.Controls.Add(row1);row1.Controls.Add(cell1);tbl.Controls.Add(row2);row2.Controls.Add(cell2);this.Controls.Add(tbl);}Any tips for me :-)Regards.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...