我希望这个图在.aspx页面的中心怎么办? [英] I want This Diagram In center in .aspx page how to do?

查看:66
本文介绍了我希望这个图在.aspx页面的中心怎么办?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





i在asp.net网络应用程序中开发了一个图表作为用户控件

这个图表我想在我的网页中使用应用程序在defalut.aspx页面中我希望这个图表在中心和这个图表代码我想指定一个特定的asp.net控件如何首先做中心位置?

以后如何分配给1个asp.net控制。?



我的用户控件(.ascx.cs)代码:

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:

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:

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;





和我的.aspx代码:







and my .aspx code:


<%@ 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>

推荐答案

您好,





您可以将align属性用于html中的任何控件:



就像你可以对齐
Hi,


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

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



或表格


or for table

<table align="center">.........</table>


试试这个中心html标签

Try this center html tag
<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>


这不是这样的模拟游戏乍一看似乎很有风格的功能。只是中心不能正常工作,因为它也会使它们成为内在的HTML。您需要仅以顶部元素为中心的样式,并根据其自己的样式保持其内部HTML对齐。



请查看我准备的完整样本:

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:
<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>





这只是给你一个想法。这里的关键是使用自动边距。现在,如果您将任何内部HTML放在此示例中显示的div中,它将保留自己的样式,包括布局。



请尝试查看。



-SA


这篇关于我希望这个图在.aspx页面的中心怎么办?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆