2016.1.1 VS中宏的使用技巧点滴

本文介绍了一系列在Visual Studio Code环境中高效操作文本的方法,包括选择文本、插入文本、文本替换等实用技巧,并展示了如何通过简单的宏命令自动生成特定的代码结构。

Dim selection As TextSelection = DTE.ActiveDocument.Selection'定义 TextSelection 对象

 

selection.StartOfLine()'移动到当前光标所在行的起始位置

 

Dim keyword = selection.Text.Trim()'取得整行文本

       

'获取当前选择首点所在行

Dim endLine As Integer

endLine = selection.TopPoint.Line

 

selection.NewLine()'插入一行空白行

 

selection.LineUp()'将光标移回到新空白行

 

selection.GotoLine(startLine) '将光标位置跳至某行的起始位置

 

selection.MoveToLineAndOffset(startLine,10 )'将光标跳至某行的起始位置+10个字符处

 

selection.LineDown(True, 18) '将选择位置向下移18行,true表示将选择范围进行扩展,选择的起始位置不变,终止位置下移18行

selection.CharRight(True,5) ’与上面类似,将选择范围向右扩展5个字符

 

'VB语法输入多段文本只能用" & Chr(13) & _ 连接的方法

 

'在选择范围中进行文本替换

DTE.Find.Action = vsFindAction.vsFindActionReplaceAll

DTE.Find.Target = vsFindTarget.vsFindTargetCurrentDocumentSelection

DTE.Find.FindWhat = "dvxxxdv"

DTE.Find.ReplaceWith = keyword

DTE.Find.Execute()

 

DTE.Find.Target = vsFindTarget.vsFindTargetCurrentDocument '定义搜索范围,注意:默认是vsFindTargetCurrentDocumentSelection,只在当前选中文本中查找,vsFindTargetCurrentDocument表示全文查找

DTE.Find.Backwards = True '向上还是向下,默认居然是向上

DTE.Find.Action = vsFindAction.vsFindActionFind

DTE.Find.FindWhat = "{"

DTE.Find.Execute()

 

MsgBox(selection.Text.Trim())'弹出提示框

 

实例:

Imports System

Imports EnvDTE

Imports EnvDTE80

Imports EnvDTE90

Imports EnvDTE90a

Imports EnvDTE100

Imports System.Diagnostics

 

Public Module SkModule

    'sk 2014.8.27 快速输入string.Format

    Sub SQLFormat()

        ActiveDocument.Selection.Text = "string.Format(@""select "",AisLogical.curUser);"

        ActiveDocument.Selection.EndOfLine()

        ActiveDocument.Selection.CharLeft(False, 23)

    End Sub

    'sk 2016.1.8将DataGridview控件加上两个事件替代selectionchanged事件

    Sub DvAddFunc()

        Dim selection As TextSelection = DTE.ActiveDocument.Selection

        '选择整行,注意此时光标焦点落在下一行开始处

        selection.SelectLine()

        '取得整行文本

        Dim keyword = selection.Text.Trim()

 

        selection.Text = ""

        '插入一行空白行

        selection.NewLine()

        '将光标移回到新空白行

        selection.LineUp()

 

        Dim startLine As Integer

        '获取selection末端行号

        startLine = selection.BottomPoint.Line

 

 

        'VB语法输入多段文本只能用" & Chr(13) & _连接的方法

        '注意在输入过程中VS环境可能会自动将某些看似语法错误的表达式替换成貌似正确的表达式,可能跟插入文本原文不一致

        selection.Text = "//将下面两行剪切到该Dv控件所在窗体的Designer.cs文件中的InitializeComponent()函数末尾" & Chr(13) & _

        "this.dvxxxdv.CellClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dvxxxdv_CellClick);" & Chr(13) & _

        "this.dvxxxdv.KeyUp += new System.Windows.Forms.KeyEventHandler(this.dvxxxdv_KeyUp);" & Chr(13) & _

        "public void zMySelectionChanged_dv()" & Chr(13) & _

        "{" & Chr(13) & _

        "if (dvxxxdv.SelectedRows.Count == 0) return;" & Chr(13) & _

        "}" & Chr(13) & _

        "private void dvxxxdv_CellClick(object sender, DataGridViewCellEventArgs e)" & Chr(13) & _

        "{" & Chr(13) & _

        "if (e.RowIndex < 0) return;//如果不是单击列表头" & Chr(13) & _

        "zMySelectionChanged_dv();" & Chr(13) & _

        "}" & Chr(13) & _

        "" & Chr(13) & _

        "private void dvxxxdv_KeyUp(object sender, KeyEventArgs e)" & Chr(13) & _

        "{" & Chr(13) & _

        "if (e.KeyData == Keys.Down || e.KeyData == Keys.Up)" & Chr(13) & _

        "zMySelectionChanged_dv();            " & Chr(13) & _

        "}" & Chr(13)

 

        '将选择起始位置重新设回文本插入前的位置

        selection.GotoLine(startLine)

        selection.LineDown(True, 18)

 

        '在选择范围中进行文本替换

        DTE.Find.Action = vsFindAction.vsFindActionReplaceAll

        DTE.Find.Target = vsFindTarget.vsFindTargetCurrentDocumentSelection

        DTE.Find.FindWhat = "dvxxxdv"

        DTE.Find.ReplaceWith = keyword

        DTE.Find.Execute()

    End Sub

 

    'sk 2016.1.9将选择的范围加上#region结构

    Sub AddRegion()

        Dim selection As TextSelection = DTE.ActiveDocument.Selection '定义TextSelection 对象

 

        Dim startLine As Integer

        startLine = selection.TopPoint.Line

        Dim endLine As Integer

        endLine = selection.BottomPoint.Line

 

        selection.GotoLine(startLine) '将光标位置跳至某行的起始位置

        selection.Text = "#region" + Chr(13)

 

        selection.GotoLine(endLine + 1) '将光标位置跳至某行的起始位置

        selection.EndOfLine()

        selection.NewLine()

        selection.Text = "#endregion"

 

    End Sub

 

    'sk 2016.1.10将当前光标所在模块加上#region结构

    Sub RegionOnBlock()

        Dim selection As TextSelection = DTE.ActiveDocument.Selection '定义TextSelection 对象

        Dim startline As Integer

        startline = -1

        Dim endline As Integer

        endline = -1

 

        Dim currentline As Integer = selection.ActivePoint.Line

 

        selection.EndOfDocument() '将选择行移到最末一行

        Dim documentlines As Integer = selection.ActivePoint.Line '整篇文档总行数

 

        selection.GotoLine(currentline) '此时光标会停留在行首,如果加上,true参数整行将选择,选择的起始位置保持在行首和末尾

 

        Dim kuohaoleft = 0 '从初始位置到当前位置共出现过几次{

 

        selection.SelectLine()

        selection.CharLeft(True)

        Dim tx As String = selection.Text.Trim()

        If (tx = "{") Then

            kuohaoleft = 1

            startline = selection.ActivePoint.Line

        ElseIf (tx.IndexOf("{") >= 0) Then

            MsgBox("光标所在行的'{'没有单独占一行,请重新选择行")

            Return

        Else

            Do While kuohaoleft <= 0

                '以下行为上移整行选择,选择的起始位置在行首和末尾,如果没有第句,选择末端会停留在下一行,也可用selection.GotoLine(xxline,true)实现

                selection.LineUp()

                selection.SelectLine()

                selection.CharLeft(True)

 

                tx = selection.Text.Trim()

                If (tx = "{") Then

                    kuohaoleft += 1

                ElseIf (tx = "}") Then

                    kuohaoleft -= 1

                End If

 

                If (selection.ActivePoint.Line = 1) Then Exit Do

            Loop

            If (kuohaoleft = 1) Then

                startline = selection.ActivePoint.Line

            Else

                MsgBox("从当前位置以上没有出现单独一行的'{'")

                Return

            End If

        End If

 

        '此时光标停留在初始位置往上真实的第一个{处

 

        kuohaoleft = 1 '其实运行到这里肯定kuohaoleft=1

 

        Do While (kuohaoleft > 0)

            selection.LineDown()

            selection.SelectLine()

            selection.CharLeft(True)

 

            tx = selection.Text.Trim()

            If (tx = "{") Then

                kuohaoleft += 1

            ElseIf (tx = "}") Then

                kuohaoleft -= 1

            End If

            If (selection.ActivePoint.Line = documentlines) Then Exit Do

        Loop

 

        If (kuohaoleft = 0) Then

            endline = selection.ActivePoint.Line

        Else

            MsgBox("从当前位置以下没有出现单独一行的'}'")

            Return

        End If

 

        If (endline > startline And startline > 0) Then

 

            selection.GotoLine(startline)

            selection.EndOfLine()

            selection.Text = Chr(13) + "#region"

 

            selection.GotoLine(endline)

            selection.EndOfLine()

            selection.Text = Chr(13) + "#endregion"

 

            '将光标放置到起始{行的末尾

            selection.GotoLine(startline)

            selection.EndOfLine()

 

        End If

 

    End Sub

 

End Module

转载于:https://www.cnblogs.com/mol1995/p/5964945.html

一、数据采集层:多源人脸数据获取 该层负责从不同设备 / 渠道采集人脸原始数据,为后续模型训练与识别提供基础样本,核心功能包括: 1. 多设备适配采集 实时摄像头采集: 调用计算机内置摄像头(或外接 USB 摄像头),通过OpenCV的VideoCapture接口实时捕获视频流,支持手动触发 “拍照”(按指定快捷键如Space)或自动定时采集(如每 2 秒采集 1 张),采集时自动框选人脸区域(通过Haar级联分类器初步定位),确保样本聚焦人脸。 支持采集参数配置:可设置采集分辨率(如 640×480、1280×720)、图像格式(JPG/PNG)、单用户采集数量(如默认采集 20 张,确保样本多样性),采集过程中实时显示 “已采集数量 / 目标数量”,避免样本不足。 本地图像 / 视频导入: 支持批量导入本地人脸图像文件(支持 JPG、PNG、BMP 格式),自动过滤非图像文件;导入视频文件(MP4、AVI 格式)时,可按 “固定帧间隔”(如每 10 帧提取 1 张图像)或 “手动选择帧” 提取人脸样本,适用于无实时摄像头场景。 数据集对接: 支持接入公开人脸数据集(如 LFW、ORL),通过预设脚本自动读取数据集目录结构(按 “用户 ID - 样本图像” 分类),快速构建训练样本库,无需手动采集,降低系统开发与测试成本。 2. 采集过程辅助功能 人脸有效性校验:采集时通过OpenCV的Haar级联分类器(或MTCNN轻量级模型)实时检测图像中是否包含人脸,若未检测到人脸(如遮挡、侧脸角度过大),则弹窗提示 “未识别到人脸,请调整姿态”,避免无效样本存入。 样本标签管理:采集时需为每个样本绑定 “用户标签”(如姓名、ID 号),支持手动输入标签或从 Excel 名单批量导入标签(按 “标签 - 采集数量” 对应),采集完成后自动按 “标签 - 序号” 命名文件(如 “张三
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值