当前位置: 首页 > news >正文

一种C# Winform的UI处理

效果

·圆角 + 阴影 +突出按钮

说明

这是一种另类的处理,不是多层窗口 也不是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);
}

http://www.dtcms.com/a/99187.html

相关文章:

  • Python第六章18:数据容器的通用操作
  • 简单ELK框架搭建
  • 为pip设置国内镜像源
  • Android Jetpack学习总结(源码级理解)
  • 明达IOT 平台助推纺织龙头实现智能管理
  • 动态规划篇(数位统计DP)
  • 用空闲时间做了一个小程序-二维码生成器
  • 【安全】nginx防止host头攻击
  • c++弱指针实现原理
  • Python小练习系列 Vol.5:数独求解(经典回溯 + 剪枝)
  • Linux之基础知识
  • 深度学习处理时间序列(5)
  • 《新凯来:半导体设备制造领域的“国家队”》
  • 【愚公系列】《高效使用DeepSeek》039-政务工作辅助
  • LeetCode 2360.图中的最长环:一步一打卡(不撞南墙不回头) - 通过故事讲道理
  • Redis延时队列在订单超时未报到场景的应用分享
  • 【数据结构】二叉树 — 经典OJ面试题剖析!!!
  • 关于 websocket协议的理解
  • 001 - 前缀和算法:从原理到实战,一文讲透区间和问题
  • 谈谈Minor GC、Major GC和Full GC
  • Java——数组
  • RSA 简介及 C# 和 js 实现【加密知多少系列_4】
  • .NET开发基础知识11-20
  • Lavazza拉瓦萨亮相上海樱花节,增色海派咖啡风情
  • rbpf虚拟机-汇编和反汇编器
  • OpenCV、YOLO与大模型的区别与关系
  • Web开发:数据的加密和解密
  • Python之函数
  • 图片RGBA像素值提取工具v1.0.0发布
  • 【原理系列】计算机组成原理-第一遍阅读总结