在按键空间的文本框上添加符号
嗨,您好,我尝试制作搜索引擎程序,我需要在按空格键时插入%。
我已成功插入符号%
,但它后面放了一个空格。我想在没有空格的情况下附加符号。
提前谢谢
这是我的代码
Public Class Form2
Public Sub New()
Me.InitializeComponent()
Me.KeyPreview = True
End Sub
Private Sub Button1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Button1.KeyDown
tbSearch.AppendText("%")
'If e.KeyCode = Keys.Space Then
'e.SuppressKeyPress = True
'End If
End Sub
Private Sub Form2_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = Keys.Space Then
tbSearch.AppendText("%")
tbSearch.Text.Trim()
End If
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim pict = "https://i.ytimg.com/vi/" + TextBox1.Text + "/hqdefault.jpg?custom=true&w=168&h=94&stc=true&jpg444=true&jpgq=90&sp=68&sigh=6rUlsKOOsNW2_I8q7wgQJZ-z3Mw"
PictureBox1.ImageLocation = pict
Dim Link = "http://www.youtube.com/results?search_type=&search_query=" + TextBox1.Text + "&aq=f"
ProgressBar1.Value = 0
ProgressBar1.Value = 100
Form1.TextBox1.Text = Me.TextBox1.Text
MsgBox("Video Have Been Load And Are Ready To Play...")
ProgressBar1.Value = 0
Me.Close()
End Sub
Private Sub BackMainPageToolStripMenuItem_Click(sender As Object, e As EventArgs)
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
End Sub
Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click
End Sub
Public Function SwapClipboardHtmlText( _
ByVal replacementHtmlText As String) As String
Dim returnHtmlText As String = Nothing
If (Clipboard.ContainsText(TextDataFormat.Html)) Then
returnHtmlText = Clipboard.GetText(TextDataFormat.Html)
Clipboard.SetText(replacementHtmlText, TextDataFormat.Html)
End If
Return returnHtmlText
TextBox1.Text = returnHtmlText
End Function
Private Sub btnSearch_Click(sender As Object, e As EventArgs) Handles btnSearch.Click
Dim pict = "https://i.ytimg.com/vi/" + TextBox1.Text + "/hqdefault.jpg?custom=true&w=168&h=94&stc=true&jpg444=true&jpgq=90&sp=68&sigh=6rUlsKOOsNW2_I8q7wgQJZ-z3Mw"
Me.WebBrowser2.ScriptErrorsSuppressed() = True
Me.WebBrowser1.ScriptErrorsSuppressed() = True
Dim info = "http://gdata.youtube.com/feeds/api/videos/" + tbSearch.Text
Me.WebBrowser2.Navigate("https://www.google.pt/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=" + tbSearch.Text + "&*")
Process.Start("chrome", "https://www.youtube.com/results?search_query=" + tbSearch.Text)
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Process.Start("chrome", "http://www.google.com/search?hl=en&q=" + tbSearch.Text + "&aq=f&oq=")
End Sub
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
tbSearch.Select()
MsgBox("Type Your Search Keyword And Press Search Youtube")
End Sub
End Class
答案 0 :(得分:0)
您可以将KeyEventArgs.SuppressKeyPress
property设置为True
,使其忽略当前按下的键,但要使其正常工作,您必须处理 文本框的 KeyDown
事件而不是表单。
Private Sub tbSearch_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles tbSearch.KeyDown
If e.KeyCode = Keys.Space Then
tbSearch.AppendText("%")
e.SuppressKeyPress = True
End If
End Sub