简易调色盘控件 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_1196_[HNOI2006]公路修建问题_kruskal+二分答案
BZOJ_1196_[HNOI2006]公路修建问题_kruskal+二分答案 题意:http://www.lydsy.com/JudgeOnline/problem.php?id=1196 分析: ...
- 面试必问!Java 多线程中两个线程交替执行,一个输出偶数,一个输出奇数
前言 楼主今天在面经上看到这个题,挺有意思,小小的题目对多线程的考量还挺多.大部分同学都会使用 synchronized 来实现.楼主今天带来另外两种优化实现,让你面试的时候,傲视群雄! 第一种 sy ...
- Django文件上传(经典上传方式)
经典文件上传方式 创建URL from django.contrib import admin from django.urls import path from django.conf.urls i ...
- 神奇的Scala Macro之旅(四)- BeanBuilder
在Java开发中,经常会有一个需求,将一个 Bean 复制到另外一个 Bean,尤其是在后台分层的场景下,在不同的层之间传递信息,经常需要进行 这样的一个对象复制工作,类似于: val source: ...
- 死磕 java集合之PriorityBlockingQueue源码分析
问题 (1)PriorityBlockingQueue的实现方式? (2)PriorityBlockingQueue是否需要扩容? (3)PriorityBlockingQueue是怎么控制并发安全的 ...
- 无敌简单快速的文件服务器sgfs
前言 想要构建一个Linux文件服务器?看看下面几个要求是不是你想要的? 1.只需要单节点部署就够了 2.部署启动简单,下载之后,一键启动,一键关闭 3.不需要任何其他的依赖安装,而且运行时占用内存资 ...
- Win64下编译OSG详细过程(Win10+VS2015+OSG3.6.3)
目录 1. 数据资源准备 2. 编译第三方库 3. 编译GDAL 4. 编译OSG 1) CMAKE_INSTALL_PREFIX: 2) BUILD_OSG_EXAMPLES/BUILD_MFC_ ...
- 【Oracle RAC】Linux系统Oracle11gR2 RAC安装配置详细过程V3.1(图文并茂)
[Oracle RAC]Linux系统Oracle11gR2 RAC安装配置详细过程V3.1(图文并茂) 2 Oracle11gR2 RAC数据库安装准备工作2.1 安装环境介绍2.2 数据库安装软件 ...
- 2018-08-20 中文代码之Spring Boot集成H2内存数据库
续前文: 中文代码之Spring Boot添加基本日志, 源码库地址相同. 鉴于此项目中的数据总量不大(即使万条词条也在1MB之内), 当前选择轻量级而且配置简单易于部署的H2内存数据库比较合理. 此 ...
- Lenovo System x3650 设置管理接口地址
1.开启服务器. 2.显示<F1> Setup提示后,按 F1.(此提示在屏幕上仅显示几秒钟.必须迅速按 F1.) 如果同时设置了开机密码和管理员密码,则必须输入管理员密码才能访问完整的 ...