编程页ASP.net Web应用程序C#配售图片 [英] Placing images programatically on page ASP.net Web application c#

查看:120
本文介绍了编程页ASP.net Web应用程序C#配售图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何编程移动图像控制?在该网页上的asp.net web应用程序,我想以编程方式创建3个图像,并把它们与它们之间有一定距离;

How can I move an image control programatically ? in a asp.net web application on that page, I wish to create 3 images programatically and place them with some distance between them;

int punctX = 50;
            int punctY=50;

            for (int y = 0; y < 2; y++)
            {
                System.Web.UI.WebControls.Image image = new System.Web.UI.WebControls.Image();
                image.ID = "culoare" + y.ToString();

- 如何将图像页面上?
}

-- how to place image on page? }

推荐答案

这是更好,如果你可以使用某种类型的占位符到您的图像添加进去。在这里,在这个例子中我使用asp.net面板控制。在code你后面可以设置相应属性的样式属性。

It's better if you can use some kind of a place holder to add your images into. Here in this example I am using a asp.net panel control. In the code behind you can set the style property with the corresponding attributes.

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
    CodeBehind="Default.aspx.cs" Inherits="StackOverFlow_2._Default" %>

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    <asp:Panel ID="pnlImages" runat="server"></asp:Panel>
</asp:Content>

只要你有这样的图像

Provided you have images like this

您可以做这样的事情(不是可能是最干净的code,但你的想法)

You can do something like this (not may be the cleanest code; but you get the idea)

using System;
using System.Web.UI;

namespace StackOverFlow_2
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                double punctX = 10;
                double punctY = 10;

                double spacing = 5;

                pnlImages.Style["position"] = "relative";

                for (int y = 0; y < 3; y++)
                {
                    System.Web.UI.WebControls.Image image = new System.Web.UI.WebControls.Image();
                    image.ID = "culoare" + y.ToString();
                    image.Style["position"] = "absolute";
                    image.Style["left"] = punctX.ToString() + "px";
                    image.Style["top"] = punctY.ToString() + "px";
                    image.Width = 100;
                    image.Height = 60;
                    image.ImageUrl = "~/Images/" + image.ID.ToString() + ".jpg";

                    pnlImages.Controls.Add(image);                    

                    punctX += image.Width.Value + spacing;

                }
            }
        }
    }
}

渲染输出看起来像这样(你的图像放置5像素除外)

Rendered output looks like this (your images are placed 5px apart)

这篇关于编程页ASP.net Web应用程序C#配售图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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