Windows Mobile - 吸引人的 UI:第一部分






4.92/5 (10投票s)
Windows Mobile - 吸引人的用户界面(关于 AlphaMobilecontrols 的描述)。
- 下载源代码 - 47.3 KB (包含更新后的
AlphaMobileControls
,具有一些附加功能以及一组新控件)
引言
本文介绍了如何使用 .NET CF 开发具有背景透明度等功能的移动应用程序。 Rémy Baudet 创建了一组控件,可在 AlphaMobileControls 获取。 这些控件提供背景透明图像、图像按钮和标签。 我已将以下项目添加到由 alphamobilecontrols
提供的库中
AlphaButton
AlphaListBox
- 修改了
AlphaImage
控件,使图像可以根据控件的大小进行拉伸
在第一部分,我将描述关于现有 AlphaMobileControls
的详细信息,然后在下一部分,我们将讨论在 AlphaMobileControls
基础上构建控件
背景
移动厚客户端应用程序正变得越来越受欢迎。 当我开始开发客户端应用程序时,我对 .NET Compact Framework 了解不多。 我发现 CF 类库控件不足以创建外观美观的用户界面。 然后我尝试了许多第三方控件 - 其中大多数要么太重无法在手持设备中使用,要么很容易出错(特别是内存泄漏是这些第三方控件的常见问题)。 后来我了解到由 Rémy Baudet 开发的 AlphaMobileControls
。 但是,它们没有我想要的所有功能,即一个可导航的按钮控件和一个用于显示项目列表的列表控件。
Alpha Mobile 控件如何工作!!
AlphaControl
是从 control
基类派生的,而 Alpha 按钮是从 alpha 控件派生的。
public class AlphaControl : Control
public class AlphaButton : AlphaControl
Alpha 控件应放置在 alpha 容器类上 - alphaform
或 alphapanel
。此容器类包含透明度的主要技巧。 它有一个 paint
方法,该方法又会触发所有包含的 alpha 控件的 draw
方法
/// <summary>
/// Handles the Paint event, it is where the magic happens :-)
/// </summary>
public void OnPaint(PaintEventArgs e)
{
if (_backBuffer != null)
{
// We need a Graphics object on the buffer to get an HDC
using (Graphics gxBuffer = Graphics.FromImage(_backBuffer))
{
// Since we nop'd OnPaintBackground, take care of it here
gxBuffer.Clear(_control.BackColor);
Region gxClipBounds = new Region(Rectangle.Ceiling(gxBuffer.ClipBounds));
// Iterates the child control list in reverse order
// to respect the Z-order
for (int i = _control.Controls.Count - 1; i >= 0; i--)
{
// Handle controls inheriting AlphaControl only
AlphaControl ctrl = _control.Controls[i] as AlphaControl;
if (ctrl == null)
continue;
// Something to draw?
Rectangle clipRect =
Rectangle.Intersect(e.ClipRectangle, ctrl.Bounds);
if (clipRect.IsEmpty)
continue;
// Clip to the control bounds
gxBuffer.Clip = new Region(clipRect);
// Perform the actual drawing
ctrl.DrawInternal(gxBuffer);
}
// Restore clip bounds
gxBuffer.Clip = gxClipBounds;
}
// Put the final composed image on screen.
e.Graphics.DrawImage
(_backBuffer, e.ClipRectangle, e.ClipRectangle, GraphicsUnit.Pixel);
}
else
{
// This should never happen, should it?
e.Graphics.Clear(_control.BackColor);
}
}
}
AlphaControl
继承自 Control
类并隐藏自身。
/// <summary>
/// Default constructor.
/// </summary>
public AlphaControl()
{
base.Visible = false;
}
它有一个名为 drawinternal
的方法,该方法是从其父容器(AlphaPanel
或 AlphaForm
)调用的。 此 drawinteral
方法调用派生类的 draw
方法。 draw
方法使用诸如 drawstring
、drawrectangle
、drawline
之类的方法在容器上绘制/绘制控件。
/// <summary>
/// Internal Draw method, called by the container.
/// Will call the actual Draw method if the control is visible.
/// </summary>
internal void DrawInternal(Graphics gx)
{
if (_visible)
Draw(gx);
}
/// <summary>
/// Must be overridden.
/// </summary>
public virtual void Draw(Graphics gx)
{
}
第二部分和第三部分将包含什么
我将发布更多文章
- 第二部分将包含
AlphaImage
控件 - 第三部分将包含
AlphaButton
、AlphaListBox
和其他控件。 一旦发布了这些文章,我将使用链接更新本文。
关注点
AlphaMobile 控件一直是一个非常有趣且具有扩展功能和控件集合潜力的开发项目。 一些可能的增强功能可以是为控件提供设计器支持。 这在使用 Alpha Datagrid 控件或其他列表控件时非常有用。
历史
- 2009 年 9 月 17 日:初始帖子