简易调色盘控件 for .NET(EN)
By Conmajia
Originally posted in 2012
Introduction
Simple & fast implementation of a rectangular RGB palette control for .NET Fx 2.0. Old-school shit.
Name it as SRP.
Project download… Nah...
(ancient project, where on earth can I retrieve those antiques?)
The palette looks like:
Features
Pick a color
You can access the color you pick via
e.Colorof theColorChangedevent.Set palette block size
Note that size of the whole palette will be changed.
Screenshots
Here I have several examples. SRP is formed in a 6×36 color grid.
Layers
Disassemble SRP into layers for graphic painting. (bottom to top)
- Canvas
- Color blocks
- Grids
- Border
- Cursor
Paint It
Paint these layer sequentially.
protected override void OnPaint(PaintEventArgs e) {
Graphics g = e.Graphics;
drawPalette(g);
drawGrid(g);
drawBorder(g);
drawCursor(g);
}
A hello to the modern Flat UI 7 yrs. ago.
void drawGrid(Graphics g) {
for(int i = 0; i < rows; i++) {
g.DrawLine(Pens.Black, 0, blockWidth * (i + 1), blockWidth * cols, blockWidth * (i + 1));
}
for(int i = 0; i < cols; i++) {
g.DrawLine(Pens.Black, blockWidth * (i + 1), 0, blockWidth * (i + 1), blockWidth * rows);
}
}
Calculate coordinates of a color, fill blocks, proceed on. Here’s my algorithm of generating RGB colors, you can generate your own shits.
Color getColor(int row, int col) {
byte r = 0, g = 0, b = 0;
int step = 0xff / (rows - 1);
r = (byte)(row * step);
g = (byte)(step * (col / rows));
b = (byte)(step * (col % rows));
return Color.FromArgb(r, g, b);
}
Instead of storing preset colors, all colors shown were automatically generated during run-time.
current = getColor(pt.Y / blockWidth, pt.X / blockWidth);
Draw mouse cursor. Refresh only dirty parts on canvas.
void updateCursor(Point pt) {
lastCursor.X = cursor.X;
lastCursor.Y = cursor.Y;
cursor.X = pt.X - pt.X % blockWidth;
cursor.Y = pt.Y - pt.Y % blockWidth;
current = getColor(pt.Y / blockWidth, pt.X / blockWidth);
}
Redraw dirty.
protected override void OnMouseMove(MouseEventArgs e) {
updateCursor(e.Location);
// redraw larger spaces
Invalidate(new Rectangle(lastCursor.X - 1, lastCursor.Y - 1, lastCursor.Width + 2, lastCursor.Height + 2));
Invalidate(new Rectangle(cursor.X - 1, cursor.Y - 1, cursor.Width + 2, cursor.Height + 2));
// fire event
OnColorChanged();
}
Trigger OnColorChanged() event which happens after color is changed.
// -- custom events
public delegate void ColorChangedEventHandler(object sender, ColorChangedEventArgs e);
[Description("Fires every time when color changed.")]
public event ColorChangedEventHandler ColorChanged;
protected virtual void OnColorChanged() {
if(ColorChanged != null) ColorChanged(this, new ColorChangedEventArgs(current));
}
// custom event args
public class ColorChangedEventArgs: EventArgs {
Color color = Color.Black;
public Color Color {
get {
return color;
}
set {
color = value;
}
}
public ColorChangedEventArgs(Color color): base() {
this.color = color;
}
}
Application
With some extra optimizations, you'll have one simple yet elegant palette.
The End. \(\Box\)
#cnblogs_post_body>p {text-indent:0 !important;}
简易调色盘控件 for .NET(EN)的更多相关文章
- WPF Timeline简易时间轴控件的实现
原文:WPF Timeline简易时间轴控件的实现 效果图: 由于整个控件是实现之后才写的教程,因此这里记录的代码是最终实现后的,前后会引用到其他的一些依赖属性或者代码,需要阅读整篇文章. 1.确定T ...
- 贝塞尔曲线控件 for .NET (EN)
Conmajia 2012 Updated on Feb. 18, 2018 In Photoshop, there is a very powerful feature Curve Adjust, ...
- WinForm 简易仿360界面控件
因为经常要做一些1.2千行的小工具,WinForm自带的TabCtrl又不美观,所以想做成360的样子,在网上找来找去,都只有散乱的代码,没有可以通用的结构,于是自己写了一个简易的通用控件. 控件主要 ...
- 【番外篇】ASP.NET MVC快速入门之免费jQuery控件库(MVC5+EF6)
目录 [第一篇]ASP.NET MVC快速入门之数据库操作(MVC5+EF6) [第二篇]ASP.NET MVC快速入门之数据注解(MVC5+EF6) [第三篇]ASP.NET MVC快速入门之安全策 ...
- MSComm控件与Win32 API操作串口有何区别?
MSComm控件与Win32 API操作串口有何区别? [问题点数:50分,结帖人shell_shell] 收藏帖子 回复 我是一个小兵,在战场上拼命! 结帖率 83.33% 我以前用MSCo ...
- 手机APP支付--整合银联支付控件
长话短说,本文根据银联官方说明文档,简单总结下,并且说明下中途碰到问题该如何解决. 一.开发前的准备工作1. 打开https://open.unionpay.com/,后续说的文档下载.FAQ查询等都 ...
- Web 前端实战:JQ 实现树形控件
前言 这是一篇个人练习 Web 前端各种常见的控件.组件的实战系列文章.本篇文章将介绍个人通过 JQuery + 无序列表 + CSS 动画完成一个简易的树形控件. 最终实现的效果是: 这样结构比较复 ...
- IOS(二)基本控件UIButton、简易动画、transform属性、UIImageView
UIButton //1.设置UIButton 的左右移动 .center属性 获得 CGPoint 来修改x y //1.设置UIButton 的放大缩小 bounds属性 获得CGRect 然后通 ...
- 性能调优的Windows窗体DataGridView控件
性能调优的Windows窗体DataGridView控件 . 净框架4.5 在处理大量数据时, DataGridView 控制可以消耗大量的内存开销,除非你仔细地使用它. 在客户有限的内存,你 ...
随机推荐
- BZOJ_2938_[Poi2000]病毒_AC自动机
BZOJ_2938_[Poi2000]病毒_AC自动机 Description 二进制病毒审查委员会最近发现了如下的规律:某些确定的二进制串是病毒的代码.如果某段代码中不存在任何一段病毒代码,那么我们 ...
- ios swift版 sqlite3详解
iOS中的SQLite3的封装与详细应用 SQLite是一个开源的嵌入式关系数据库,特点是易使用.高效.安全可靠.可移植性强. iOS中的本地持久化存储 NSUserDefault:一般用于存储小规模 ...
- nginx用户认证与htpasswd命令
最近在搭建ELK,然后ELK的kibana界面想添加一个访问限制,看到kibana有个插件x-pack,本来想用用,发现是收费的,就放弃了,然后就想着想配置下nginx的认证访问来实现简单的访问登陆. ...
- Bootstrap优秀模板-ColorAdmin.4.3.0
老牌的Bootstrap商业模板,提供HTML.AngularJS.AngularJS5.Vue.React多种环境,风格覆盖Flat.Material.Apple.Transparent甚至Face ...
- 神奇的Scala Macro之旅(四)- BeanBuilder
在Java开发中,经常会有一个需求,将一个 Bean 复制到另外一个 Bean,尤其是在后台分层的场景下,在不同的层之间传递信息,经常需要进行 这样的一个对象复制工作,类似于: val source: ...
- 系统的讲解 - SSO单点登录
目录 概念 好处 技术实现 小结 扩展 概念 SSO 英文全称 Single Sign On,单点登录. 在多个应用系统中,只需要登录一次,就可以访问其他相互信任的应用系统. 比如:淘宝网(www.t ...
- Hi,给他介绍一款markdown的帮助文档生成器
当今大多数的团队都实现了前.后端分支.前端与后端的沟通都是通过接口来实现的(一般情况下都是webapi接口).这种情况你肯定需要一个接口查询的帮助文档,这个当然用swagger都可以实现.但做为前端开 ...
- [翻译 EF Core in Action 1.9] 掀开EF Core的引擎盖看看EF Core内部是如何工作的
Entity Framework Core in Action Entityframework Core in action是 Jon P smith 所著的关于Entityframework Cor ...
- ADO.NET 基础学习笔记1
1. ODBC.OLEDB.ADO.ADO.NET之间的关系 ODBC: 开放数据库互连(ODBC)是MICROSOFT提出的数据库访问接口标准.ODBC(Open DatabaseConnectiv ...
- 设计模式之适配者模式——Java语言描述 | Amos H's blog
适配器模式是作为两个不兼容的接口之间的桥梁.这种类型的设计模糊属于结构性模式,它结合了两个独立接口的功能 概念阐述 使用适配器模式可以解决在软件系统中,将一些旧的类放入新环境中,但是新环境要求的接口旧 ...