将工具提示添加到抖动文本框

时间:2016-05-27 10:03:34

标签: c# winforms tooltip

我正在尝试将工具提示添加到winform中的抖动文本框中。要添加工具提示,需要鼠标悬停事件,但是在抖动文本框的情况下,鼠标悬停事件不会触发。有没有其他方法可以为鼠标悬停添加工具提示?

当用户将鼠标悬停在此抖动文本框上时,文本框的整个内容应显示在工具提示中。

2 个答案:

答案 0 :(得分:1)

  

第一次鼠标悬停在TextBox上时,工具提示不会显示。

似乎TextBox的工具提示仅出现在第二个悬停事件中。 TextBox是否ReadOnly无关紧要。但作为一种解决方法,您可以自己处理MouseHoverMouseLeave个事件并编写此类代码:

private void textBox1_MouseHover(object sender, EventArgs e)
{
    var point = this.textBox1.PointToClient(Cursor.Position);
    point.Offset(0, 20);
    this.toolTip1.Show("Some Text", this.textBox1,
        point, 2000);
}
private void textBox1_MouseLeave(object sender, EventArgs e)
{
    this.toolTip1.Hide(this.textBox1);
}

以下是修复前行为的屏幕截图:

enter image description here

修复后的屏幕截图:

enter image description here

答案 1 :(得分:0)

请尝试以下代码:

import AVFoundation

class TextToSpeechService: NSObject {
  let synth = AVSpeechSynthesizer()
  let audioSession = AVAudioSession.sharedInstance()
  override init() {
    super.init()
    synth.delegate = self
    do {
      try audioSession.setCategory(AVAudioSessionCategoryPlayback, withOptions: .DuckOthers)
    } catch {
      print("AVAudioSession: cannot set category")
    }
  }
  func saySomething(text: String) {
    let myUtterance = AVSpeechUtterance(string: text)       
    do {
      try audioSession.setActive(true)
    } catch {
      print("AVAudioSession: cannot activate")
    }
    synth.speakUtterance(myUtterance)
  }
}

extension TextToSpeechService: AVSpeechSynthesizerDelegate {
  func speechSynthesizer(synthesizer: AVSpeechSynthesizer, didFinishSpeechUtterance utterance: AVSpeechUtterance) {
    do {
      try audioSession.setActive(false)
    } catch {
      print("AVAudioSession: cannot deactivate")
    }
  }
}

使用X / Y值进行游戏,将其移动到您想要的位置。可见时间是它消失多久。

相关问题