校园春色亚洲色图_亚洲视频分类_中文字幕精品一区二区精品_麻豆一区区三区四区产品精品蜜桃

主頁(yè) > 知識(shí)庫(kù) > ASPX向ASCX傳值以及文本創(chuàng)建圖片(附源碼)

ASPX向ASCX傳值以及文本創(chuàng)建圖片(附源碼)

熱門(mén)標(biāo)簽:怎樣在地圖標(biāo)注消火栓圖形 廈門(mén)四川外呼系統(tǒng) 內(nèi)蒙古智能電銷機(jī)器人哪家強(qiáng) 泰州手機(jī)外呼系統(tǒng)軟件 山東防封電銷卡辦理套餐 地圖標(biāo)注位置多的錢 濟(jì)源人工智能電話機(jī)器人價(jià)格 杭州智能電話機(jī)器人 百度地圖標(biāo)注點(diǎn)擊事件
網(wǎng)頁(yè)ASPX有一個(gè)TextBox,另一個(gè)ASCX有一個(gè)ImageButton,用戶點(diǎn)一點(diǎn)這個(gè)銨鈕,把用戶在TextBox輸入的文字創(chuàng)建為一個(gè)圖片,ASCX的ImageButton的ImageUrl重新指向這剛產(chǎn)生的圖片。

為了傳值,寫(xiě)一個(gè)接口,返回aspx的TextBox函數(shù):
復(fù)制代碼 代碼如下:

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.aspx.cs,并實(shí)現(xiàn)接口。
復(fù)制代碼 代碼如下:

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接入頁(yè)面。
復(fù)制代碼 代碼如下:

%@ Page Language="C#" AutoEventWireup="true" CodeFile="A.aspx.cs" Inherits="A" %>
%@ Register src="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:
復(fù)制代碼 代碼如下:

%@ 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:
復(fù)制代碼 代碼如下:

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"); //默認(rèn)值。
}
protected void imgBmp_Click(object sender, ImageClickEventArgs e)
{
Itransmitable textbox = (Itransmitable)this.Page; //把page轉(zhuǎn)換為接口。
this.imgBmp.ImageUrl = GetImagePath(textbox.GetTextBoxControl().Text.Trim());
}
//創(chuàng)建圖片
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;
}
}

運(yùn)行效果:
 
Demo code download(.NET 4.5)
您可能感興趣的文章:
  • JQuery為用戶控件(ASCX)賦值與接口的應(yīng)用
  • asp.net頁(yè)面master頁(yè)面與ascx用戶控件傳值的問(wèn)題
  • js獲取.aspx頁(yè)面里面的服務(wù)器控件和.ascx中的服務(wù)器控件值

標(biāo)簽:喀什 百色 臺(tái)州 朝陽(yáng) 周口 新鄉(xiāng) 朔州 洛陽(yáng)

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《ASPX向ASCX傳值以及文本創(chuàng)建圖片(附源碼)》,本文關(guān)鍵詞  ASPX,向,ASCX,傳值,以及,文本,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《ASPX向ASCX傳值以及文本創(chuàng)建圖片(附源碼)》相關(guān)的同類信息!
  • 本頁(yè)收集關(guān)于ASPX向ASCX傳值以及文本創(chuàng)建圖片(附源碼)的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    主站蜘蛛池模板: 泾源县| 互助| 奉化市| 黄浦区| 永清县| 阜南县| 吴忠市| 台北县| 达州市| 金川县| 富锦市| 新巴尔虎左旗| 水富县| 新田县| 乌苏市| 保山市| 改则县| 德阳市| 安新县| 遂宁市| 澄江县| 揭东县| 罗城| 平遥县| 化德县| 普兰店市| 寿阳县| 九龙城区| 汽车| 宝清县| 和林格尔县| 宿迁市| 孙吴县| 德阳市| 香港| 水城县| 天气| 乌兰浩特市| 辉县市| 乌鲁木齐县| 浦县|