码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • 自定义容器控件之C#设计笔记(十五)


    一、定义容器控件时,需对该类指定相应特性
    Designer(typeof(ParentControlDesigner))

    二、获取或设置边框属性,如颜色、宽度、阴影、样式等等函数实现如下
    //获取或设置边框宽度
    float penWidth = 2;
    public float PenWidth
    {
    get
    {
    return penWidth;
    }
    set
    {
    if (penWidth != value)
    {
    penWidth = value;
    Invalidate();
    }
    }
    }
    //获取或设置顶边框颜色
    Color topcolor = Color.FromArgb(45, 45, 47);
    public Color PenTopColor
    {
    get
    {
    return topcolor;
    }
    set
    {
    if (topcolor != value)
    {
    topcolor = value;
    Invalidate();
    }
    }
    }
    //获取或设置滴边框颜色
    Color bottomcolor = Color.FromArgb(127, 127, 130);
    public Color PenBottomColor
    {
    get
    {
    return bottomcolor;
    }
    set
    {
    if (bottomcolor != value)
    {
    bottomcolor = value;
    Invalidate();
    }
    }
    }
    //边框绘制
    private void DrawBorder(Graphics g)
    {
    if (penWidth > 0)
    {
    List points = GetPoints();
    Pen pen = new Pen(topcolor, PenWidth);
    g.DrawLine(pen, points[0], points[1]);
    g.DrawLine(pen, points[0], points[3]);
    pen.Width += 3;
    pen.Color = bottomcolor;
    g.DrawLine(pen, points[1], points[2]);
    g.DrawLine(pen, points[3], points[2]);
    pen.Dispose();
    }
    }
    private List GetPoints()
    {
    List points = new List();
    points.Add(new Point(0, 0));
    points.Add(new Point(this.Width ,0));
    points.Add(new Point(this.Width , this.Height));
    points.Add(new Point(0, this.Height));
    return points;
    }

    三、自定义Panel的初始化时,注意设置缓冲区避免闪烁感,并指定相应样式
    如下
    public useranel()
    {
    InitializeComponent();
    this.SetStyle(ControlStyles.ResizeRedraw
    | ControlStyles.DoubleBuffer
    | ControlStyles.AllPaintingInWmPaint
    | ControlStyles.UserPaint,
    true);
    this.UpdateStyles();
    DoubleBuffered = true;
    }

    四、在重画中增加相应实现:如设置边框、颜色、宽度、阴影等等
    protected override void OnPaint(PaintEventArgs pe)
    {
    base.OnPaint(pe);
    DrawBorder(pe.Graphics);
    }

    五、实现自定义控件注意该类继承UserControl,并添加如下相关引用
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Drawing;
    using System.Windows.Forms;
    using System.Windows.Forms.Design;

  • 相关阅读:
    memcmp函数详解 看这一篇就够了-C语言(函数讲解、函数实现、使用用法举例、作用、自己实现函数 )
    itext生成pdf
    Vue框架的学习(Vue操作指令学习三 V-bind )第三课
    《程序员的炫技代码》
    vue基于promise可以用于浏览器和node.js的网络请求库【axios封装-收藏版】
    资深腾讯架构师耗时2个月整理的Redis全套学习笔记,涵盖所有核心知识点
    java8新特性(上)-Lambda表达式
    软件流程和管理(四):Communication Management
    leetcode-240:搜索二维矩阵 II
    GitHub基本概念
  • 原文地址:https://blog.csdn.net/weixin_48408892/article/details/127925740
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号