仓酷云

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 666|回复: 7
打印 上一主题 下一主题

[学习教程] ASP.NET网页编程之Asp.net2.0之自界说控件ImageButton

[复制链接]
飘灵儿 该用户已被删除
跳转到指定楼层
楼主
发表于 2015-1-16 22:23:38 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
c++是语言,其实C++和java的应用范围根本就不一样的。在java应用的领域内,c++是不合适的。所以微软才搞了C#和Java对抗。上个礼拜三入手下手学自界说控件,做了很多实习。花了一上中午间写了一个imageButton,之前就像写这个控件,只是不会。图片

注释
这个控件仿照winform中的button,能够撑持图片和笔墨。能够选择实行服务器端程序仍是客户端程序,另有一些复杂的设置。
不敷的是不撑持款式,下次但愿能够写一个工具条。
以下就是代码
以下为援用的内容:
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Web.UI.WebControls;
usingSystem.ComponentModel;
usingSystem.Web.UI;
usingSystem.Drawing.Design;
usingSystem.Drawing.Drawing2D;
namespaceClassLibrary1
{
[Serializable]
publicclassPicture
{

privateUnitheight=16;

privatestringsrc=string.Empty;
[NotifyParentProperty(true)]
[Browsable(true),Bindable(true),Description("图片路径"),Category("Appearance")]
[Editor("System.Web.UI.Design.ImageUrlEditor,System.Design,Version=2.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a",typeof(UITypeEditor))]
publicstringSrc
{
get{returnthis.src;}
set{this.src=value;}
}
[DefaultValue(typeof(Unit),"16px")]
[NotifyParentProperty(true)]
publicUnitHeight
{
get{returnheight;}
set{height=value;}
}
privateUnitwidth=16;
[NotifyParentProperty(true)]
[DefaultValue(typeof(Unit),"16px")]
publicUnitWidth
{
get{returnwidth;}
set{width=value;}
}

publicenumAlign{Left,Right}

}
[Serializable]
publicclassLabel
{


privatestringtext=string.Empty;
[NotifyParentProperty(true)]
publicstringText
{
get{returntext;}
set{text=value;}
}
privateSystem.Drawing.FontfontFamily=newSystem.Drawing.Font("宋体",8);


[NotifyParentProperty(true)]
publicSystem.Drawing.FontFont
{
get{returnthis.fontFamily;}
set{this.fontFamily=value;}
}

}
[PersistChildren(false)]
[ParseChildren(true)]
publicclassImageButton:Control,INamingContainer,IPostBackEventHandler
{
publicenumRaiseEventType{Client,Server}
privatePicturepic=newPicture();
privatePicture.AlignpicAlign=Picture.Align.Left;
privateLabellabel=newLabel();
privatestringjsFunction=string.Empty;
privatestaticreadonlyobjectclickKey=newobject();
publicenumTextAlign{Left,Center,Right}
[Browsable(true),Bindable(true),Description("javascript办法"),Category("Action")]
publicstringJSFunction
{
get{returnthis.jsFunction;}
set{this.jsFunction=value;}
}

privateRaiseEventTyperaiseEvent=RaiseEventType.Server;
[Browsable(true),Bindable(true),Description("呼应事务体例"),Category("Action")]
publicRaiseEventTypeRaiseEvent
{
get{returnthis.raiseEvent;}
set{this.raiseEvent=value;}
}


privateTextAlignalign=TextAlign.Left;
[Browsable(true),Bindable(true),Description("笔墨的对齐体例"),Category("Appearance")]
publicTextAlignALign
{
get{returnalign;}
set{align=value;}

}
privateUnitwidth=80;
[Browsable(true),Bindable(true),Description("控件宽度"),Category("Appearance")]
[DefaultValue(typeof(Unit),"80px")]
publicUnitWidth
{
get{returnthis.width;}
set{this.width=value;}
}


[Browsable(true),Bindable(true),Category("Action")]
publiceventEventHandlerOnClick
{
add
{
Events.AddHandler(clickKey,value);
}
remove
{
Events.RemoveHandler(clickKey,value);
}
}
[Browsable(true),Bindable(true),Description("图片类"),Category("Appearance")]
publicPicture.AlignPicAlign
{
get{returnpicAlign;}
set{picAlign=value;}
}

[Browsable(true),Bindable(true),Description("图片类"),Category("Appearance")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[TypeConverter(typeof(ExpandableObjectConverter))]
[PersistenceMode(PersistenceMode.InnerProperty)]
publicPicturePic
{
get{returnpic;}

}
[Browsable(true),Bindable(true),Description("笔墨类"),Category("Appearance")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[TypeConverter(typeof(ExpandableObjectConverter))]
[PersistenceMode(PersistenceMode.InnerProperty)]
publicLabelLabel
{
get{returnlabel;}

}
protectedoverridevoidRender(HtmlTextWriterwriter)
{
if(raiseEvent==RaiseEventType.Server)
{
writer.AddAttribute(HtmlTextWriterAttribute.Onclick,Page.GetPostBackEventReference(this,this.ClientID));
}
else
{
writer.AddAttribute(HtmlTextWriterAttribute.Onclick,"javascript:"+this.jsFunction);
}

writer.AddStyleAttribute(HtmlTextWriterStyle.Cursor,"hand");
writer.AddStyleAttribute(HtmlTextWriterStyle.Width,this.width.Value.ToString()+"px");
if(align==TextAlign.Left)
{
writer.AddStyleAttribute(HtmlTextWriterStyle.TextAlign,"left");
}
elseif(align==TextAlign.Center)
{
writer.AddStyleAttribute(HtmlTextWriterStyle.TextAlign,"center");
}
else
{
writer.AddStyleAttribute(HtmlTextWriterStyle.TextAlign,"right");
}

writer.RenderBeginTag(HtmlTextWriterTag.Div);


if(PicAlign==Picture.Align.Left)
{
AddPic(writer);
AddLabel(writer);
}
else
{AddLabel(writer);
AddPic(writer);

}
writer.RenderEndTag();
//base.Render(writer);
}
privatevoidAddPic(HtmlTextWriterwriter)
{

writer.AddAttribute(HtmlTextWriterAttribute.Src,base.ResolveClientUrl(pic.Src));
writer.AddAttribute(HtmlTextWriterAttribute.Height,pic.Height.ToString());
writer.AddAttribute(HtmlTextWriterAttribute.Width,pic.Width.ToString());

writer.RenderBeginTag(HtmlTextWriterTag.Img);
writer.RenderEndTag();
//writer.Write("<imagesrc="+this.Src+"height="+pic.Height+"width="+pic.Width+"/>");
}
privatevoidAddLabel(HtmlTextWriterwriter)
{
writer.AddStyleAttribute(HtmlTextWriterStyle.VerticalAlign,"middle");
writer.AddStyleAttribute(HtmlTextWriterStyle.FontSize,label.Font.Size.ToString()+"pt");
writer.AddStyleAttribute(HtmlTextWriterStyle.FontFamily,label.Font.FontFamily.Name);
if(label.Font.Bold)
{

writer.AddStyleAttribute(HtmlTextWriterStyle.FontWeight,"Bold");
}
writer.RenderBeginTag(HtmlTextWriterTag.Label);

writer.Write(label.Text==string.Empty?this.ClientID.ToString():label.Text);
writer.RenderEndTag();
//writer.Write("<label>"+Label.Text+"</label>");
}


#regionIPostBackEventHandler成员

publicvoidRaisePostBackEvent(stringeventArgument)
{
EventHandlere=(EventHandler)Events[clickKey];
if(e!=null)
{
e(this,EventArgs.Empty);
}
}

#endregion

究竟是刚学,一定会有良多不敷和毛病,但愿人人斧正,感谢。
开头,持续勉力,看完别的的材料。
以前学了大概半年时间的asp(没有机会做大系统,最多是自己对公司系统做些调整和修改还有一些小程序)。应该说开始接触asp.net是今年元月5号的事。现在很想把公司的系统重新用.net来架构,却不知道如何下手。
若相依 该用户已被删除
沙发
发表于 2015-1-19 10:24:36 | 只看该作者
在asp.net虚拟主机的服务提供商中,目前首推的是CNNIC的其中一家域名注册机构---时代互联(www.ckuyun.com),他们早在2001年微软刚推出Asp.net时就推出了对应的Asp.net虚拟主机了,经笔者的使用测试,他提供的Asp.net性能非常的稳定,版本也会定期的更新,目前他的
板凳
发表于 2015-1-26 22:33:40 | 只看该作者
ASP.NET可以无缝地与WYSIWYGHTML编辑器和其他编程工具(包括MicrosoftVisualStudio.NET)一起工作。这不仅使得Web开发更加方便,而且还能提供这些工具必须提供的所有优点,包括开发人员可以用来将服务器控件拖放到Web页的GUI和完全集成的调试支持。微软为ASP.net设计了这样一些策略:易于写出结构清晰的代码、代码易于重用和共享、可用编译类语言编写等等,目的是让程序员更容易开发出Web应用,满足计算向Web转移的战略需要。
老尸 该用户已被删除
地板
发表于 2015-2-4 22:18:21 | 只看该作者
在一个项目中谁敢保证每天几千万甚至几亿条的数据不丢失?谁敢保证应用的高可靠性?有可以借签的项目吗?
蒙在股里 该用户已被删除
5#
发表于 2015-2-10 21:55:05 | 只看该作者
ASP.net1.1和2.0在程序上的语法也有很大不同,现在2.0属于新出来的,不知道半年后会不会有3.0(说笑一下)。Windows2003系统自动支持ASP和ASP.net环境,不用安装任何程序。Asp.net属于编译语言。ASP的最大不同(ASP属于解释语言)。
小女巫 该用户已被删除
6#
发表于 2015-3-1 16:12:19 | 只看该作者
能产生和执行动态、交互式、高效率的站占服务器的应用程序。运用ASP可将VBscript、javascript等脚本语言嵌入到HTML中,便可快速完成网站的应用程序,无需编译,可在服务器端直接执行。容易编写。
兰色精灵 该用户已被删除
7#
发表于 2015-3-10 20:45:27 | 只看该作者
在asp.net虚拟主机的服务提供商中,目前首推的是CNNIC的其中一家域名注册机构---时代互联(www.now.net.cn),他们早在2001年微软刚推出Asp.net时就推出了对应的Asp.net虚拟主机了,经笔者的使用测试,他提供的Asp.net性能非常的稳定,版本也会定期的更新,目前他的
柔情似水 该用户已被删除
8#
发表于 2015-3-24 07:24:14 | 只看该作者
业务逻辑代码都不必做任何改动;继承性和多态性使得代码的可重用性大大提高,你可以通过继承已有的对象最大限度保护你以前的投资。并且C#和C++、Java一样提供了完善的调试/纠错体系。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|仓酷云 鄂ICP备14007578号-2

GMT+8, 2024-9-24 00:19

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表