简体   繁体   English

asp.net中Web窗体的自定义按钮

[英]Custom buttons for Web Forms in asp.net

I would like to make some custom buttons for a website I am writing in asp.net. 我想为我在asp.net中编写的网站设置一些自定义按钮。 I am having a hard time figuring out what would be the best way to go. 我很难弄清楚什么是最好的方法。

For these buttons, I would like to design their looks. 对于这些按钮,我想设计它们的外观。 Shapes other than rectangles is what I am going for. 我要的是矩形以外的其他形状。 I also want these buttons to behave like a normal button would. 我还希望这些按钮的行为像普通按钮一样。 Lets say the normal state version of the button is red, then when I click on the button it turns yellow, and finally when I release ( mouse button up ), it goes back to red. 可以说该按钮的正常状态版本为红色,然后当我单击该按钮时它变为黄色,最后当我松开(鼠标按钮向上)时,它又回到红色。 I would also like the clickable region be in the same shape of the button. 我也希望可点击区域具有与按钮相同的形状。

I have looked at ImageButtons and this doesn't quite fit what I want it to do. 我已经看过ImageButtons了,这与我想要它做的不完全一样。 I have looked at User Controls and Custom Controls but I don't know if this is quite what I want either. 我看过用户控件和自定义控件,但我不知道这是否是我想要的。 In school, we didn't really go over these features in either of my C sharp class or asp.net web development class. 在学校里,我的C Sharp课程或asp.net Web开发课程都没有真正涉及这些功能。 Most stuff that seems to fit what I want are demos and examples in winforms, not necessarily in webforms. 似乎最适合我想要的东西是winforms中的演示和示例,而不一定是webforms中的示例。

What is the best way to go to try and accomplish this? 尝试实现此目标的最佳方法是什么? Is User Control the way to go? 用户控制是要走的路吗? Or is there a more elegant way to accomplish this? 还是有一种更优雅的方式来实现这一目标? Any advice is greatly appreciated. 任何意见是极大的赞赏。 I don't want code, I just want to know which way to go that you guys would think would be easiest. 我不需要代码,我只想知道你们认为最简单的方法。

Thank you. 谢谢。

As for me, I won't implement User Control just to style button. 对于我来说,我不会仅仅为样式按钮实现用户控制。 Instead, I'll use CSS to style them, because CSS is light weight and easy to maintain. 相反,我将使用CSS设置样式,因为CSS重量轻且易于维护。

For example, 例如,

在此处输入图片说明

<style type="text/css">
    .submit {
        border: 1px solid #563d7c;
        border-radius: 5px;
        color: white;
        padding: 5px 10px 5px 25px;
        background: url(https://i.stack.imgur.com/jDCI4.png) 
            left 3px top 5px no-repeat #563d7c;
    }
</style>

<asp:Button runat="server" ID="Button1" Text="Submit" CssClass="submit" />

User or Custom controls are the way to go. 用户或自定义控件是必经之路。 You can define the HTML, CSS, Javascript, rendering, everything that your control needs. 您可以定义HTML,CSS,Javascript,渲染以及控件所需的所有内容。

User controls are .ascx files that you can implement in your code behind. 用户控件是.ascx文件,您可以在后面的代码中实现这些文件。 They are easy and lightweight but not good for large projects. 它们简单轻巧,但不适用于大型项目。

Custom controls are compiled and if desired you can drag and drop them in your form(s). 自定义控件已编译,如果需要,您可以将其拖放到表单中。 These take more time but you can control the rendering and they work well in large projects. 这些操作花费更多时间,但是您可以控制渲染,并且在大型项目中效果很好。

You can read more here: 你可以在这里阅读更多:

https://msdn.microsoft.com/en-us/library/aa651710%28v=vs.71%29.aspx?f=255&MSPPError=-2147217396 https://msdn.microsoft.com/zh-cn/library/aa651710%28v=vs.71%29.aspx?f=255&MSPPError=-2147217396

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM