惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

宝玉的分享
宝玉的分享
NISL@THU
NISL@THU
E
Exploit-DB.com RSS Feed
L
LINUX DO - 热门话题
L
Lohrmann on Cybersecurity
K
Kaspersky official blog
Project Zero
Project Zero
Cisco Talos Blog
Cisco Talos Blog
T
The Exploit Database - CXSecurity.com
P
Palo Alto Networks Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
T
Threatpost
S
Schneier on Security
G
GRAHAM CLULEY
The Hacker News
The Hacker News
T
Threat Research - Cisco Blogs
Scott Helme
Scott Helme
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
P
Privacy & Cybersecurity Law Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
Cyberwarzone
Cyberwarzone
C
CERT Recently Published Vulnerability Notes
T
Tor Project blog
AWS News Blog
AWS News Blog
Simon Willison's Weblog
Simon Willison's Weblog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
爱范儿
爱范儿
P
Privacy International News Feed
云风的 BLOG
云风的 BLOG
P
Proofpoint News Feed
S
Securelist
G
Google Developers Blog
The Last Watchdog
The Last Watchdog
Google Online Security Blog
Google Online Security Blog
美团技术团队
F
Fortinet All Blogs
小众软件
小众软件
Recorded Future
Recorded Future
V
Visual Studio Blog
B
Blog RSS Feed
H
Help Net Security
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Google DeepMind News
Google DeepMind News
Blog — PlanetScale
Blog — PlanetScale
博客园 - 聂微东
Stack Overflow Blog
Stack Overflow Blog
Martin Fowler
Martin Fowler
Latest news
Latest news
Spread Privacy
Spread Privacy
H
Heimdal Security Blog

博客园 - TangHuawei

設置RichTextBox行距 - TangHuawei - 博客园 新的一年又开始了 C#纯数学方法递归实现货币数字转换中文 移动没有标题栏的窗口 - TangHuawei - 博客园 让程序更智能-自动选择功能的实现 - TangHuawei - 博客园 让复选框生动起来 用VB实现局域网屏幕监视 如何在VB6中实现文字“打屏”及霓虹灯效果 - TangHuawei - 博客园 用VB“破解”有时间限制的程序 用VB5 Winsock控件创建TCPIP客户机 服务器程序 用VB产生随机密码 用vb开发通信软件 用VB设计基于代理服务器的网络计费系统 用VB设计能适应各种显示属性的界面 用VB设计软件封面 用VB实现彩蝶飞舞 游动的窗体 有历史记录功能的菜单 远程共享显示及声音的实现
C#.NET windows控件实现水印
TangHuawei · 2007-01-12 · via 博客园 - TangHuawei

 

Windows控件在Web下的引用,首先我们建立一个window控件,项目名称为EditImagePint,然后,

C#.NET windows控件实现水印(图一)

我们把项目下的UserControl1.cs改为ImagePint.cs,切记文件名和构造函数都改!

先制作界面,首先在设计模式下,我们将一个PictureBox拖放到解面上,命名为pictureBox1

C#.NET windows控件实现水印(图二)

C#.NET windows控件实现水印(图三)

下面我们转入代码页,也就是ImagePint.cs

我们需要引用的对象有:
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using System.IO;
using System.Net;

然后我们写一个函数

private void ImagePint_Load(object sender, System.EventArgs e)
{
/*具体代码我们下面介绍*/
}

这个函数,是为了在web页面使用时候加载使用的.

然后我们看控件自己的生成代码,把
this.Load += new System.EventHandler(this.ImagePint_Load);
加如InitializeComponent()中
#region 组件设计器生成的代码:

///
/// 设计器支持所需的方法 - 不要使用代码编辑器
/// 修改此方法的内容。
///
private void InitializeComponent()
{
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.SuspendLayout();
//
// pictureBox1
//
this.pictureBox1.Location = new System.Drawing.Point(0, 0);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.TabIndex = 0;
this.pictureBox1.TabStop = false;
//
// ImagePint
//
this.Controls.Add(this.pictureBox1);
this.Name = "ImagePint";
//看到了吗?很明显,先面的是我们加上去的
this.Load += new System.EventHandler(this.ImagePint_Load);
this.ResumeLayout(false);

}
#endregion

有了这些东西,组件就可以在web下使用了,但是既然是水印,就应该有原始图片,和水印图片,及一些其他的参数,这里我们就用公共函数,至于web怎么把值传进去,我们到下面再说

#region 公共属性

//显示宽度
public int ImgWidht
{
get {return _ImgWidth;}
set {_ImgWidth = value;}
}

//显示高度
public int ImgHeight
{
get {return _ImgHeight;}
set {_ImgHeight = value;}
}

//透明度
private int Alpha
{
get {return _Alpha;}
set {_Alpha = value;}
}

//主图片地址
public string ZPicture
{
get {return _ZPicture;}
set {_ZPicture = value;}
}

//水印图片地址
public string FPicture
{
get {return _FPicture;}
set {_FPicture = value;}
}

#endregion

下面把完整的代码贡献给大家:

代码拷贝框

[Ctrl+A 全部选择 然后拷贝]

然后我们把这个控件生成一个Release版本,然后把生成的dll文件copy到你的虚拟目录下,然后就是web调用了,我们先建立一个虚拟目录,比如说我们建立的虚拟目录及地址为:
localhost/Object/ImagePrint/
我们就把生成的 EditImagePint.dll 文件copy到这个目录下
并建立一个html文件,把以下的代码放进去:

<object id="print" classid="http://localhost/Object/ImagePrint/
EditImagePint.dll#EditImagePint.ImagePint"
Width="177" Height="144" VIEWASTEXT >
<param name="ImgWidht" value="177">
<param name="ImgHeight" value="144">
<param name="Alpha" value="40">
<param name="ZPicture" value="http://localhost/Object/ImagePrint/my.jpg">
<param name="FPicture" value="http://localhost/Object/ImagePrint/make.jpg">
</object>

看到了把,这些param就是我们的公共属性了:),这样就把值传递进去了

最终显示如下:

C#.NET windows控件实现水印(图四)

转自图中的那位帅哥!