In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly shows you "ASPX how to send values to ASCX and text to create pictures", the content is easy to understand, well-organized, hope to help you solve your doubts, the following let Xiaobian lead you to study and learn "how to send values from ASPX to ASCX and text to create pictures" this article.
The web page ASPX has a TextBox, and another ASCX has an ImageButton. The user clicks this button to create an image of the text entered by the user in TextBox, and the ImageUrl of ASCX's ImageButton points back to the newly generated image.
To pass a value, write an interface and return the TextBox function of aspx:
The copy code is as follows:
Using System
Using System.Collections.Generic
Using System.Linq
Using System.Web
Using System.Web.UI.WebControls
/ / /
/ Summary description for Itransmitable
/ / /
Namespace Insus.NET
{
Public interface Itransmitable
{
TextBox GetTextBoxControl ()
}
}
A.aspx.cs and implement the interface.
The copy code is as follows:
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, connect the user control B.ascx to the page.
The copy code is as follows:
B.ascx:
The copy code is as follows:
B.ascx.cs:
The copy code is as follows:
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"); / / default.
}
Protected void imgBmp_Click (object sender, ImageClickEventArgs e)
{
Itransmitable textbox = (Itransmitable) this.Page; / / converts page to an interface.
This.imgBmp.ImageUrl = GetImagePath (textbox.GetTextBoxControl () .Text.Trim ())
}
/ / create a picture
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
}
}
Running effect:
The above is all the content of the article "how ASPX passes values to ASCX and text creates pictures". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.