第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

文本創(chuàng)建圖片,ASPX向ASCX傳值

標(biāo)簽:
JavaScript

网页ASPX有一个TextBox,另一个ASCX有一个ImageButton,用户点一点这个铵钮,把用户在TextBox输入的文字创建为一个图片,ASCX的ImageButton的ImageUrl重新指向这刚产生的图片。

 

为了传值,写一个接口,返回aspx的TextBox函数:

Itransmitable

using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI.WebControls;/// <summary>/// Summary description for Itransmitable/// </summary>namespace Insus.NET{    public interface Itransmitable    {        TextBox GetTextBoxControl();    }}


A.asp.cs,并实现接口。

A.aspx.cs

using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.HtmlControls;using System.Web.UI.WebControls;using Insus.NET;public partial class A : System.Web.UI.Page,Itransmitable {    protected void Page_Load(object sender, EventArgs e)    {            }    public TextBox GetTextBoxControl()    {        return this.tbHid;    }}


A.aspx,把用户控件B.ascx接入页面。

A.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="A.aspx.cs" Inherits="A" %><%@ Register class="lazyload" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB/AAffA0nNPuCLAAAAAElFTkSuQmCC" data-original="B.ascx" tagname="B" tagprefix="uc1" %><!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server">    <title></title></head><body>    <form id="form1" runat="server">        <div>            <asp:TextBox ID="tbHid" runat="server" />                       <uc1:B ID="B1" runat="server" />                   </div>    </form></body></html>


B.ascx:

View Code

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="B.ascx.cs" Inherits="B" %> <asp:ImageButton runat="server" ID="imgBmp" OnClick="imgBmp_Click" BorderWidth="1" />


B.ascx.cs:

B.ascx.cs

using System;using System.Collections.Generic;using System.Drawing;using System.Drawing.Drawing2D;using System.Drawing.Imaging;using System.Drawing.Text;using System.IO;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using Insus.NET;public partial class B : System.Web.UI.UserControl{       protected void Page_Load(object sender, EventArgs e)    {        this.imgBmp.ImageUrl = GetImagePath("Insus.NET");  //默认值。    }    protected void imgBmp_Click(object sender, ImageClickEventArgs e)    {       Itransmitable textbox = (Itransmitable)this.Page; //把page转换为接口。       this.imgBmp.ImageUrl = GetImagePath(textbox.GetTextBoxControl().Text.Trim());    }    //创建图片    private string GetImagePath(string _text)    {        Bitmap bitmap = new Bitmap(1, 1);        Font font = new Font("Arial", 25, FontStyle.Regular, GraphicsUnit.Pixel);        Graphics graphics = Graphics.FromImage(bitmap);        int width = (int)graphics.MeasureString(_text, font).Width;        int height = (int)graphics.MeasureString(_text, font).Height;        bitmap = new Bitmap(bitmap, new Size(width, height));        graphics = Graphics.FromImage(bitmap);        graphics.Clear(Color.White);        graphics.SmoothingMode = SmoothingMode.AntiAlias;        graphics.TextRenderingHint = TextRenderingHint.AntiAlias;        graphics.DrawString(_text, font, new SolidBrush(Color.FromArgb(0, 0, 0)), 0, 0);        graphics.Flush();        graphics.Dispose();        string fileName = Path.GetFileNameWithoutExtension(Path.GetRandomFileName()) + ".jpg";        bitmap.Save(Server.MapPath("~/ImageLib/") + fileName, ImageFormat.Jpeg);        return "~/ImageLib/" + fileName;    }}


运行效果:

 

 

Demo code download(.NET 4.5) :
http://download.cnblogs.com/insus/ASPDOTNET/aspx2ascx.rar

 

點(diǎn)擊查看更多內(nèi)容
TA 點(diǎn)贊

若覺(jué)得本文不錯(cuò),就分享一下吧!

評(píng)論

作者其他優(yōu)質(zhì)文章

正在加載中
  • 推薦
  • 評(píng)論
  • 收藏
  • 共同學(xué)習(xí),寫(xiě)下你的評(píng)論
感謝您的支持,我會(huì)繼續(xù)努力的~
掃碼打賞,你說(shuō)多少就多少
贊賞金額會(huì)直接到老師賬戶(hù)
支付方式
打開(kāi)微信掃一掃,即可進(jìn)行掃碼打賞哦
今天注冊(cè)有機(jī)會(huì)得

100積分直接送

付費(fèi)專(zhuān)欄免費(fèi)學(xué)

大額優(yōu)惠券免費(fèi)領(lǐng)

立即參與 放棄機(jī)會(huì)
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)

舉報(bào)

0/150
提交
取消