我已下载并实现了库以进行SFTP下载,效果很好.我一直在查看文档和示例,只是看不到如何实现SFTP下载和进度.我想显示下载的进度.到目前为止,我有:
Imports Renci.SshNet
Imports System.IO
Using sftp As New SftpClient("0.0.0.0", 25, "id", "pwd")
'connect to the server
sftp.Connect()
'the name of the remote file we want to transfer to the PC
Dim remoteFileName As String = "/data/OUT/trips.txt"
'download the file as a memory stream and convert to a file stream
Using ms As New MemoryStream
'download as memory stream
sftp.DownloadFile(remoteFileName, ms)
'create a file stream
Dim fs As New FileStream("c:\mytrips.txt", FileMode.Create, FileAccess.Write)
'write the memory stream to …Run Code Online (Sandbox Code Playgroud) 这可能是一件简单的事情,但在VB2010中,我喜欢将我的源代码放在例程注释中.有些URL嵌入了&符号,IDE会将其标记为警告.
''' <summary>
''' routine that creates a new file based on a definition query.
''' </summary>
''' <param name="newLoc"></param>
''' <returns></returns>
''' <remarks>
''' http://forums.esri.com/Thread.asp?c=93&f=992&t=194920#580036
''' http://forums.esri.com/Thread.asp?c=93&f=992&t=155005#452664
''' </remarks>
Public Function DoSelectLoc(ByVal newLoc As NewLocation) As Boolean
'my routine
End Function
Run Code Online (Sandbox Code Playgroud)
上面的两个URL标有警告.我已经尝试了几种替代方法来编写URL,但没有一种方法可行.我已经尝试了HTML代码,&但仍然有&符号.我知道IDE使用XML作为注释,但必须有一些方法来编写URL而不会收到警告并仍保持相同的引用链接.
更新:基于此处的讨论http://social.msdn.microsoft.com/Forums/en-US/f14e7b55-c352-4ca5-a82c-bca3b83818db/double-ampersand-in-a-code-comment-causes-intellisense -error我决定使用CDDATA来封装我的URL,如下所示:
''' <remarks>
''' <![CDATA[
''' http://forums.esri.com/Thread.asp?c=93&f=992&t=194920#580036
''' http://forums.esri.com/Thread.asp?c=93&f=992&t=155005#452664
''' ]]>
''' </remarks>
Run Code Online (Sandbox Code Playgroud)
似乎工作以允许链接正常工作,也不会使Visual Studio警告绊倒.
VB2010.我正在尝试使用Enumeration单位的内容填充ComboBox.我已经设法用字典做了这个.就像是
Dim dUnits As New Dictionary(Of String, Integer)
Dim da As String
For Each enumValue As eUnits In System.Enum.GetValues(GetType(eUnits))
da = ConvertEnumToCommonName 'gets unique name for an enumeration
dUnits.Add(da, enumValue)
Next
cbo.DisplayMember = "Key" 'display the the common name
cbo.ValueMember = "Value" 'use the enumeration as the value
cbo.DataSource = New BindingSource(dUnits, Nothing)
Run Code Online (Sandbox Code Playgroud)
当我加载我的表格运作良好.现在,用户可以选择要显示的默认单位.那么我试试吧
Dim defUnits As eUnits = eUnits.Feet
Dim idx As Integer = cbo.Items.IndexOf(defUnits) 'doesnt work, returns a -1
cbo.SelectedIndex = idx
Run Code Online (Sandbox Code Playgroud)
我已经做了一段时间的研究,并且相当肯定这与ComboBox将值存储为字符串有关,实际上我正在搜索一个整数的枚举.不知道我是否有这个权利.无论如何,我似乎无法选择默认项目.我可以尝试另一种方法吗?
我已经做了一些阅读,似乎无法解决在我的VB2010项目中克隆List(类)的最佳方法.我有三个相关的课程
Public Class City
'here are many fields of type string and integer
Public Roads As New List(Of Road)
End Class
Public Class Road
'here are many fields of type string and integer
Public Hazards As New List(Of Hazard)
End Class
Public Class Hazard
Implements ICloneable
'here are many fields of type string and integer and double
Public Function Clone() As Object Implements System.ICloneable.Clone
Return Me.MemberwiseClone
End Function
End Class
Run Code Online (Sandbox Code Playgroud)
所以,假设我有一个我正在研究的城市,有些情况我想要创建,作为基础的一条道路及其危险,然后添加另一条道路,但使用先前的道路危险作为起点然后调整字段.
Dim rd As New Road
'add road fields
dim …Run Code Online (Sandbox Code Playgroud) VB2010。我了解如何保存设置并从 My.Settings 命名空间加载它们。我想弄清楚的是如何获取设置的默认值并将其呈现给用户。我不想保存设置我只想显示当前值是什么以及默认值是什么。我试过这个,但我认为它没有做我认为它应该做的事情:
Msgbox "Current setting: " & My.Settings.CustLineWidth & vbcrlf & _
"Default setting: " & My.MySettings.Default.CustLineWidth
Run Code Online (Sandbox Code Playgroud)
我在 IDE 中设置的默认值为 10,但用户将其更改为 25。如果我运行上面的代码,我会得到
Current setting: 25
Default setting: 25
Run Code Online (Sandbox Code Playgroud)
我想要的是
Current setting: 25
Default setting: 10
Run Code Online (Sandbox Code Playgroud)
解决方案:我遍历所有设置并像这样打印出当前值和默认值
For Each prop As Configuration.SettingsPropertyValue In My.Settings.PropertyValues
Debug.Print("Name={0}", prop.Name)
Debug.Print(" Value ={0}", prop.PropertyValue.ToString)
Debug.Print(" Default={0}", prop.Property.DefaultValue.ToString)
Next prop
Run Code Online (Sandbox Code Playgroud) VB2010我手动创建了一个DataTable,因此它不是来自数据库.我已将其分配给组合框并显示我的数据列.如果我更改了DataTable,我是否必须重新建立链接?
'assign first table
dt = GetFirstTable()
cbo.DataSource = dt
cbo.DisplayMember = "Time"
cbo.ValueMember = "Time"
'print out items in combobox
'assign second table
dt = GetSecondTable()
'cbo.DataSource = dt 'do i have to re-connect here?
'print out items in combobox
Run Code Online (Sandbox Code Playgroud)
似乎我不重新建立链接我得到相同的项目.我虽然因为cbo已经链接到dt变量,所以我不需要每次都重新链接它.那是怎么回事,或者我在这里做错了什么?
VB.NET 2010 - 我有一个RichTextbox,用户可以在其中手动输入数据或从其他来源复制/粘贴.数据完成后,他会点击并突出显示几个关键词.我的问题是,如果他从其他来源复制/粘贴,格式也会被复制.好吧,有时外部源有一个白色字体,我的文本框有一个白色背景,所以看起来他没有粘贴,他一次又一次地做.
我正在寻找的是一种拦截粘贴操作到文本框的方法,这样我就可以将该文本粘贴为纯ASCII,而无需格式化.
在使用KeyDown进行实验后进行编辑
Private Sub txtRch_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles txtRch.KeyDown
If e.Modifiers = Keys.Control AndAlso e.KeyCode = Keys.V Then
With txtRch
Dim i As Integer = .SelectionStart 'cache the current position
.Select(0, i) 'select text from start to current position
Dim s As String = .SelectedText 'copy that text to a variable
.Select(i, .TextLength) 'now select text from current position to end
Dim t As String = .SelectedText 'copy that text to a variable …Run Code Online (Sandbox Code Playgroud) vb.net ×7
combobox ×2
ampersand ×1
class ×1
clone ×1
comments ×1
datasource ×1
datatable ×1
default ×1
dictionary ×1
enumeration ×1
formatting ×1
hook ×1
icloneable ×1
indexof ×1
list ×1
my.settings ×1
paste ×1
progress ×1
richtextbox ×1
sftp ×1
ssh ×1
url ×1
xml ×1