How to close a web page on a button click, a hyperlink or a link button click? [closed]

浪尽此生 提交于 2019-12-12 10:43:58

问题


How can we provide a hyperlink or button to close a web page ?


回答1:


Assuming you're using WinForms, as it was the first thing I did when I was starting C# you need to create an event to close this form.

Lets say you've got a button called myNewButton. If you double click it on WinForms designer you will create an event. After that you just have to use this.Close

    private void myNewButton_Click(object sender, EventArgs e) {
        this.Close();
    }

And that should be it.

The only reason for this not working is that your Event is detached from button. But it should create new event if old one is no longer attached when you double click on the button in WinForms designer.




回答2:


To close a windows form (System.Windows.Forms.Form) when one of its button is clicked: in Visual Studio, open the form in the designer, right click on the button and open its property page, then select the field DialogResult an set it to OK or the appropriate value.




回答3:


double click the button and add write // this.close();

  private void buttonClick(object sender, EventArgs e)
{
    this.Close();
}



回答4:


public class Form1 : Form
{
public Form1()
{
    InitializeComponents(); // or whatever that method is called :)
    this.button.Click += new RoutedEventHandler(buttonClick);
}

private void buttonClick(object sender, EventArgs e)
{
    this.Close();
}
}


来源:https://stackoverflow.com/questions/2891012/how-to-close-a-web-page-on-a-button-click-a-hyperlink-or-a-link-button-click

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!