惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

N
Netflix TechBlog - Medium
V
Vulnerabilities – Threatpost
Google Online Security Blog
Google Online Security Blog
Hugging Face - Blog
Hugging Face - Blog
L
LINUX DO - 热门话题
云风的 BLOG
云风的 BLOG
P
Proofpoint News Feed
D
Docker
C
Cyber Attacks, Cyber Crime and Cyber Security
MyScale Blog
MyScale Blog
P
Palo Alto Networks Blog
T
Tenable Blog
P
Privacy International News Feed
Google DeepMind News
Google DeepMind News
小众软件
小众软件
Cisco Talos Blog
Cisco Talos Blog
aimingoo的专栏
aimingoo的专栏
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
A
Arctic Wolf
C
Cybersecurity and Infrastructure Security Agency CISA
C
Cisco Blogs
T
Threat Research - Cisco Blogs
NISL@THU
NISL@THU
The Hacker News
The Hacker News
Project Zero
Project Zero
AWS News Blog
AWS News Blog
Simon Willison's Weblog
Simon Willison's Weblog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
T
Threatpost
V
Visual Studio Blog
The GitHub Blog
The GitHub Blog
The Cloudflare Blog
Last Week in AI
Last Week in AI
Jina AI
Jina AI
Cyberwarzone
Cyberwarzone
The Register - Security
The Register - Security
C
CXSECURITY Database RSS Feed - CXSecurity.com
Vercel News
Vercel News
D
Darknet – Hacking Tools, Hacker News & Cyber Security
MongoDB | Blog
MongoDB | Blog
U
Unit 42
Scott Helme
Scott Helme
A
About on SuperTechFans
WordPress大学
WordPress大学
F
Fortinet All Blogs
大猫的无限游戏
大猫的无限游戏
G
GRAHAM CLULEY
Latest news
Latest news
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
S
Schneier on Security

博客园 - Duan Junyi

招聘.net 架构师和项目经理 招聘.net/silverlight/wpf开发人员-HP 12月初在微软维亚大厦做的WPF,Silverlight培训资料下载 8月25日上午10点Webcast:Windows 7开发系列课程(1):Windows7新特性开发概览(Level 300) Windows 安全体系部分概述以及windows兼容性开发培训录像 OpenSearch for MSDN via Windows 7 Search Federation 简单写了一个windows7 native boot step bystep的文档 wpf/sl的overview资料 下载 Silverlight2 for mobile?? 12月4日上海IE8开发培训资料下载 用silverlight2.0给微软DPE做的一个简单的demo,欢迎下载 [分享视频下载]11月29日高阳和我在北京邮电大学的演讲(IT职业规划和软件加服务) 11月22日北京.net俱乐部活动ppt下载以及11月19日微软西格玛IE8开发讲座ppt下载 2008年11月22日北京.net俱乐部活动,欢迎大家用livemeeting收听 (已经结束) 微软TECHED2008 我的讲座:DEV354使用VSTS快速开发高性能WPF复合应用程序的PPT 经过修改MSN2009安装包,终于把最新版MSN安装到window server 2008下了 6月28日北京.net俱乐部活动小记以及PPT下载 silverlight2.0之--------基本控件 4月22日上午在西格玛三楼的讲座(wcf,wf,silverlight,cardspace)
silverlight2 beta 2 实现简单的手写功能
Duan Junyi · 2008-06-17 · via 博客园 - Duan Junyi

silverlight beta2 刚出来不久,变化很大,sdk里面的例子也不是很丰富

下面简单用托管代码写了一个小demo来实现手写功能,(SDK上面有个用js写的),效果如下:

准备:
安装
Install Visual Studio 2008
Install Silverlight Tools Beta 2 for Visual Studio 2008

新建一个silverlight工程。
在xaml页面加入一个

InkPresenter 控件,这个例子主要是对InkPresenter控件进行操作
把下面代码复制到xaml页面

 <Grid x:Name="LayoutRoot" Background="BlueViolet">
        
<StackPanel>
<InkPresenter x:Name="inkCanvas"  Width="300" Height="200" Margin="50" MouseLeftButtonDown="inkCanvas_MouseLeftButtonDown" Background="Khaki"  MouseMove="inkCanvas_MouseMove" MouseLeftButtonUp="inkCanvas_MouseLeftButtonUp" MouseLeave="inkCanvas_MouseLeave">
            


        
</InkPresenter>
           
                
<Button x:Name="btnInk" Content="画笔"  Width="50" Height="20"  Click="btnInk_Click"></Button>
            
<Button x:Name="btnErase" Content="橡皮"  Width="50" Height="20" Click="btnErase_Click"></Button>    
       
</StackPanel>
    
</Grid>

下面就是通过写c#代码来操作了
注意到上面的InkPresenter控件里面有操作鼠标的方法,下面我们一个一个说
第一个方法inkCanvas_MouseLeftButtonDown
当鼠标左键按下去的时候开始取得当前坐标开始划线,这个方法的代码如下:

    private void inkCanvas_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        
{
            inkCanvas.CaptureMouse();
            Point p 
= e.GetPosition(inkCanvas);
            StylusPoint sp 
= new StylusPoint();
            sp.X 
= p.X;
            sp.Y 
= p.Y;
            
if (_isErase)//判断是不是橡皮
            {
                _epoint 
= new StylusPointCollection();
                _epoint.Add(sp);
              
            }

            
else
            
{
                _stroke 
= new Stroke();
                _stroke.StylusPoints.Add(e.StylusDevice.GetStylusPoints(inkCanvas));
                _stroke.DrawingAttributes 
= new DrawingAttributes();
//属性赋值
                _stroke.DrawingAttributes.Color = Colors.Black;
                _stroke.DrawingAttributes.Width 
= 2.00;
                _stroke.DrawingAttributes.Height 
= 2.00;
                _stroke.DrawingAttributes.OutlineColor 
= Colors.Green;
                inkCanvas.Strokes.Add(_stroke);
            
            }

        }

写完这个方法以后,当鼠标左键点击的时候就会往页面上画点。那么我们怎么移动画线呢,写mousemove事件inkCanvas_MouseMove,代码如下

    private void inkCanvas_MouseMove(object sender, MouseEventArgs e)
        
{
            Point p 
= e.GetPosition(inkCanvas);
          
            StylusPoint sp 
= new StylusPoint();
            sp.X 
= p.X;
            sp.Y 
= p.Y;
//也可以用  
// e.StylusDevice.GetStylusPoints(inkCanvas)
//来得到
            if (_isErase)
            
{
                
if (_epoint != null)
                
{

                    _epoint.Add(sp);
                    StrokeCollection sc 
= inkCanvas.Strokes.HitTest(_epoint);
                    
for (int i = 0; i < sc.Count; i++)
                    
{
                        
this.inkCanvas.Strokes.Remove(sc[i]);
                    }

                }

            }

            
else
            
{
                
if (_stroke != null)
                
{
                    _stroke.StylusPoints.Add(sp);
                }

            }

        }

最后一步实现鼠标左键松开的事件inkCanvas_MouseLeftButtonUp

  private void inkCanvas_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        
{
            
if (_stroke != null)
            
{
             Point pos 
= e.GetPosition(inkCanvas);
                StylusPoint sp 
= new StylusPoint();
                sp.X 
= pos.X;
                sp.Y 
= pos.Y;
                _stroke.StylusPoints.Add(sp);
            }

            
this.inkCanvas.ReleaseMouseCapture();
            _stroke 
= null;
            _epoint 
= null;
        }

大概就这样,大家根据这个进行扩展就行了
完整的代码我发到这个帖子里面了
http://bbs.crfly.com/showtopic-6552.aspx