首页 \ 问答 \ WinForms如何调用按钮上的双击事件?(WinForms how to call a Double-Click Event on a Button?)

WinForms如何调用按钮上的双击事件?(WinForms how to call a Double-Click Event on a Button?)

当点击一次按钮时,我不希望事件发生,而只是在双击按钮时才会发生事件。 令人遗憾的是,双击事件并未出现在IDE中的事件列表中。

任何人都知道这个问题很好的解决方案? 谢谢!


Rather than making an event occur when a button is clicked once, I would like the event to occur only when the button is double-clicked. Sadly the double-click event doesn't appear in the list of Events in the IDE.

Anyone know a good solution to this problem? Thank you!


原文:https://stackoverflow.com/questions/13486245
更新时间:2021-11-05 22:11

最满意答案

它没有用,因为你手动改变props数组--React不知道它已经改变了。 一般来说,你根本不应该改变道具。

如果您真的想这样做,可以在componentDidMount中使用setState,然后通过以下方式呈现您的子组件:

class Parent extends React.Component {
  constructor(props) {
    super(props);

    this.state = {
      childComponent: null
    }
  }

  componentDidMount() {
    this.setState({ childComponent: <div>Hello</div> });
  }

  render() {
    return (
      <div>
        {this.state.childComponent}
      </div>
    )
  }
}

但是,无论你想做什么,都可能有更好的解决方案。 我无法想象很多情况下你只想在父装载后才能渲染东西。


It's not working because you are mutating the props array manually - React has no idea that it has changed. In general, you should never change props at all.

If you really want to do this, you can use setState within componentDidMount, and then render your child component through that:

class Parent extends React.Component {
  constructor(props) {
    super(props);

    this.state = {
      childComponent: null
    }
  }

  componentDidMount() {
    this.setState({ childComponent: <div>Hello</div> });
  }

  render() {
    return (
      <div>
        {this.state.childComponent}
      </div>
    )
  }
}

However, there might be a better solution to whatever you're trying to do. I can't imagine many situations in which you'd want to render stuff only after the parent has mounted.

相关问答

更多

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。