升星了,散分庆祝一下。附一个类Iphone闹钟的时间选择控件

LorenLiu 2010-11-08 01:01:20
终于脱掉了5个小裤衩。。。。

前一段时间有人问过如何弄一个类似Iphone的list control,这两天写了一个,贴出来分享一下,不过功能还未完善。


public partial class CustomListControl : Control
{
public CustomListControl()
{
InitializeComponent();
SetStyle(ControlStyles.Selectable, true);
SetStyle(
ControlStyles.AllPaintingInWmPaint |
ControlStyles.OptimizedDoubleBuffer |
ControlStyles.UserPaint,
true
);
}

protected override void OnPaint(PaintEventArgs pe)
{
base.OnPaint(pe);

// Draw background
Rectangle clientRect = new Rectangle(
kBorderWidth,
kBorderWidth,
this.ClientRectangle.Width - 2 * kBorderWidth,
this.ClientRectangle.Height - 2 * kBorderWidth
);

using (LinearGradientBrush b = new LinearGradientBrush(
clientRect,
Color.Black,
Color.White,
90f)
)
{
Blend blend = new Blend();
blend.Positions = new float[] { 0.0f, 0.04f, 0.08f, 0.12f, 0.15f, 0.5f, 0.85f, 0.88f, 0.92f, 0.96f, 1f };
blend.Factors = new float[] { .2f, .4f, 0.6f, 0.8f, 0.85f, 0.95f, .85f, .8f, .6f, .4f, .2f };
b.Blend = blend;
pe.Graphics.FillRectangle(b, clientRect);
}

// Draw border
using (Pen p = new Pen(Color.FromArgb(127, 127, 127)))
{
p.Width = kBorderWidth;
pe.Graphics.DrawRectangle(
p,
new Rectangle(
kBorderWidth / 2,
kBorderWidth / 2,
this.Width - kBorderWidth,
this.Height - kBorderWidth
)
);
}


// Draw selected focus
Rectangle selectedBound = new Rectangle(
this.ClientRectangle.X,
this.ClientRectangle.Y + ((Int32)m_DisplayItemCount / 2) * this.ClientRectangle.Height / (Int32)m_DisplayItemCount,
this.ClientRectangle.Width,
this.ClientRectangle.Height / (Int32)m_DisplayItemCount
);
using (Pen p = new Pen(Color.FromArgb(100, 100, 100, 100)))
{
pe.Graphics.DrawLine(
p,
new Point(selectedBound.X, selectedBound.Y),
new Point(selectedBound.X + selectedBound.Width, selectedBound.Y)
);
}
using (Pen p = new Pen(Color.FromArgb(100, 250, 250, 250)))
{
pe.Graphics.DrawLine(
p,
new Point(selectedBound.X, selectedBound.Y + 1),
new Point(selectedBound.X + selectedBound.Width, selectedBound.Y + 1)
);
}

using (Pen p = new Pen(Color.FromArgb(100, 100, 100, 100)))
{
pe.Graphics.DrawLine(
p,
new Point(selectedBound.X, selectedBound.Y + selectedBound.Height - 2),
new Point(selectedBound.X + selectedBound.Width, selectedBound.Y + selectedBound.Height - 2)
);
}
using (Pen p = new Pen(Color.FromArgb(100, 250, 250, 250)))
{
pe.Graphics.DrawLine(
p,
new Point(selectedBound.X, selectedBound.Y + selectedBound.Height - 1),
new Point(selectedBound.X + selectedBound.Width, selectedBound.Y + selectedBound.Height - 1)
);
}

using (Brush b = new SolidBrush(Color.FromArgb(100, 255, 255, 255)))
{
pe.Graphics.FillRectangle(
b,
new Rectangle(
selectedBound.X,
selectedBound.Y + 2,
selectedBound.Width,
selectedBound.Height / 2 - 2
)
);
}

using (Brush b = new SolidBrush(Color.FromArgb(100, 180, 180, 180)))
{
pe.Graphics.FillRectangle(
b,
new Rectangle(
selectedBound.X,
selectedBound.Y + selectedBound.Height / 2 + 1,
selectedBound.Width,
selectedBound.Height / 2 - 2
)
);
}

// Draw display items
if (m_Items.Count == 0)
return;

using (Brush b = new SolidBrush(this.ForeColor))
{
for (Int32 i = 0; i < (Int32)m_DisplayItemCount; i++)
{
Rectangle bound = new Rectangle(
clientRect.X,
clientRect.Y + i * clientRect.Height / (Int32)m_DisplayItemCount,
clientRect.Width,
clientRect.Height / (Int32)m_DisplayItemCount
);
Int32 index = m_CurrentIndex + i - (Int32)m_DisplayItemCount / 2;
if (index < 0)
index += m_Items.Count;
if (index >= m_Items.Count)
index %= m_Items.Count;
String item = m_Items[index];
using (StringFormat sf = new StringFormat())
{
sf.Alignment = StringAlignment.Center;
sf.LineAlignment = StringAlignment.Center;
pe.Graphics.DrawString(item, this.Font, b, bound, sf);
}
}

}
}

protected override void OnPreviewKeyDown(PreviewKeyDownEventArgs e)
{
base.OnPreviewKeyDown(e);
switch (e.KeyCode)
{
case Keys.Up:
m_CurrentIndex--;
if (m_CurrentIndex < 0)
m_CurrentIndex += m_Items.Count;
this.Invalidate();
break;
case Keys.Down:
m_CurrentIndex++;
if (m_CurrentIndex >= m_Items.Count)
m_CurrentIndex %= m_Items.Count;
this.Invalidate();
break;
default:
break;
}
}

protected override void OnMouseWheel(MouseEventArgs e)
{
base.OnMouseWheel(e);
m_CurrentIndex -= e.Delta / 120;
NormalizeCurrentIndex();
this.Invalidate();
}

protected override void OnMouseClick(MouseEventArgs e)
{
base.OnMouseClick(e);
Int32 delta = e.Y / (this.ClientRectangle.Height / (Int32)m_DisplayItemCount);
m_CurrentIndex += delta - 2;
NormalizeCurrentIndex();
this.Invalidate();
}

[DefaultValue(0)]
private Int32 CurrentIndex
{
get { return m_CurrentIndex; }
set { m_CurrentIndex = value; }
}

public List<String> Items
{
get { return m_Items; }
}

[DefaultValue(DisplayItemCountEnum.Normal)]
public DisplayItemCountEnum DisplayItemCount
{
get { return m_DisplayItemCount; }
set { m_DisplayItemCount = value; }
}

private void NormalizeCurrentIndex()
{
if (m_CurrentIndex >= m_Items.Count)
m_CurrentIndex %= m_Items.Count;
if (m_CurrentIndex < 0)
m_CurrentIndex += m_Items.Count;
}

private List<String> m_Items = new List<String>();
private Int32 m_CurrentIndex;
private DisplayItemCountEnum m_DisplayItemCount = DisplayItemCountEnum.Normal;
private const Int32 kBorderWidth = 3;

public enum DisplayItemCountEnum
{
Less = 3,
Normal = 5,
More = 7
}
}



测试效果:


现在还有不完善的地方,比如现在只能要求item的个数要大于等于指定的显示item个数,以后慢慢完善。
...全文
543 66 打赏 收藏 转发到动态 举报
写回复
用AI写文章
66 条回复
切换为时间正序
请发表友善的回复…
发表回复
mxjupiter 2011-12-08
  • 打赏
  • 举报
回复
mark一下,学习学习。。。有些东西做了才知道。。。
txblovezbing1314 2011-02-25
  • 打赏
  • 举报
回复
Loren,最近在忙什么啊,很少看见你了哈
ziyelinhaigmail 2011-02-19
  • 打赏
  • 举报
回复
标记学习
amandag 2010-11-09
  • 打赏
  • 举报
回复
学习
fellowcheng 2010-11-09
  • 打赏
  • 举报
回复
think_huang 2010-11-09
  • 打赏
  • 举报
回复
接分咯~
a511900703 2010-11-09
  • 打赏
  • 举报
回复
我是来接分的。
Waldenz 2010-11-09
  • 打赏
  • 举报
回复
裤衩穿很久了/......
Waldenz 2010-11-09
  • 打赏
  • 举报
回复
xuexi..........
shichao102471077 2010-11-09
  • 打赏
  • 举报
回复
  • 打赏
  • 举报
回复
恭喜下 学习下
LeeGang 2010-11-08
  • 打赏
  • 举报
回复
我是来接分的...
tongjoying 2010-11-08
  • 打赏
  • 举报
回复
gongxigongxi
tongjoying 2010-11-08
  • 打赏
  • 举报
回复
gongxigongxi
lastnemo 2010-11-08
  • 打赏
  • 举报
回复
gxgx
SimonYeung 2010-11-08
  • 打赏
  • 举报
回复
liyupengcainiao 2010-11-08
  • 打赏
  • 举报
回复
恭喜恭喜~~~
gaobn001 2010-11-08
  • 打赏
  • 举报
回复
哎 何年何月我也升星
ycproc 2010-11-08
  • 打赏
  • 举报
回复
subxli 2010-11-08
  • 打赏
  • 举报
回复
GX..
加载更多回复(44)
源码链接: https://pan.quark.cn/s/0f7c75cb3aad ### MIPI Video Mode 与 Command Mode 的差异 #### 一、引言 MIPI (Mobile Industry Processor Interface) 是一种用于连接移动设备中处理器及其外围设备的标准化接口。MIPI 接口支持多种协议,其中包含 DSI (Display Serial Interface) 和 DCS (Display Control Interface) 等协议。在 MIPI 接口的应用中,主要涉及两种工作模式:Video Mode(视频模式)和 Command Mode(命令模式)。本文旨在系统性地阐述这两种模式的工作机制、特性以及实际应用环境。 #### 二、LCD RAM 概念说明 在进一步探讨 MIPI 的两种模式之前,有必要对文中提及的“LCD RAM”概念进行明确。实际上,“LCD RAM”并非一个通用术语,而是本文作者用来描述 LCD 控制器中用于存储显示数据的内存区域。LCD(Liquid Crystal Display,液晶显示屏)通常配备一个控制 IC(Integrated Circuit,集成电路),该控制 IC 可能内置 RAM 以缓存显示数据。 #### 三、MIPI Video Mode(视频模式) **定义:** - 视频模式是一种似于传统 RGB 接口的工作模式,它要求主机持续不断地向显示器传输刷新数据。 - 在这种模式下,数据和控制信号以报文的形式通过 MIPI 总线进行传输。 - 显示器本身无需配备帧缓冲器,因为主机会周期性地刷新屏幕。 **特点:** 1. **实时性高:** 主机需要不...
源码下载地址: https://pan.quark.cn/s/a4b39357ea24 在电磁模拟技术中,CST(Computer Simulation Technology)是一种被广泛采纳的软件工具,它主要用于电磁场、微波、天线以及射频系统的设计工作。本资料将详细分析CST软件中离散端口的具体配置方法,这些方法对于提升仿真结果的精确度和专业水准具有决定性作用。离散端口在CST软件中扮演着模拟信号输入或输出的重要角色,它们构成了仿真模型不可或缺的部分。在配置离散端口时,一个核心的原则是保证端口的方向与网格线保持一致,这是因为这样做能够有效降低计算过程中产生的误差,并确保仿真数据的有效性。如果未能遵循这一指导原则,可能会引发未知的计算问题,进而导致仿真结果失去可靠性。 在CST软件中配置离散端口,通常需要借助“Pick Points”这一功能。通过选择“Pick Edge Center”选项,端口将被设定在模型边缘的中心位置上。然而,这种做法并不总是能够确保端口与网格线保持平行。在某些特定情形下,模型的几何构造可能不允许直接选取一个与网格线平行的边作为端口的安装位置。 为了克服这一挑战,可以采用多种不同的策略。如果模型本身已经包含一条与馈电口平行的边,那么可以直接利用这条边来建立端口,此时CST软件会自动调整端口使其与网格线对齐。另一种可选的方法是,当模型不具备现成的平行边时,用户可以手动构建一个几何结构,比如一个立方体,并使其边缘与馈电口平行。通过这种方式,新建立的几何结构的边缘就可以作为端口的位置,从而确保端口与网格线的平行关系。 在实施上述操作时,必须关注端口尺寸的合理性和物理意义的一致性。端口的尺寸应当依据实际天线馈电部分的尺寸进行适当调整,过大的端口或...
代码下载链接: https://pan.quark.cn/s/a4b39357ea24 【使用TensorFlow进行图像识别】 图像识别作为计算机视觉领域的关键任务之一,其核心在于通过算法解析和理解图像所包含的信息。在此资源中,我们将集中探讨如何借助功能强大的深度学习框架TensorFlow来执行手写数字识别。手写数字识别构成了众多实际应用的基础,例如自动支票处理、光学字符识别(OCR)等场景。 TensorFlow是由Google创建的一个开源库,它主要用于数值运算和机器学习,尤其在深度学习方面表现卓越。其核心优势在于可以构建并训练复杂的神经网络架构,并且在多种硬件环境中实现高效执行,涵盖CPU和GPU平台。 在此实践项目中,我们将运用TensorFlow来构建一个卷积神经网络(CNN)模型,这种架构是处理图像数据的理想选择。CNNs通过模仿人脑视觉皮层的运作机制,能够自主地提取图像中的关键特征,进而达成识别目标。在手写数字识别的特定情境下,这些特征可能涉及笔画的几何形态、走向以及相互间的连接模式。 对于CNN的基础结构,我们需要具备相应的认知,其通常由卷积层、池化层、全连接层以及激活函数等部分组成。卷积层借助滤波器(亦称卷积核)对图像进行扫描,以捕捉局部特征;池化层则用于降低数据维度,同时保留核心信息;全连接层将特征向量映射至各别的概率分布;而激活函数如ReLU则通过引入非线性元素,使模型能够学习更为复杂的模式。 在此案例中,建议采用MNIST数据集,这是一个广泛用于手写数字识别的标准测试集。该数据集包含60,000个训练样本和10,000个测试样本,每个样本均为28x28像素的灰度图像,代表0到9这十个数字中的某一个。为了训练模型,必须首先加载数据,并...

7,776

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧