如何把Button按钮样式换成ImageButton?

问题描述

red button

解决方案

最直接的办法就是把button的content设置为图片,还有一个比较通用的办法就是把这个button做成一个模板化控件。
新建一个名称为ImageButton的模板化控件,在cs文件里加上一个Icon属性,前台模板里对应的加上一个图片,然后实现Icon的属性,要用到类似下面的代码来注册一下这个属性
public object Title
{
get { return GetValue(TitleProperty); }
set { SetValue(TitleProperty, value); }
}

public static readonly DependencyProperty TitleProperty =
DependencyProperty.Register(
“Title”,
typeof(object),
typeof(TWindow),
null);
最后不要忘记重写OnApplyTemplate,类似
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
}
的代码就可以搞定,在这里面可以用GetTemplateChild(控件名称)来得到模板里的控件,组织一下就得到了一个通用的ImageButton控件。
附上我做的一个效果:
silverlight

代码如下:

<Style x:Key="StyleCode" TargetType="{x:Type Button}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border x:Name="borderBG">
<Border.Background>
<ImageBrush ImageSource="../Resources/register/code-btn.png"/>
</Border.Background>
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="borderBG" Property="Background">
<Setter.Value>
<ImageBrush ImageSource="../Resources/register/code-btn-hover.png" />
</Setter.Value>
</Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

参考

http://stackoverflow.com/questions/3965427/wpf-set-border-background-in-trigger

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
编辑器 FCKeditor2.4 使用说明 .下载 FCKeditor2.3 (FCKeditot for java) FCKeditor2.4 (FCKeditor基本文件) 以下是下载地址: http://www.fckeditor.net/download/default.html 2.建立项目: 建立项目tomcat/webapps/TestFCKeditor. 3.将FCKeditor2.4解压缩 将FCKeditor2.4解压缩,将整个目录FCKeditor复制到项目的根目录下,并将解压缩出来的文件夹fckeditor重命名为FCKeditor 目录结构为:tomcat/webapps/TestFCKeditor/FCKeditor 然后将FCKeditor-2.3.zip(java)压缩包中\web\WEB-INF\lib\目录下的两个jar文件拷到项目的\WEB-INF\ lib\目录下把其中的src目录下的FCKeditor.tld文件copy到TestFCKedit/WEB-INF/下 4.合并web.xml: 将FCKeditor-2.3.zip压缩包中\web\WEB-INF\目录下的web.xml文件合并到项目的\WEB-INF\目录下的web.xml文件中 5. 修改合并后的web.xml文件 修改合并后的web.xml文件,将名为SimpleUploader的Servlet的enabled参数值改为true, 以允许上传功能,Connector Servlet的baseDir参数值用于设置上传文件存放的位置 在web.xml最后添加标签定义: <taglib> <taglib-uri>/TestFCKeditor</taglib-uri> <taglib-location>/WEB-INF/FCKeditor.tld</taglib-location> </taglib> 现在的web.xml文件没有<taglib>标签了,应该直接在jsp文件中使用:<%@ taglib uri="http://fckeditor.net/tags-fckeditor" prefix="FCK" %> 6. 映射: 上面文件中两个servlet的映射分别为:/editor/filemanager/browser/default/connectors/jsp/connector 和/editor/filemanager/upload/simpleuploader,需要在两个映射前面加上/FCKeditor, 即改为/FCKeditor/editor/filemanager/browser/default/connectors/jsp/connector和 /FCKeditor/editor/filemanager/upload/simpleuploader 这两个名字根据你放在工程中的FCKeditor文件夹名称而定 7.修改skin文件夹 进入skin文件夹,如果你想使用fckeditor默认的这种奶黄色, 那就把除了default文件夹外的另两个文件夹直接删除.(建议不删除,以后要用到其中的一个文件夹) 8.删除无用文件 删除/FCKeditor/目录下除fckconfig.js, fckeditor.js, fckstyles.xml, fcktemplates.xml四个文件以外的所有文件,保留文件夹editor 删除目录/editor/_source, 删除/editor/filemanager/browser/default/connectors/下的所有文件 删除/editor/filemanager/upload/下的所有文件 删除/editor/lang/下的除了fcklanguagemanager.js(我下载的没有这个文件), en.js, zh.js, zh-cn.js四个文件的所有文件 9.修改配置: 打开/FCKeditor/fckconfig.js 修改 FCKConfig.DefaultLanguage = 'zh-cn' ; 把FCKConfig.LinkBrowserURL等的值替换成以下内容: FCKConfig.LinkBrowserURL = FCKConfig.BasePath + "filemanager/browser/default/browser.html?Connector=connectors/jsp/connector" ; FCKConfig.ImageBrowserURL = FCKConfig.BasePath + "filemanager/browser/default/browser.html?Type=Image&Connector=connectors/jsp/connector" ; FCKConfig.FlashBrowserURL = FCKConfig.BasePath + "filemanager/browser/default/browser.html?Type=Flash&Connector=connectors/jsp/connector" ; FCKConfig.LinkUploadURL = FCKConfig.BasePath + 'filemanager/upload/simpleuploader?Type=File' ; FCKConfig.FlashUploadURL = FCKConfig.BasePath + 'filemanager/upload/simpleuploader?Type=Flash' ; FCKConfig.ImageUploadURL = FCKConfig.BasePath + 'filemanager/upload/simpleuploader?Type=Image' ; 10.其它 fckconfig.js总配置文件,可用记录本打开,修改后将文件存为utf-8 编码格式找到: FCKConfig.TabSpaces = 0 ; 改为FCKConfig.TabSpaces = 1 ; 即在编辑器域内可以使用Tab键 如果你的编辑器还用在网站前台的话,比如说用于留言本或是日记回复时,那就不得不考虑安全了, 在前台千万不要使用Default的toolbar,要么自定义一下功能,要么就用系统已经定义好的Basic, 也就是基本的toolbar,找到: FCKConfig.ToolbarSets["Basic"] = [ ['Bold','Italic','-','OrderedList','UnorderedList','-',/*'Link',*/'Unlink','-','Style','FontSize','TextColor','BGColor','-', 'Smiley','SpecialChar','Replace','Preview'] ] ; 这是改过的Basic,把图像功能去掉,把添加链接功能去掉,因为图像和链接和flash和图像按钮添加功能都能让前台 页直接访问和上传文件, fckeditor还支持编辑域内的鼠标右键功能 FCKConfig.ContextMenu = ['Generic',/*'Link',*/'Anchor',/*'Image',*/'Flash','Select','Textarea','Checkbox','Radio','TextField','HiddenField', /*'ImageButton',*/'Button','BulletedList','NumberedList','TableCell','Table','Form'] ; 这也是改过的把鼠标右键的链接图像,FLASH,图像按钮功能都去掉 找到: FCKConfig.FontNames = 'Arial;Comic Sans MS;Courier New;Tahoma;Times New Roman;Verdana' ; 加上几种我们常用的字体 FCKConfig.FontNames = '宋体;黑体;隶书;楷体_GB2312;Arial;Comic Sans MS;Courier New;Tahoma;Times New Roman;Verdana' ; 11.添加文件 添加文件 /TestFCKeditor/test.jsp: <%@ page language="java" import="com.fredck.FCKeditor.*" %> <%@ taglib uri="/TestFCKeditor" prefix="FCK" %> <script type="text/javascript" src="/TestFCKeditor/FCKeditor/fckeditor.js"></script> <%-- 三种方法调用FCKeditor 1.FCKeditor自定义标签 (必须加头文件 <%@ taglib uri="/TestFCKeditor" prefix="FCK" %> ) 2.script脚本语言调用 (必须引用 脚本文件 <script type="text/javascript" src="/TestFCKeditor/FCKeditor/fckeditor.js"></script> ) 3.FCKeditor API 调用 (必须加头文件 <%@ page language="java" import="com.fredck.FCKeditor.*" %> ) --%> //标签调用方式 <%-- <form action="show.jsp" method="post" target="_blank"> <FCK:editor basePath="/TestFCKeditor/FCKeditor/" width="700" height="500" skinPath="/TestFCKeditor/FCKeditor/editor/skins/silver/" toolbarSet = "Default" > input </FCK:editor> <input type="submit" value="Submit"> </form> --%> //JS调用方式 <form action="show.jsp" method="post" target="_blank"> <table border="0" width="700"><tr><td> <textarea style="WIDTH: 100%; HEIGHT: 400px">input</textarea> <script type="text/javascript"> var oFCKeditor = new FCKeditor('content') ; oFCKeditor.BasePath = "/TestFCKeditor/FCKeditor/" ; oFCKeditor.Height = 400; oFCKeditor.ToolbarSet = "Default" ; oFCKeditor.ReplaceTextarea(); </script> <input type="submit" value="Submit"> </td></tr></table> </form> //FCKeditor API 调用 <%-- <form action="show.jsp" method="post" target="_blank"> <% FCKeditor oFCKeditor ; oFCKeditor = new FCKeditor( request, "content" ) ; oFCKeditor.setBasePath( "/TestFCKeditor/FCKeditor/" ) ; oFCKeditor.setValue( "input" ); out.println( oFCKeditor.create() ) ; %> <br> <input type="submit" value="Submit"> </form> --%> 添加文件/TestFCKeditor/show.jsp: <% String content = request.getParameter("content"); out.print(content); %> 12.测试 浏览http://localhost:8080/TestFCKeditor/test.jsp 最后注意不同的版本 变量名称可能不一样请参考你使用的API文档 配置选项: AutoDetectLanguage=true/false 自动检测语言 BaseHref="" 相对链接的基地址 ContentLangDirection="ltr/rtl" 默认文字方向 ContextMenu=字符串数组,右键菜单的内容 CustomConfigurationsPath="" 自定义配置文件路径和名称 Debug=true/false 是否开启调试功能,这样,当调用FCKDebug.Output()时,会在调试窗中输出内容 DefaultLanguage="" 缺省语言 EditorAreaCss="" 编辑区的样式表文件 EnableSourceXHTML=true/false 为TRUE时,当由可视化界面切换到代码页时,把HTML处理成XHTML EnableXHTML=true/false 是否允许使用XHTML取代HTML FillEmptyBlocks=true/false 使用这个功能,可以将空的块级元素用空格来替代 FontColors="" 设置显示颜色拾取器时文字颜色列表 FontFormats="" 设置显示在文字格式列表中的命名 FontNames="" 字体列表中的字体名 FontSizes="" 字体大小中的字号列表 ForcePasteAsPlainText=true/false 强制粘贴为纯文本 ForceSimpleAmpersand=true/false 是否不把&符号转换为XML实体 FormatIndentator="" 当在源码格式下缩进代码使用的字符 FormatOutput=true/false 当输出内容时是否自动格式化代码 FormatSource=true/false 在切换到代码视图时是否自动格式化代码 FullPage=true/false 是否允许编辑整个HTML文件,还是仅允许编辑BODY间的内容 GeckoUseSPAN=true/false 是否允许SPAN标记代替B,I,U标记 IeSpellDownloadUrl=""下载拼写检查器的网址 ImageBrowser=true/false 是否允许浏览服务器功能 ImageBrowserURL="" 浏览服务器时运行的URL ImageBrowserWindowHeight="" 图像浏览器窗口高度 ImageBrowserWindowWidth="" 图像浏览器窗口宽度 LinkBrowser=true/false 是否允许在插入链接时浏览服务器 LinkBrowserURL="" 插入链接时浏览服务器的URL LinkBrowserWindowHeight=""链接目标浏览器窗口高度 LinkBrowserWindowWidth=""链接目标浏览器窗口宽度 Plugins=object 注册插件 PluginsPath="" 插件文件夹 ShowBorders=true/false 合并边框 SkinPath="" 皮肤文件夹位置 SmileyColumns=12 图符窗列数 SmileyImages=字符数组 图符窗中图片文件名数组 SmileyPath="" 图符文件夹路径 SmileyWindowHeight 图符窗口高度 SmileyWindowWidth 图符窗口宽度 SpellChecker="ieSpell/Spellerpages" 设置拼写检查器 StartupFocus=true/false 开启时FOCUS到编辑器 StylesXmlPath="" 设置定义CSS样式列表的XML文件的位置 TabSpaces=4 TAB键产生的空格字符数 ToolBarCanCollapse=true/false 是否允许展开/折叠工具栏 ToolbarSets=object 允许使用TOOLBAR集合 ToolbarStartExpanded=true/false 开启是TOOLBAR是否展开 UseBROnCarriageReturn=true/false 当回车时是产生BR标记还是P或者DIV标记 解决上传乱码: 在SimpleUploaderServlet.java和ConnectorServlet.java两个文件里找到 DiskFileUpload upload = new DiskFileUpload(); 分别在其后加入 upload.setHeaderEncoding("utf-8"); 这样解决了文件上传的中文乱码问题. 但是在控制台显示的中文内容还是乱码,但是没关系,我们没必要去看控制台下的中文 ----------------------------------------------------------------another FCKeditor2.4.2 Java版使用说明 下载地址以及基本配置请参考:http://hi.baidu.com/wain19/blog/item/c33fb0fab74f24dfb48f312d.html 我的开发环境是ubuntu7.04, 系统默认编码是utf-8, 期间,本人遇到了下面这些问题: 问题一:XML request error: Internel Server Error(500) 出现错误的地方是在:点插入图片,点Browse按钮的时候: XML request error: Internel Server Error(500) 找资料:http://lamono.javaeye.com/blog/49135 拷贝xalan.jar和serialize.jar到/WEB-INF/lib,问题解决 FCKeditor-java没有很好的解决中文问题需要我们修改它的源代码后重新编译打包打包过程如下: 1 新建一个web工程名字为FCKeditor-java-2.3,然后把FCKeditor-2.3-java.zip解压缩后的代码拷贝到工程目录下 2如果是用的Eclipse,使用快捷键Ctrl+Shift+R 在SimpleUploaderServlet.java和ConnectorServlet.java两个文件里找到 DiskFileUpload upload = new DiskFileUpload(); 分别在其后加入 upload.setHeaderEncoding("utf-8"); 现在如果直接运行ant任务,会报下面的错误: taskdef class org.apache.catalina.ant.DeployTask cannot be found 3 把tomcat安装目录下/server/lib中的catalina-ant.jar拷贝到/WEB-INF/lib目录 下 4 打开build.xml 找到 <property 修改成你自己的tomcat安装目录 <property value="/home/uniquejava/tool/tomcat5028/"/> 找到 <taskdef 修改成如下内容 <taskdef classname="org.apache.catalina.ant.DeployTask"> <classpath refid="compile.classpath"> </classpath> </taskdef> <taskdef classname="org.apache.catalina.ant.ListTask"> <classpath refid="compile.classpath"> </classpath> </taskdef> <taskdef classname="org.apache.catalina.ant.ReloadTask"> <classpath refid="compile.classpath"> </classpath> </taskdef> <taskdef classname="org.apache.catalina.ant.UndeployTask"> <classpath refid="compile.classpath"> </classpath> </taskdef> 运行ant任务dist, 就可以生成新的FCKeditor-2.3.jar包 问题三: 上传时新建的中文目录全部乱码 虽然上传到服务器上的文件名正常,但在JSP页面点下载链接时文件名乱码导致不能正常下载 查找资料:TOMCAT 链接参数有中文时,乱码解决方法 http://hi.baidu.com/jadestone/blog/item/7564deefc9192d36acafd5be.html 修改tomcat-home/conf/server.xml 方法一: 在两处地方加上URIEncoding="utf-8": <Connector port="8080" maxThreads="150" minSpareThreads="25" maxSpareThreads="75" enableLookups="false" redirectPort="8443" acceptCount="100" debug="0" connectionTimeout="20000" disableUploadTimeout="true" URIEncoding="utf-8" /> <Connector port="8009" enableLookups="false" redirectPort="8443" debug="0" protocol="AJP/1.3" URIEncoding="utf-8" /> 方法二: 使用useBodyEncodingForURI="true". 这个方法适合你的TOMCAT实例下需要跑多个不同Encoding的程序时(有点怀疑?!) <... maxThreads="150" minSpareThreads="25" maxSpareThreads="75" enableLookups="false" redirectPort="8443" acceptCount="100" connectionTimeout="20000" disableUploadTimeout="true" useBodyEncodingForURI="true" /> enableLookups="false" redirectPort="8443" protocol="AJP/1.3" useBodyEncodingForURI="true" / 我只试了方法一,问题解决! 这样, FCKeditor终于可以正常使用了 ================================================================= 以下为个人原创 http://blog.csdn.net/nickshen3/ 怎么将FCKeditor2.4使用在自己的web中 1. 在webapps创建test文件夹webapps\test 2. 将下载的FCKeditor2.3的Java包FCKeditor-2.3.zip解压缩,并将web文件夹下的两个文件夹_samples,WEB-INF拷贝到刚才建立的webapps\test下再将src文件夹下的FCKeditor.tld拷贝到WEB-INF下 3. 在webapps\test\下建立文件夹FCKeditor 4. 将刚才下载的 FCKeditor_2.4.3.zip 解压缩,然后将fckeditor文件夹下的 editor(文件夹),fckconfig.js,fckeditor.js,fckstyles.xml,fcktemplates.xml四个文件拷贝到刚才建立的文件夹FCKeditor下 5.修改test\_samples\jsp\sample02.jsp文件,将原来的 <FCK:editor basePath="/FCKeditor/" 改为<FCK:editor basePath="/test/FCKeditor/"以后使用的时候只需将test换成项目的名称即可 6.打开tomcat测试Http://localhost:8080/test/_samples/jsp/sample02.jsp ok
要实现一个图片按钮,你可以使用 Android 中的 ImageButton 控件。ImageButton 控件是 Button 控件的子类,它允许你在按钮中显示一个图像。 如果你想要自定义 ImageButton 控件,可以创建一个继承自 ImageButton 的子类,并重写其中的方法。下面是一个 Android 自定义 ImageButton 的示例代码: ``` public class CustomImageButton extends ImageButton { public CustomImageButton(Context context) { super(context); } public CustomImageButton(Context context, AttributeSet attrs) { super(context, attrs); } public CustomImageButton(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); // 在这里绘制你自己的图像 // 例如,你可以使用 Canvas 对象来绘制一个圆形图像 Paint paint = new Paint(); paint.setAntiAlias(true); paint.setColor(Color.BLUE); canvas.drawCircle(getWidth() / 2, getHeight() / 2, getWidth() / 2, paint); } } ``` 在这个示例中,我们创建了一个名为 `CustomImageButton` 的子类,并重写了其中的 `onDraw` 方法。在 `onDraw` 方法中,我们使用 Canvas 对象来绘制一个蓝色的圆形图像。你可以根据自己的需求来绘制其它的图像。 要在布局文件中使用这个自定义 ImageButton,你可以像使用普通的 ImageButton 一样,使用完全限定的类名来引用它: ``` <com.example.myapplication.CustomImageButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/my_image" /> ``` 在这个示例中,我们使用 `com.example.myapplication.CustomImageButton` 来引用我们自己定义的 ImageButton 控件。我们也指定了 `android:src` 属性来设置 ImageButton 中显示的图像。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值