?
Solved

Help with the logos in c#

Posted on 2007-08-01
10
Medium Priority
?
337 Views
Last Modified: 2013-12-17
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
Comment
Question by:eddyinperu
  • 4
  • 3
7 Comments
 
LVL 21

Expert Comment

by:Yurich
ID: 19613204
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
 

Author Comment

by:eddyinperu
ID: 19616812
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
 
LVL 21

Expert Comment

by:Yurich
ID: 19620237
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
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 

Author Comment

by:eddyinperu
ID: 19653949
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
 
LVL 21

Accepted Solution

by:
Yurich earned 2000 total points
ID: 19657486
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
 

Author Comment

by:eddyinperu
ID: 19753867
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
 
LVL 21

Expert Comment

by:Yurich
ID: 19923088
well, my solution is 100% working... just copy-paste - can't go wrong with it.

Regards,
Yurich
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Integration Management Part 2
Suggested Courses

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question