宁睿 发表于 2025-3-30 23:37:57

一种C# Winform的UI处理惩罚

效果

·圆角 + 阴影 +突出按钮https://i-blog.csdnimg.cn/direct/fd4a5a2377bd4cf68ef43ab8ecdf4db4.png
说明

这是一种另类的处理惩罚,不是多层窗口 也不是WPF 。这种方式的特点是比较简单,例如圆角、阴影、按钮等特殊轻易修改过。实在就是html + css + DirectXForm。
在VS中如下
https://i-blog.csdnimg.cn/direct/fef0db38425b4849b70380a07ca869c9.png
圆角和阴影

然后编辑这个窗体的Html模板,例如圆角和阴影的调整可以修改CSS中的
    border-radius: 14px;
    box-shadow: 0px 8px 24px 0px rgba(0, 0, 0, 0.2);
https://i-blog.csdnimg.cn/direct/fca0ac463fc54453b7491fecd7625a04.png
我要想一个小圆角可以改成 border-radius: 6px;
https://i-blog.csdnimg.cn/direct/6426d6ebfcb64a57adf72d264bcd5957.png
中间的按钮

中间的按钮的CSS
https://i-blog.csdnimg.cn/direct/97ac5121a9274065884671c83c89a206.png
.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);
https://i-blog.csdnimg.cn/direct/4b372715afe14649a825d239a8a9c8d9.png
反正就是CSS
窗体可以任意放控件 
https://i-blog.csdnimg.cn/direct/2f512e3cab98405bac64de9888a992da.png
全部代码

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"/>
               <divstyle="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);
}

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
页: [1]
查看完整版本: 一种C# Winform的UI处理惩罚