在按下键空格的文本框中附加一个符号



按下键空格的文本框上附加一个符号

嗨,您好,我尝试制作一个搜索引擎程序,当他们按下空格键时,我需要插入 %。

我已经成功地插入了符号%但它后面放了一个空白。我想附加没有空格的符号。

提前谢谢你

这是我的代码

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
可以将

KeyEventArgs.SuppressKeyPress 属性设置为 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

相关内容

最新更新