4
如何在「HelpRequest-mode」中單擊時獲取UserControl調度HelpRequest事件?如何獲取UserControl調度HelpRequest事件
我試着用一些彩色背景設置最簡單的UserControl。但不能讓它工作。
修訂
namespace SeoTools.UI.Components
{
public partial class HelpRequestTest : UserControl
{
public HelpRequestTest()
{
InitializeComponent();
}
protected override void OnHelpRequested(HelpEventArgs hevent)
{
base.OnHelpRequested(hevent); //can't get it here either
}
}
}
namespace SeoTools.UI.Components
{
partial class HelpRequestTest
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.SuspendLayout();
//
// HelpRequestTest
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.SystemColors.ActiveCaption;
this.Name = "HelpRequestTest";
this.Size = new System.Drawing.Size(114, 94);
this.ResumeLayout(false);
}
#endregion
}
}
...
private void WebHelpRequested(object sender, HelpEventArgs hlpevent)
{
string tag = ((Control)sender).Tag.ToString();
if (!string.IsNullOrEmpty(tag))
{
try
{
ProcessStartInfo sInfo = new ProcessStartInfo(tag);
Process.Start(sInfo);
}
catch (Exception) { }
}
hlpevent.Handled = true;
}
...
//
// helpRequestTest1
//
this.helpRequestTest1.BackColor = System.Drawing.SystemColors.ActiveCaption;
this.helpRequestTest1.Location = new System.Drawing.Point(91, 3);
this.helpRequestTest1.Name = "helpRequestTest1";
this.helpRequestTest1.Size = new System.Drawing.Size(114, 94);
this.helpRequestTest1.TabIndex = 1;
this.helpRequestTest1.Tag = "http://offerta.se";
this.helpRequestTest1.HelpRequested += new System.Windows.Forms.HelpEventHandler(this.WebHelpRequested);
我無法獲得自定義用戶控件來觸發HelpRequested事件。我附上我的代碼。 –
@NielsBosma您的代碼有效。我更新了我的答案 - 我唯一的猜測是你的UserControl中的子控件會干擾。這是我讓它「不工作」的唯一方法。 – LarsTech