Ⅰ asp.net自定义控件,
看看自定义控件的部署一章
方式一:共享位置
方式二:嵌入程序集,估计你是采用这种方式
如何使用方式二:
1. 需要源文件属性为嵌入资源
2.添加属性在AssemblyInfo.cs中
[assembly:WebResource("资源名称","MIME类型")]
3.重写OnPreRender,注册资源(就是生成页面中对资源引用,估计你的没有引用,所以才有脚本错误吧)
资源url用Page.ClientScript.GetWebResourceUrl方法取到
RegisterClientScriptResource
Ⅱ c# 自定义控件制作
看下资料吧:
自己开发的WinForm控件通常有三种类型:复合控件(Composite Controls),扩展控件(Extended Controls),自定义控件(Custom Controls)。
复合控件:将现有的各种控件组合起来,形成一个新的控件,将集中控件的功能集中起来。
扩展控件:在现有控件的控件的基础上派生出一个新的控件,为原有控件增加新的功能或者修改原有控件的控能。
自定义控件:直接从System.Windows.Forms.Control类派生出来。Control类提供控件所需要的所有基本功能,包括键盘和鼠标的事件处理。自定义控件是最灵活最强大的方法,但是对开发者的要求也比较高,你必须为Control类的OnPaint事件写代码,你也可以重写Control类的WndProc方法,处理更底层的Windows消息,所以你应该了解GDI+和Windows API。
本系列文章主要介绍自定义控件的开发方法。
控件(可视化的)的基本特征:
1. 可视化。
2. 可以与用户进行交互,比如通过键盘和鼠标。
3. 暴露出一组属性和方法供开发人员使用。
4. 暴露出一组事件供开发人员使用。
5. 控件属性的可持久化。
6. 可发布和可重用。
参考资料一:http://www.cnblogs.com/hackenliu/archive/2008/07/23/1249885.html
参考资料二:http://blog.csdn.net/songkexin/article/details/4961215
Ⅲ 为什么直接继承view来自定义控件时,需要重写onmeasure方法并设置wrap
描述View本身大小的多少!自定义View的时候重载onMeasure(),onLayout(),onDraw()三个函数构建了自定义View的外观形象。再加上onTouchEvent()等重载视图的行为,可以构建任何我们需要的可感知到的自定义View。我们知道,不管是自定义View还是系统提供的TextView这些,它们都必须放置在LinearLayout等一些ViewGroup中,因此理论上我们可以很好的理解onMeasure(),onLayout(),onDraw()这三个函数:1.View本身大小多少,这由onMeasure()决定;2.View在ViewGroup中的位置如何,这由onLayout()决定;3.绘制View,onDraw()定义了如何绘制这个View。
Ⅳ 如何开发finereport的自定义控件
1、实例化一个注册控件的接口
packagecom.hg.free.plugin.customcombo.param;
importcom.fr.design.designer.creator.XComboBox;
importcom.fr.design.fun.impl.;
importcom.fr.form.ui.Widget;
{
@Override
publicClass<?extendsWidget>classForWidget(){
returnCustomComboBox.class;
}
@Override
publicClass<?>appearanceForWidget(){
returnXComboBox.class;
}
@Override
publicStringiconPathForWidget(){
return"/com/fr/web/images/combobox.png";
}
@Override
publicStringnameForWidget(){
return"自定义下拉框";
}
}
2、重写控件类
packagecom.hg.free.plugin.customcombo.param;
importcom.fr.form.ui.ComboBox;
importcom.fr.ui.DataFilter;
{
=7169771062153345236L;
@Override
publicStringgetXType(){
return"customcombo";
}
@Override
(){
();
}
}
因为要改变过滤方式,就要重写一个过滤器
packagecom.hg.free.plugin.customcombo.param;
importcom.fr.form.ui.ComboBoxDataFilter;
{
@Override
publicbooleanisMatch(Stringtxt,Stringfilter){
if(null==txt&&null!=filter)returnfalse;
if(null==txt&&null==filter)returntrue;
returntxt.indexOf(filter)!=-1;
}
}
3、继承前端控件js
;
(function($){
FR.CustomComboBoxEditor=FR.extend(FR.ComboBoxEditor,{
_init:function(){
FR.CustomComboBoxEditor.superclass._init.apply(this,arguments);
}
});
$.shortcut("customcombo",FR.CustomComboBoxEditor);
})(jQuery);
然后写个xml用ant打包成插件就可以了。
Ⅳ 如何重写自定义控件里的事件
使用OnPaint事件可以随时绘制图形 调用窗体的OnPaint事件protected override void OnPaint(PaintEventArgs e){ base.OnPaint(e); //绘图} 但是如何重写控件的OnPaint事件呢?比如说绘图是在PictureBox中绘制的,那么如何重写PictureBox的OnPaint事件? 我们无法直接在窗体的代码中重写控件的OnPaint事件,只能重写窗体的OnPaint事件。 重写控件的OnPaint事件,必须创建一个新的控件。这个控件继承Windows的控件,然后在创建的控件中重写控件的OnPaint事件。 以PictureBox为例: //定义一个新的控件,继承PictureBox控件 public class myPictureBox : PictureBox { //自定义控件的构造函数 public myPictureBox() { } //重写控件的OnPaint属性 protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); //绘图 } } 使用这种方法,就可以重写任何一个控件的OnPaint事件了。
Ⅵ asp.net 自定义控件
先贴源代码~一会再解释~
新建一个类库/服务器控件项目,添加TextBox.cs文件,复制以下代码~
TextBox.cs
using System.Collections.Specialized;
namespace MyControl
{
[DefaultProperty("Text")]
[ToolboxData("<{0}:TextBox runat=server></{0}:TextBox>")]
public class TextBox : WebControl,IPostBackDataHandler
{
#region //event
public event EventHandler TextChanged;
#endregion
#region //Properties
public string Text
{
get
{
String s = (String)ViewState["Text"];
return ((s == null) ? "" : s);
}
set
{
ViewState["Text"] = value;
}
}
#endregion
#region //Render Engine
protected override HtmlTextWriterTag TagKey
{
get
{
return HtmlTextWriterTag.Input;
}
}
protected override void AddAttributesToRender(HtmlTextWriter writer)
{
writer.AddAttribute(HtmlTextWriterAttribute.Type, "text");
writer.AddAttribute(HtmlTextWriterAttribute.Name, this.UniqueID);
writer.AddAttribute(HtmlTextWriterAttribute.Value, Text);
base.AddAttributesToRender(writer);
}
#endregion
#region //realize the interface IPostBackDataHandler
public bool LoadPostData(string postDataKey, NameValueCollection postCollection)
{
if (postCollection[postDataKey] != Text)
{
Text = postCollection[postDataKey];
return true;
}
return false;
}
public void RaisePostDataChangedEvent()
{
if (TextChanged != null)
TextChanged(this, EventArgs.Empty);
}
#endregion
}
}
测试自定义控件的步骤:
右键项目,选择【生成】
新建一个网站,新建/Bin目录,右键【添加引用】,导航到上一个新建的项目的.ddl文件。
default.aspx的源代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register Assembly="MyControl" Namespace="MyControl" TagPrefix="lark" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<lark:TextBox runat="server" ID="tbInput" OnTextChanged="tbInput_TextChanged"></lark:TextBox>
<asp:Button ID="btnSubmit" runat="server" Text="提交" />
<asp:Label ID="lblShowInput" runat="server" ></asp:Label>
</div>
</form>
</body>
</html>
default.aspx.cs
protected void tbInput_TextChanged(object sender,EventArgs e)
{
lblShowInput.Text = "您输入的是:" + tbInput.Text;
}
==============源代码部分(完)===================
下面随便解释下源代码哈~
1。自定义控件其实就是个类,该类继承自WebControl类,同时实现IPostBackDataHandler接口~
2。添加自定义属性Text,并将之存储在控件的ViewState集合中~
3。添加自定义事件TextChanged
4。编写控件的生成引擎:
重写TagKey属性为INPUT,以修改外围标记
重写AddAttributeToRender()方法,为外围标记<input/>添加type value name属性。
5。实现IPostBackDataHandler接口的两个方法:
LoadPostData():接收投递的表单值,用于更新Text属性值。若属性值变化,返回true,自动调用RaisePostDataChangedEvent()方法。
RaisePostDataChangedEvent()方法中激活TextChanged事件~
以上~
自定义控件是ASP.NET中比较难懂的概念了~但是一旦掌握了的话,对之前ASP.NET的许多知识点都会有质的飞跃哦~
Ⅶ android自定义控件继承View,其中父类的三个构造方法有什么区别
在代码里new的话一般用一个参数的,
写在xml里的 调用2个参数的 attr里边传过来的是 xml里边对应的height width等参数,包括自己定义的参数,如果在xml里边写入自定义控件的话 必须要重写2个参数的构造函数
第3个参数不熟,传style的吧貌似
Ⅷ android 自定义view要重写哪几个方法
很多的Android入门程序猿来说对于Android自定义View,可能都是比较恐惧的,但是这又是高手进阶的必经之路,所有准备在自定义View上面花一些功夫,多写一些文章。先总结下自定义View的步骤: 1、自定义View的属性 2、在View的构造方法中获得我们自定义的属性 [ 3、重写onMesure ] 4、重写onDraw 我把3用[]标出了,所以说3不一定是必须的,当然了大部分情况下还是需要重写的。 详见网址:blog/lmj623565791/article/details/24252901