试验平台:.Net Micro Framework 模拟器
在Microsoft.SPOT.Presentation.Shapes命名空间下,包含几个形状对象,主要有Ellipse、Line、Polygon、Rectangle,同样也只有Rectangle实现的最好,其他形状都不支持填充色,虽然每个对象都有Fill属性。
让人奇怪的是,每个形状对象都不能设置left和top坐标,仅能设置宽度和高度,用起来很不习惯。
StackPanel类是Panel的派生类,从字面意思上看,就是可以堆叠的面板。意如其名,它可以包含多个子对象,不过每一对象都不能重叠,以特有的方式堆叠在一起。
有如下几个属性方法控制堆叠方式:
1、 Orientation属性,有两种方式:Orientation.Horizontal,Orientation.Vertical。设置该属性后,StackPanel的子对象的坐标系就会发生变化(很可惜字体的方向并没有从根本上改变)。
2、 HorizontalAlignment、VerticalAlignment属性,设置子对象的堆叠方式。枚举定义如下。
public enum HorizontalAlignment
{
Left = 0,
Center = 1,
Right = 2,
Stretch = 3,
}
public enum VerticalAlignment
{
Top = 0,
Center = 1,
Bottom = 2,
Stretch = 3,
}
3、 SetMargin方法,设置边界空白大小。
完整的代码如下,
using System;
using Microsoft.SPOT;
using Microsoft.SPOT.Input;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Presentation.Shapes;
namespace MFWindow
{
public class Program : Microsoft.SPOT.Application
{
public static void <place w:st="on">Main</place>()
{
//创建窗体
WindowsDrawing win = new WindowsDrawing();
//程序运行
new Program().Run(win);
}
internal sealed class WindowsDrawing : Window
{
public WindowsDrawing()
{
this.Width = SystemMetrics.ScreenWidth;
this.Height = SystemMetrics.ScreenHeight;
//可设置显示方向(水平,垂直)
//StackPanel panel = new StackPanel(Orientation.Vertical);
StackPanel panel = new StackPanel(Orientation.Horizontal);
//设置边界空白
panel.SetMargin(10);
//设置对象堆叠的方式
panel.HorizontalAlignment = HorizontalAlignment.Center;
panel.VerticalAlignment = VerticalAlignment.Center;
this.Child = panel;
//添加文本
Text txt = new Text(Resources.GetFont(Resources.FontResources.small), "yefan");
//不能设置left,top坐标
txt.Width = 100;
txt.Height = 30;
panel.Children.Add(txt);
//添加不同的形状对象
Shape[] shapes = new Shape[]
{
new Ellipse(),
new Line(),
new Polygon(new Int32[] { 0, 0, 10, 0, 10, 10, 0, 10 }),
new Rectangle()
};
//设置形状对象必要的参数(各对象不能重叠,只能堆叠在一起)
foreach (Shape s in shapes)
{
s.Fill = new SolidColorBrush(ColorUtility.ColorFromRGB(0, 255, 0));
s.Stroke = new Pen(Color.Black, 2);
//不能设置left,top坐标
s.Height = 40;
s.Width = 40;
panel.Children.Add(s);
}
}
}
}
}
仅修改这句代码 StackPanel panel = new StackPanel(Orientation.Horizontal);中的参数就可以实现两种不同的效果,如下面两图所示:
<shapetype id="_x0000_t75" stroked="f" filled="f" path="m@4@5l@4@11@9@11@9@5xe" o:preferrelative="t" o:spt="75" coordsize="21600,21600"><stroke joinstyle="miter"></stroke><formulas><f eqn="if lineDrawn pixelLineWidth 0"></f><f eqn="sum @0 1 0"></f><f eqn="sum 0 0 @1"></f><f eqn="prod @2 1 2"></f><f eqn="prod @3 21600 pixelWidth"></f><f eqn="prod @3 21600 pixelHeight"></f><f eqn="sum @0 0 1"></f><f eqn="prod @6 1 2"></f><f eqn="prod @7 21600 pixelWidth"></f><f eqn="sum @8 21600 0"></f><f eqn="prod @7 21600 pixelHeight"></f><f eqn="sum @10 21600 0"></f></formulas><path o:connecttype="rect" gradientshapeok="t" o:extrusionok="f"></path><lock aspectratio="t" v:ext="edit"></lock></shapetype><shape id="_x0000_i1026" style="WIDTH: 414.75pt; HEIGHT: 241.5pt" type="#_x0000_t75"><imagedata o:title="MF071106001" src="file:///C:/DOCUME~1/%E5%8F%B6%E5%B8%86/LOCALS~1/Temp/msohtml1/01/clip_image001.jpg"></imagedata></shape>
<shape id="_x0000_i1025" style="WIDTH: 414.75pt; HEIGHT: 241.5pt" type="#_x0000_t75"><imagedata o:title="MF071106002" src="file:///C:/DOCUME~1/%E5%8F%B6%E5%B8%86/LOCALS~1/Temp/msohtml1/01/clip_image002.jpg"></imagedata></shape>
总的来说,我觉得MF提供的图像对象还很不完善,不仅一些基本功能没有完成(如填充、线宽),并且无法设置形状对象的绝对坐标(left,top),同时总类也特别少,希望以后的版本中能有很大的提升。
<iframe align="center" marginwidth="0" marginheight="0" src="http://www.zealware.com/csdnblog.html" frameborder="0" width="728" scrolling="no" height="90"></iframe>
相关推荐
Unity插件Shapes最新版 4.2.1
alpha shapes提取点云边界特征(C++版本)基于PCL库写的alpha shapes算法,具体实现原理参考:https://blog.csdn.net/qq_36686437/article/details/115168516或者参考论文:[1]刘科. 平面点云边界提取算法研究[D].长沙...
Shapes2
教程《Blender图解教程:使用Orient bone shapes插件轻松解决设置骨骼自定义形状(Bone Custom Shapes)时的各种痛点》地址:https://orzgame.blog.csdn.net/article/details/109734778
Shapes1
Programming Excel with VBA and .NET Preface Part I: Learning VBA Chapter 1. Becoming an Excel Programmer Section 1.1. Why Program? Section 1.2. Record and Read Code Section 1.3. Change ...
Mega Shapes - 神奇的卡通场景与模型制作工具,注意这是一款Unity3d 插件,非模型 制作一个赛车游戏?完全没有问题。 为道路画一条线,画一个截面,就能制作出道路。 添加障碍或扭曲他们,可任意发挥你的想象力!...
Shapes is a real-time vector graphics library with high-quality line drawing and infinite resolution shapes, rendered with advanced anti-aliasing techniques
Shapes 是一款实时向量图库,带有高质量的线条画和无限分辨率的图形,并以高级的抗锯齿技术渲染 功能特色 高质量的线条画,带有随机厚度以及高级抗锯齿 • 可指定厚度单位为米、像素或节点 • 2D 形状,比如多段线、...
MacDonald will take you through a thorough investigation of the more advanced aspects of WPF, and its relation to other elements of the WinFX stack and the .NET Framework 3.5, to complete your ...
Serge Belongie大作, Matching Shapes,形状上下文论文
基于openGL的图形学相关性研究Numerical Geometry of Non-Rigid Shapes
jquery.roundabout-shapes 5.js
Shapes 是一款实时向量图库,带有高质量的线条画和无限分辨率的图形,并以高级的抗锯齿技术渲染
Excel-VBA常用技巧-第04章shape(图形)、Chart(图表)对象.docx
通过train_shapes.ipynb可以在平台jupyter notebook上进行训练,同时也可以在平台jupyter notebook上将文件转换为python文件,中包括ap.map的计算。
与我的博客上的文章的配套资源,谢谢大家的下载,可以参考这篇博客http://blog.csdn.net/bboot/article/details/29926219
Pro WPF Windows Presentation Foundation in.NET 3.0(PDF) 900多页。 目录: ■CHAPTER 1 Introducing WPF ■CHAPTER 2 XAML ■CHAPTER 3 The Application ■CHAPTER 4 Layout ■CHAPTER 5 Content ■CHAPTER 6...
The final sections describe two powerful new graphic tools that were introduced with .NET Framework 3.0: WPF graphics and FlowDocuments. WPF applications can use XAML graphic commands to declaratively...
牛津小学英语五年级上册unit7shapes说课设计.pdf