如何解决如何通过源代码单击启用按钮?
这是我拥有的exe;
我只想单击代码中的启用按钮,而不是手动在表单上单击
就像触发按钮一样,执行点击,启用点击(无论我不知道什么);
如何使用启用按钮单击的谷码启动exe;
如果您能解决,我将非常高兴;
非常感谢您的未来帮助;
using Honeygain.Presenters;
using Honeygain.Properties;
using Honeygain.Utilities;
using Honeygain.Views.Events;
using System;
using System.ComponentModel;
using System.Drawing;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Honeygain.Views.Forms
{
internal class StreamingForm : BaseForm
{
private readonly IMainPresenter _presenter;
private CancellationTokenSource _actionCTS;
private IContainer components;
private TableLayoutPanel panel;
private PictureBox banner;
private Label title;
private LinkLabel terms;
private Label description;
private TableLayoutPanel buttons;
private Button disable;
private Button enable;
private LinkLabel questions;
public event EventHandler<FormFailedEventArgs> StreamingToggleFailed;
public event EventHandler StreamingToggleFinished;
public event EventHandler StreamingToggleStarted;
public StreamingForm(IMainPresenter presenter)
{
this.InitializeComponent();
this._presenter = presenter;
}
private void OnFormVisibleChanged(object sender,EventArgs e)
{
this._actionCTS?.Cancel();
this._actionCTS = this.Visible ? new CancellationTokenSource() : (CancellationTokenSource) null;
}
private void OnTermsLinkClicked(object sender,LinkLabelLinkClickedEventArgs e) => Websites.OpenTermsOfUse();
private void OnQuestionsLinkClicked(object sender,LinkLabelLinkClickedEventArgs e) => Websites.OpenContentDelivery();
private async void OndisableClick(object sender,EventArgs e) => await this.Toggle(false);
private async void OnEnableClick(object sender,EventArgs e) => await this.Toggle(true);
private async Task Toggle(bool enable)
{
this.Prepare();
try
{
await this.Update(enable);
}
catch (TaskCanceledException ex)
{
Logger.Instance.Debug((Exception) ex);
}
catch (Exception ex)
{
this.Fail(ex);
}
finally
{
this.Finish();
}
}
private void Prepare()
{
EventHandler streamingToggleStarted = this.StreamingToggleStarted;
if (streamingToggleStarted != null)
streamingToggleStarted((object) this,EventArgs.Empty);
this.Enabled = false;
}
private async Task Update(bool enable)
{
StreamingForm streamingForm = this;
await streamingForm._presenter.SetStreamingStatusAsync(enable,streamingForm._actionCTS.Token);
streamingForm.Hide();
}
private void Fail(Exception exception)
{
this.Hide();
EventHandler<FormFailedEventArgs> streamingToggleFailed = this.StreamingToggleFailed;
if (streamingToggleFailed == null)
return;
streamingToggleFailed((object) this,new FormFailedEventArgs()
{
Error = exception
});
}
private void Finish()
{
this.Enabled = true;
EventHandler streamingToggleFinished = this.StreamingToggleFinished;
if (streamingToggleFinished == null)
return;
streamingToggleFinished((object) this,EventArgs.Empty);
}
protected override void dispose(bool disposing)
{
if (disposing && this.components != null)
this.components.dispose();
base.dispose(disposing);
}
private void InitializeComponent()
{
ComponentResourceManager componentResourceManager = new ComponentResourceManager(typeof (StreamingForm));
this.panel = new TableLayoutPanel();
this.banner = new PictureBox();
this.terms = new LinkLabel();
this.buttons = new TableLayoutPanel();
this.disable = new Button();
this.enable = new Button();
this.questions = new LinkLabel();
this.description = new Label();
this.title = new Label();
this.panel.SuspendLayout();
((ISupportinitialize) this.banner).BeginInit();
this.buttons.SuspendLayout();
this.SuspendLayout();
componentResourceManager.ApplyResources((object) this.panel,"panel");
this.panel.Controls.Add((Control) this.banner,0);
this.panel.Controls.Add((Control) this.terms,4);
this.panel.Controls.Add((Control) this.buttons,7);
this.panel.Controls.Add((Control) this.questions,5);
this.panel.Controls.Add((Control) this.description,2);
this.panel.Controls.Add((Control) this.title,1);
this.panel.Name = "panel";
componentResourceManager.ApplyResources((object) this.banner,"banner");
this.banner.Image = (Image) Resources.streaming;
this.banner.Name = "banner";
this.banner.TabStop = false;
this.terms.ActiveLinkColor = Color.FromArgb(7,100,146);
componentResourceManager.ApplyResources((object) this.terms,"terms");
this.terms.ForeColor = Color.FromArgb(118,133,141);
this.terms.LinkColor = Color.FromArgb(0,147,(int) byte.MaxValue);
this.terms.Name = "terms";
this.terms.TabStop = true;
this.terms.UseCompatibleTextRendering = true;
this.terms.LinkClicked += new LinkLabelLinkClickedEventHandler(this.OnTermsLinkClicked);
componentResourceManager.ApplyResources((object) this.buttons,"buttons");
this.buttons.Controls.Add((Control) this.disable,0);
this.buttons.Controls.Add((Control) this.enable,2,0);
this.buttons.Name = "buttons";
componentResourceManager.ApplyResources((object) this.disable,"disable");
this.disable.BackColor = Color.White;
this.disable.ForeColor = Color.FromArgb(11,152,222);
this.disable.Name = "disable";
this.disable.UseVisualStyleBackColor = false;
this.disable.Click += new EventHandler(this.OndisableClick);
componentResourceManager.ApplyResources((object) this.enable,"enable");
this.enable.BackColor = Color.FromArgb(11,222);
this.enable.ForeColor = Color.White;
this.enable.Name = "enable";
this.enable.UseVisualStyleBackColor = false;
this.enable.Click += new EventHandler(this.OnEnableClick);
this.questions.ActiveLinkColor = Color.FromArgb(7,146);
componentResourceManager.ApplyResources((object) this.questions,"questions");
this.questions.ForeColor = Color.FromArgb(118,141);
this.questions.LinkColor = Color.FromArgb(0,(int) byte.MaxValue);
this.questions.Name = "questions";
this.questions.TabStop = true;
this.questions.UseCompatibleTextRendering = true;
this.questions.LinkClicked += new LinkLabelLinkClickedEventHandler(this.OnQuestionsLinkClicked);
componentResourceManager.ApplyResources((object) this.description,"description");
this.description.ForeColor = Color.FromArgb(118,141);
this.description.Name = "description";
componentResourceManager.ApplyResources((object) this.title,"title");
this.title.ForeColor = Color.FromArgb(14,65,88);
this.title.Name = "title";
componentResourceManager.ApplyResources((object) this,"$this");
this.Controls.Add((Control) this.panel);
this.Name = nameof (StreamingForm);
this.VisibleChanged += new EventHandler(this.OnFormVisibleChanged);
this.panel.ResumeLayout(false);
this.panel.Performlayout();
((ISupportinitialize) this.banner).EndInit();
this.buttons.ResumeLayout(false);
this.ResumeLayout(false);
this.Performlayout();
}
}
}```
解决方法
您可以使用.PerformClick();
在程序中单击它。
如果您希望在加载表单时仅单击一次,则创建一个OnLoad事件并添加:
this.enable.PerformClick();
这样,将创建对象(按钮),然后单击它们。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。