• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 339
  • Last Modified:

Help with the logos in c#

Hi Experts:
I have different logos(.gif) in my database and a respective logo will appear in the web page depending who has log in. It could be a person or company(each one has its own logo). The logo appears in the right section of the page and it has been called from the database. Also, I create a dynamic cell which will have the logo in, but...
Problem: The logos in my database have different sizes. How can I make the cell to read only one size and apply this properties to all the logos, so the next time that the Logo  appear it will be center in the cell and with the width and height of the cell. I am using c#.  Tutorials or examples will be great...
Thanks
0
eddyinperu
Asked:
eddyinperu
  • 4
  • 3
1 Solution
 
YurichCommented:
Hello,
The easiest will be just seting the width property of your image control (which you should be using for displaying images) in design time to some fixed value (like 100) and you don't need to do anything else - all images will be resized automatically to fit this width.

If you want to do it dynamically, you can set it in Page_Load or Page_PreInit methods, e.g.:

Image1.Width = 100;

That should take care of it if I got correct what you want ;)
Cheers,
Yurich

0
 
eddyinperuAuthor Commented:
I tried but it doesn't work: This is swhat is going on:
private HtmlTable GenerateLogoAndBanner()
{
      HtmlTable table = new HtmlTable();
      HtmlTableRow row;
      table.CellPadding = 0;
      table.CellSpacing = 0;
      table.Width = "100%";
      table.Border = 0;
      table.BgColor = "#015294";
      row = new HtmlTableRow();
      row.Cells.Add(GenerateLogoCell());
      row.Cells.Add(GenerateSpacerCell("#ffffff", 5));
      row.Cells.Add(GenerateBannerCell());
      table.Rows.Add(row);
return table;
}

Here is calling and setting up my Logo coming from my database  This is the one that I need to change I tried the img.width =100% but doesn't work; It take almost all the row place:
private HtmlTableCell GenerateLogoCell()
{
      HtmlTableCell cell = new HtmlTableCell();
      HtmlImage img = new HtmlImage();

      cell.Width = "180";
      cell.BgColor = "red";
              return cell;
}

This one is the other cell which is next to the logo cell:
private HtmlTableCell GenerateSpacerCell(string color, int w)
{
      HtmlTableCell cell = new HtmlTableCell();
      HtmlImage img  = new HtmlImage();
      cell.BgColor = color;
      cell.Width = w.ToString();
      img.Src = iEnrollWeb.Utilities.ApplicationPath + "/images/dc.gif";
      img.Border = 0;
      img.Width = 2;

      cell.Controls.Add(img);
              return cell;
}

THe last cell next to the Spacer cell:
private HtmlTableCell GenerateBannerCell()
{
                  HtmlTableCell cell = new HtmlTableCell();
                 HtmlImage img = new HtmlImage();
      cell.BgColor = "#ffffff";
      cell.Width = "575px";
      cell.Height = "85px";
      cell.VAlign = "middle";
      cell.Attributes.Add("style","background-image: url(" + iEnrollWeb.Utilities.ApplicationPath    
                                                        + "/images/newBanner.gif); background-repeat: no-repeat;");
      string employerName = "--";
      StringBuilder banner = new StringBuilder();
      banner.Append("<table cellpadding=\"0\" cellspacing=\"0\" width=\"97%\" border=\"0\">");
                  banner.Append("  <tr>");
                  banner.Append("      <td align=\"right\">");
                  banner.Append("      <span valign=\"top\"
                                                                                             class=\"head1Banner\">{0}</span>");
                  baner.Append("            </td>");
                  baner.Append("      </tr>");
                  baner.Append("      <tr>");
                  baner.Append("            <td align=\"right\">");
                  baner.Append("            <span
                                                                                                           class=\"head2Banner\">{1}</span>");
                  baner.Append("            </td>");
                  baner.Append("      </tr>");
                  baner.Append("</table>");
      return cell;
}

3 Different cells in one rowll but like I said I tried the .width =100% and it doesn't want to work. I only want to change the cell that contain the logo so it can have a standard size foreverrr.
Thanks
0
 
YurichCommented:
well, there is some difference between 100% and 100 px. 100 % means an actual size and if your logo is 640 x 480, it will be shown like that. If, on the other hand, you set the width of your image to 100 px, then your image regardless of the size will be adjusted to fit the image control. So, your code should be:
...
HtmlImage img  = new HtmlImage();
img.Width = 100;
...
I don't see in your code where you're adding this image to your cell.Controls collection. Neither I can see anywhere that you're setting the source for your logo, but that might be just omitted.

Cheers,
Yurich
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
eddyinperuAuthor Commented:
Thanks but Still doesn't want to work., sorry that I took a litte bit time to answer but I had an accident with my motorcycle..Ia m okey...
Thanks
Eddy
0
 
YurichCommented:
Hope you OK.

Here a complete example of implementing of what you what. There're two parts, aspx page and the source (cs) code. You can copy-paste them "as is" in any new web project (.NET 2.0):

========= aspx ===============

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="ResizingImages.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
            <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /></div>
    </form>
</body>
</html>

============== source code ================

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
            HtmlTable table = new HtmlTable();
            HtmlTableRow row = new HtmlTableRow();

            HtmlTableCell cell = new HtmlTableCell();
            cell.InnerText = "This picture is originally 276 x 110 pixels, but will make it 100 pixels wide";
            row.Cells.Add( cell );

            cell = new HtmlTableCell();
            HtmlImage image = new HtmlImage();
            image.Src = @"http://images.google.co.nz/intl/en_ALL/images/images_hp.gif";
            image.Width = 100;      // that's the line of the code that controls the width
            cell.Controls.Add( image );            
            row.Cells.Add( cell );

            table.Rows.Add( row );
            this.Controls.Add( table );
    }
      protected void Button1_Click( object sender, EventArgs e )
      {
            // this button does nothing, just posts back - that's too see that we have your small
            // image on every post back
      }
}

Good luck,
I don't think I can do more than that :)
Yurich
0
 
eddyinperuAuthor Commented:
Well it didn't work!!!!.grrrrrrrrrrrrrrr. I just don't knwo what I am doing wrong but I need to leave this question in stand by  'cause I need to finish another project.
Would you mind to help me with this one. Sorry for taking your time. I promise that we will come back for this question later on!! But the othe question is Urgent and I haven't receive any postback from that question..(a little difficult).Please help Yurich!!
This is the URL:
http://www.experts-exchange.com/Programming/Languages/C_Sharp/Q_22776453.html

I appreciate your time, patience and your understanding!!!..Thanks one more time!!
0
 
YurichCommented:
well, my solution is 100% working... just copy-paste - can't go wrong with it.

Regards,
Yurich
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now