Click here to Skip to main content
15,901,666 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi

i developed one diagram as a user control in asp.net web application
this diagram i want to use in my web app in defalut.aspx page i want this diagram in center and this diagram code i want to assign one particular asp.net control how to do center position first?
later how to assign to 1 asp.net control.?

my user control(.ascx.cs) code:
C#
protected void Page_Load(object sender, EventArgs e)
{
    if (IsPostBack)
    {
        Bitmap objBitmap;
        Graphics objGraphics;

        objBitmap = new Bitmap(1000, 1000);
        objGraphics = Graphics.FromImage(objBitmap);

        objGraphics.Clear(Color.White);

        Pen p = new Pen(Color.Red, 0);
        Rectangle rect = new Rectangle(10, 10, 280, 280);
        objGraphics.DrawRectangle(p, rect);
        objGraphics.DrawEllipse(p, rect);
        objGraphics.DrawLine(p, 500, 60, 480, 60);

        Brush b1 = new SolidBrush(Color.Red);
        Brush b2 = new SolidBrush(Color.Green);
        Brush b3 = new SolidBrush(Color.Blue);
        objGraphics.FillPie(b1, rect, 0f, 60f);
        //objGraphics.FillPie(b2, rect, 60f, 150f);
        //objGraphics.FillPie(b3, rect, 210f, 150f);

        FontFamily fontfml = new FontFamily(GenericFontFamilies.Serif);
        Font font = new Font(fontfml, 16);
        SolidBrush brush = new SolidBrush(Color.Blue);
        objGraphics.DrawString("Drawing Graphics", font, brush, 70, 300);
        //objGraphics.DrawImage(objBitmap, 300, 300, 400, 500);
        //objGraphics.ScaleTransform((float)0.714, (float)0.714);
        //objGraphics.DrawImage(objBitmap, 300, 300, 400, 500);

        objBitmap.Save(Response.OutputStream, ImageFormat.Gif);
        objBitmap.Save(Server.MapPath("x.jpg"), ImageFormat.Jpeg);

        objBitmap.Dispose();
        objGraphics.Dispose();
    }
}


Namespaces:
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Text;
using System.Drawing.Design;
using System.Web.UI.WebControls.Adapters;


and my .aspx code:


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

<%@ Register src="Graph.ascx" tagname="Graph" tagprefix="uc1" %>

<!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></title>
    <style type="text/css">
        .style1
        {
            width: 100%;
        }
        .style2
        {
            width: 964px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div align="Center">

        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
        <table align="Center">
            <tr>
                <td align="Center">
                    <asp:MultiView ID="MultiView1" runat="server">
                        <asp:View ID="View1" runat="server">
                            <uc1:Graph ID="Graph1" runat="server" />
                        </asp:View>
                    </asp:MultiView>
                </td>
                <td>
                    &nbsp;</td>
            </tr>
            <tr>
                <td class="style2">
                    &nbsp;</td>
                <td style="">
                    &nbsp;</td>
            </tr>
        </table>

    </div>
    </form>
</body>
</html>
Posted
Updated 31-May-13 0:34am
v4

Hi,


You can use the align property to any of the control in html :

like u can apply align to
HTML
<div align="Center"></div>

or for table
HTML
<table align="center">.........</table>
 
Share this answer
 
v2
Comments
MAKReddy 31-May-13 6:28am    
thanks but this is not working i tried a lot...
MAKReddy 31-May-13 6:28am    
can u give me any other answer plz can u try?
Rockstar_ 31-May-13 6:36am    
Give height and width also for table and then check..
MAKReddy 31-May-13 6:56am    
i tried but only width property is there no height property how to give height?
plz can u send me the code..
Try this center html tag
XML
<center>
 <table align="Center">
            <tr>
                <td align="Center">
                    <asp:MultiView ID="MultiView1" runat="server">
                        <asp:View ID="View1" runat="server">
                            <uc1:Graph ID="Graph1" runat="server" />
                        </asp:View>
                    </asp:MultiView>
                </td>
                <td>
                    &nbsp;</td>
            </tr>
            <tr>
                <td class="style2">
                    &nbsp;</td>
                <td style="">
                    &nbsp;</td>
            </tr>
        </table>
        </center>
 
Share this answer
 
Comments
MAKReddy 4-Jun-13 7:56am    
not working...
Pallavi Waikar 4-Jun-13 10:21am    
i think it is because of css.Refer solution 4 added using css hope it will help
This is not such a simple style feature as it may seem at first glance. Just "center" won't work properly, because it will also center they inner HTML. You need the style centering only the top element, and leave its inner HTML aligned according its own styles.

Please look at my complete sample I prepared:
XML
<html >
    <head>
        <title>???</title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <style type="text/css"><!--
            .center {
                margin-top:10px;
                margin-left:auto;
                margin-right:auto;
                text-align:center;
                border:solid 1px black;
                width:828px;
                height:20px;}
        --></style>
    </head>
<body>

<div class="center">It will work for any inner HTML you want to place here...</div>

</body>
</html>


It's just to give you the idea. The key here is using auto margins. Now, if you put any inner HTML inside the div shown in this sample, it will preserve its own styles, including layout.

Please try it to see.

—SA
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900