Allow VBCommenter to support Custom User Names

Source: Internet
Author: User
When you use VBCommenter to generate comments in XML format, it is found that the user name in the Since it uses the login user name, it is probably obtained through Environment. UserName, so it searches for "Environment. UserName" and returns a row:

SRes. Append (Environment. UserName)

I changed this line of code:

SRes. Append ("Hu Dan ")

Re-compile the project, re-install VBCommenter, type ''', and press Enter. It turns out to be changed:

'''-----------------------------------------------------------------------------
''' <Summary>
'''
''' </Summary>
''' <Remarks>
''' </Remarks>
''' <History>
''' [Hu Dan] Created
''' </History>
'''-----------------------------------------------------------------------------
Public Sub New ()

End Sub

However, this is too inflexible and can only be used by yourself. If it is not common enough, add a user name configuration function.

1. Configure the User Name Interface
Directly use the frmSettings form and add a Label and TextBox to modify the user name. The interface is as follows:

 

2. Add the following attributes in Configuration. vb:
 

'Key name of the user name stored in the registry
Private Const keyHistoryUserName As String = "HistoryUserName"

'''-----------------------------------------------------------------------------
''' <Summary>
''' User Name
''' </Summary>
''' <Value> </value>
''' <Remarks>
''' </Remarks>
''' <History>
''' [Hu Dan] Created
''' </History>
'''-----------------------------------------------------------------------------
<ComponentModel. Category ("General "),_
ComponentModel. Description ("UserName "),_
ComponentModel. DefaultValue ("Environment. UserName")> _
Public Property HistoryUserName () As String
Get
Return mConfigImp. GetSetting (keyHistoryUserName, System. Environment. UserName)
End Get
Set (ByVal sValue As String)
MConfigImp. SetSetting (keyHistoryUserName, sValue)
End Set
End Property

3. Add the following code to frmSettings. vb:

Private Sub frmSettings_Load (ByVal sender As System. Object, ByVal e As System. EventArgs) Handles MyBase. Load
'Display the previously set user name (can also be added to sub new)
TxtUserName. Text = myConfig. HistoryUserName
End Sub


4. Modify the Click Event Processing code of the OK button in the form frmSettings as follows:

Private Sub btnOk_Click (ByVal sender As System. Object, ByVal e As System. EventArgs) Handles btnOk. Click
MyConfig. CreateXMLFiles = Me. chkBuildXML. Checked
MyConfig. AddHistoryTags = Me. chkHistory. Checked
MyConfig. InsertXMLComments = Me. chkInsertComments. Checked
MyConfig. XMLCommentPrefix = Me.txt Prefix. Text. Trim

'Save User Name
'In fact, it is saved in the location below the registry:
'[HKEY_CURRENT_USER \ Software \ PowerToys for Visual Studio. NET 2003 \ VBCommenter]
MyConfig. HistoryUserName = Me.txt UserName. Text. Trim
End Sub

5. The above are all auxiliary work. The most important thing is to modify the following line of code in Template. VB:

SRes. Append (Environment. UserName)

Modify the Code as follows:

'Default
'Sres. Append (Environment. UserName)

'Dedicated, you only need to use the following line
'Sres. Append ("Hu Dan ")

'Use a user name
SRes. Append (Configuration. GetInstance (). HistoryUserName)

6. recompile and reinstall it!

I heard that no plug-ins are required to write such annotations in VB2005. Do you know that custom user names are supported?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.