简易调色盘控件 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 控制可以消耗大量的内存开销,除非你仔细地使用它. 在客户有限的内存,你 ...
随机推荐
- jackson json转对象 json转集合 对大小写支持
@JsonAutoDetect(fieldVisibility = Visibility.ANY, getterVisibility = Visibility.NONE, isGetterVisibi ...
- python yield用法 (tornado, coroutine)
yield关键字用来定义生成器(Generator),其具体功能是可以当return使用,从函数里返回一个值,不同之处是用yield返回之后,可以让函数从上回yield返回的地点继续执行.也就是说,y ...
- 带着新人看java虚拟机07(多线程篇)
这一篇说一下比较枯燥的东西,为什么说枯燥呢,因为我写这都感觉很无聊,无非就是几个阻塞线程的方法和唤醒线程的方法... 1.线程中断 首先我们说一说怎么使得一个正在运行中的线程进入阻塞状态,这也叫做线程 ...
- Promise (1) 如何使用Promise
Promise 也是面试高频问题, 今天我们来看看Promise是什么, 能做什么, 怎么用, 下一期我们自己来模拟一个myPromise 1 Promise 是什么 我们要学会自己给自己提问, 才 ...
- 【ODI】| 数据ETL:从零开始使用Oracle ODI完成数据集成(三)
资料库的创建.体系结构的创建.模型反向工程都已经完成了,下面就是创建以及执行接口来完成工作了. 浏览前两节请点击: [ODI]| 数据ETL:从零开始使用Oracle ODI完成数据集成(一) [OD ...
- 腾讯云发布runC容器逃逸漏洞修复公告
尊敬的腾讯云客户,您好: 近日,腾讯云安全中心监测发现轻量级容器运行环境runc被爆存在容器逃逸漏洞,攻击者可以在利用该漏洞覆盖Host上的runc文件,从而在Host上以root权限执行代码. 为 ...
- mysql开发规范(优化)
规范 库名.表名.字段名必须使用小写字母, 并采用下划线分割, 禁止超过32个字符(整齐.易读) 临时库.表名须以tmp加日期为后缀; 使用Innodb存储引擎.[好处: 支持事务和行级锁] 字符集统 ...
- Vue.js-08:第八章 - 组件的基础知识
一.前言 在之前的学习中,我们对于 Vue 的一些基础语法进行了简单的了解,通过之前的代码可以清晰的看出,我们在使用 Vue 的整个过程,最终都是在对 Vue 实例进行的一系列操作. 这里就会引出一个 ...
- 购物网站首页(学习ING)
这几天在学着做购物网站,初步的完成了首页的框架吧,记录下.慢慢加强.主要难点,是样式的设置问题,如果自己想,自己摸索,可能会需要很长的调试.也是一个孰能生巧的过程吧,有些部分没有按照学习资料的方法也做 ...
- Android注解框架实战-ButterKnife
文章大纲 Android注解框架介绍 ButterKnife实战 项目源码下载 一.框架介绍 为什么要用注解框架? 在Android开发过程中,我们经常性地需要操作组件,操作方法有findVie ...