2016.1.1 VS中宏的使用技巧点滴
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
2016.1.1 VS中宏的使用技巧点滴的更多相关文章
- C++ 中宏的使用 --来自:http://blog.csdn.net/hgl868/article/details/7058906
宏在代码中的使用实例: g_RunLog2("Middleware client for Linux, build:%s %s", __DATE__, __TIME__); 下面详 ...
- C语言中宏定义(#define)时do{}while(0)的价值(转)
C语言中宏定义(#define)时do{}while(0)的价值 最近在新公司的代码中发现到处用到do{...}while(0),google了一下,发现Stack Overflow上早有很多讨论,总 ...
- c 语言中宏定义和定义全局变量的区别
宏定义和定义全局变量的区别: 1 作用时间不同. 宏定义在编译期间即会使用并替换,而全局变量要到运行时才可以. 2 本质类型不同. 宏定义的只是一段字符,在编译的时候被替换到引用的位置.在运行中是没有 ...
- ATL中宏定义offsetofclass的分析
近日学习ATL,通过对宏定义offsetofclass的解惑过程.顺便分析下虚函数表,以及通过虚函数表调用函数的问题. 1 解开ATL中宏定义offsetofclass的疑惑 #define _ATL ...
- C++中宏的定义与用法(现已被内联函数所代替)
在noip中,宏还是被经常采用,所以这里讲一下,C++中宏的定义与用法 第一种用法——配合条件编译:#define DEBUG 定义一个叫DEBUG的标识符.它应该与#ifdef或#ifndef配合使 ...
- C语言中的调试小技巧
C语言中的调试小技巧 经常看到有人介绍一些IDE或者像gdb这样的调试器的很高级的调试功能,也听人说过有些牛人做工程的时候就用printf来调试,不用特殊的调试器.特别是在代码经过编译器一些比较复杂的 ...
- Handlebars.js循环中索引(@index)使用技巧(访问父级索引)
使用Handlebars.js过程中,难免会使用循环,比如构造数据表格.而使用循环,又经常会用到索引,也就是获取当前循环到第几次了,一般会以这个为序号显示在页面上. Handlebars.js中获取循 ...
- Visual Studio 2015中的常用调试技巧分享
.NET 技术交流群:337901356 欢迎您的加入! 为什么要学习调试? 调试(Debug)是作为一个程序员必须要学会的东西,学会调试可以极大的提高开发效率,排错时间,很多人不喜欢调试,但我认为这 ...
- ACM 做题过程中的一些小技巧。
ACM做题过程中的一些小技巧. 1.一般用C语言节约空间,要用C++库函数或STL时才用C++; cout.cin和printf.scanf最好不要混用. 2.有时候int型不够用,可以用long l ...
随机推荐
- nginx 反向代理配置之---指定单域名
server { listen 80; server_name ngin服务器所对应的的域名; error_log /data/logs/nginx/mainsite.error.log; acces ...
- Apache Phoenix基本操作-1
本篇我们将介绍phoenix的一些基本操作. 1. 如何使用Phoenix输出Hello World? 1.1 使用sqlline终端命令 sqlline.py SZB-L0023780:2181:/ ...
- 【转载】IntelliJ IDEA WEB项目的部署配置
最近使用了一下IDEA,确实强大.在部署时出现了些问题.看了这篇文章,对ieda的一些部署配置有了些许了解,在此感谢原博.原文链接:http://blog.csdn.net/z69183787/art ...
- codeforces459D:Pashmak and Parmida's problem
Description Parmida is a clever girl and she wants to participate in Olympiads this year. Of course ...
- 神经网络卷积层 要回计算output的维度 input 28 卷积是3x3 则output是26 但是channel是卷积核的数量
model = Sequential() model.add(Conv2D(32, kernel_size=(3, 3), activation='relu', input_shape=input_s ...
- 10-THREE.JS perspective透视摄像机和orthographic正交摄像机区别
<!DOCTYPE html> <html> <head> <title></title> <script src="htt ...
- 第三方开源--Android Image Cropper--图片裁剪
github下载地址:https://github.com/ArthurHub/Android-Image-Cropper 有两种使用方式: 第一种:Activity用法 1.添加 CropImage ...
- python--关于if __name__==__main__的解释
在解释之前首先我们看下__name__这个变量存的是什么: #!/usr/bin/env python # -*- coding:utf-8 -*- print(__name__) 结果: __mai ...
- LeetCode OJ:Unique Paths II(唯一路径II)
Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How m ...
- VSCode使用正则表达式进行内容替换
首先描述一下我要达到的目的: 1.源数据: 2.目标数据: 3.使用的正则表达式如下: (id: (\d+),) id: $2, \n order: $2,