效果
·圓角 + 陰影 +突出按鈕
說明
這是一種另類的處理,不是多層窗口 也不是WPF 。這種方式的特點是比較簡單,例如圓角、陰影、按鈕等特別容易修改過。其實就是html + css + DirectXForm。
在VS中如下
圓角和陰影
然后編輯這個窗體的Html模板,例如圓角和陰影的調整可以修改CSS中的
?? ?border-radius: 14px;
?? ?box-shadow: 0px 8px 24px 0px rgba(0, 0, 0, 0.2);
我要想一個小圓角可以改成?border-radius: 6px;
中間的按鈕
中間的按鈕的CSS
.play_btn
{
?? ?position: fixed;
?? ?left: 50%;
?? ?margin-left: -39px;
?? ?cursor: pointer;
?? ?bottom: 22px;?? ?
?? ?display: inline-block;
?? ?width: 78px;
?? ?height: 78px;
?? ?background-color: rgb(255, 255, 255);?? ??
?? ?border-radius: 39px;
?? ?box-shadow: 4px 8px 8px 0px rgba(80, 80, 80, 0.55);?
}
如果你想要個丑點的陰影 ,可以改成
box-shadow: 4px 8px 8px 0px rgba(255, 0, 0, 0.75);
反正就是CSS
窗體可以隨便放控件?
全部代碼
using DevExpress.Utils;
using DevExpress.Utils.Html;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace MP3Cut
{public partial class Form1 : DevExpress.XtraEditors.DirectXForm{public Form1(){InitializeComponent();HtmlElementMouseDown += DemoDirectXForm_HtmlElementDown;}public DxHtmlElement element_mouse = null;void DemoDirectXForm_HtmlElementDown(object sender, DxHtmlElementMouseEventArgs e){var args = e.MouseArgs as DXMouseEventArgs;if (e.Element == null || args == null)return;element_mouse = e.Element;args.Handled= click_proc(element_mouse);}bool click_proc(DxHtmlElement element){if (element == null)return false;string id = element.Id;if ((string.Compare(id, "playbutton", true) == 0)|| (string.Compare(id, "playbutton_img", true) == 0)){DxHtmlImageElement el = (DxHtmlImageElement)(this.FindElementById("playbutton_img"));string src = el.Src;if (string.Compare(src, "play", true) == 0){el.ClassName = "img_pause";el.Src = "pause"; }else{el.ClassName = "img_play";el.Src = "play";} //directXFormContainerControl1.Refresh(); return true;}return false;}private void Form1_MouseClick(object sender, MouseEventArgs e){}private void directXFormContainerControl1_DoubleClick(object sender, EventArgs e){}private void Form1_MouseDoubleClick(object sender, MouseEventArgs e){if (element_mouse != null){ click_proc(element_mouse);this.Invalidate(true);this.Scale(1.000f);}}private void simpleButton1_Click(object sender, EventArgs e){if (element_mouse != null){click_proc(element_mouse);this.Invalidate(true);this.Scale(1.000f);}}}
}
HTML
<div class="shadowframe"><div class="frame" id="frame"><div class="titlebar"><img class="logo" src="logo" /><div class="title">一個例子</div><div class="searchbox"></div> <img class="button" src="Close" id="closebutton"/></div><div class="content" id="content"></div><div class="footerbar"> <img class="button" src="begin" id="beginbutton"/><div style="width:200px;display: inline-block;"></div> <img class="button" src="end" id="enbbutton"/> </div></div><div class="play_btn" id="playbutton"><img class="img_play" id="playbutton_img" src="play" /></div>
</div>
CSS
body{
?? ?padding: 30px;
}
.titlebar{
?? ?padding: 11px 12px 11px 11px;
?? ?display: flex;
?? ?flex-direction: row;
?? ?height: 40px;
}
.shadowframe{
?? ?height: 100%;
?? ?border-radius: 6px;
?? ?box-shadow: 0px 8px 24px 0px rgba(0, 0, 0, 0.2);
}
.frame{
?? ?height: 100%;
?? ?display: flex;
?? ?flex-direction: column;
?? ?border-radius: 6px;
?? ?border: 1px solid rgba(0, 0, 0, 0.2);
?? ?background-color: rgb(252, 252, 253);
?? ?box-shadow: 0px 2px 4px 0px rgba(0, 0, 0, 0.15);
}
.footerbar{
?? ?padding: 11px 11px 11px 10px;
?? ?align-items: center; ?
?? ?height: 42px;
?? ?background-color:rgb(249,250,251);
?? ?border-radius: 0px 0px 13px 13px;
?? ?text-align: center;
?? ?border-top: 1px solid rgb(229, 231, 235);
}
.contenttext{
?? ?display: flex;
?? ?justify-content: center;
?? ?align-items:center;
?? ?flex-direction: column;
?? ?align-self: center;
?? ?font: 14px 'Segoe UI';
?? ?color: @DisabledText/0.5;
}
.content{
?? ?flex-grow: 1;
} ??
.panelspace{
?? ?flex-grow:1;
}
.button {
?? ?margin: 0px 4px 0px 4px;
?? ?padding: 8px;
?? ?opacity: 1;
?? ?object-fit: none;
}
.button:hover{
?? ?border-radius: 8px;
?? ?background-color: @ControlText/0.2;
}
.button:active{
?? ?opacity: 0.25;
?? ?border-radius: 8px;
?? ?background-color: @ControlText/0.2;
}
.logo{
?? ?margin:-5px 15px 0px 0px;
?? ?object-fit: none;
}
.searchbox{
?? ?display: flex;
?? ?flex-direction: row;?? ?
?? ?height: 40px;
?? ?flex-grow: 1;
}
.play_btn
{
?? ?position: fixed;
?? ?left: 50%;
?? ?margin-left: -39px;
?? ?cursor: pointer;
?? ?bottom: 22px;?? ?
?? ?display: inline-block;
?? ?width: 78px;
?? ?height: 78px;
?? ?background-color: rgb(255, 255, 255);?? ??
?? ?border-radius: 39px;
?? ?box-shadow: 4px 8px 8px 0px rgba(80, 80,80, 0.55);
? ?
}
.play_btn:hover{?
?? ?background-color: rgb(237,238,239);
}
.play_btn:active{?
?? ?background-color: ?rgb(244,248,249);
}
.img_play {
?? ?width: 42px;
?? ?height: 42px;
?? ?margin-top: 19px;
?? ?margin-left: 24px;
?? ?pointer-events: none;
} ?
.img_pause {
?? ?width: 24px;
?? ?margin-top: 22px;
?? ?margin-left: 27px;
?? ?pointer-events: none;
} ?
.title {
?? ?padding: 5px;
?? ?display: inline-block;
?? ?font: 19px 'Segoe UI';
?? ?font-weight: bold;
?? ?color: rgb(100, 116, 139);
}