[英]C# windows form project
Method of the 1st Form Class:第一种形式 Class 的方法:
private void englishToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Hide();
var Editor = new Editor();
Editor.Engprop = 1;
Editor.Closed += (s, args) => this.Close();
Editor.Show();
}
Method of the 2nd Form Class:第二种形式 Class 的方法:
public partial class Editor : Form
{
public int Engprop { get; set; }
public Uri MyProperty { get; set; }
public Editor()
{
InitializeComponent();
webBrowser1.ScriptErrorsSuppressed = true;
}
Uri temp = new Uri("file:///C:/Users/PC/Desktop/projese302/newtmp.html");
Uri eng = new Uri("file:///C:/Users/PC/Desktop/projese302/engtemp.html");
private void Editor_Load(object sender, EventArgs e)
{
if (Engprop==1)
{
webBrowser1.Navigate(eng);
}
}
I am trying to do that when Engprop
becomes 1 (when a user clicks the item of the ToolStripMenu), it should navigate the eng
URL but it doesn't work properly.我试图在
Engprop
变为 1 时(当用户单击 ToolStripMenu 的项目)时这样做,它应该导航eng
URL 但它不能正常工作。 I will be grateful for your help.我会很感激你的帮助。
I suppose the Editor_Load method is called from the OnLoad event of the form.我想 Editor_Load 方法是从表单的 OnLoad 事件中调用的。
If so, I'm not sure when this event is raised... Can be after the constructor (it explain why you have this problem) or after the Show method (in this case, I don't know why it doesn't work)如果是这样,我不确定何时引发此事件......可以在构造函数之后(它解释了为什么你有这个问题)或在 Show 方法之后(在这种情况下,我不知道为什么它没有工作)
Try to check if the event is raised before or after you set the Engprop property (debug + breakpoints)尝试检查在设置 Engprop 属性之前或之后是否引发了事件(调试 + 断点)
In any way, I think your code has a lack of architecture, since who use your Editor class need to know that can change the Engprop only between the constructor and the Show method.无论如何,我认为您的代码缺乏架构,因为谁使用您的编辑器 class 需要知道只能在构造函数和 Show 方法之间更改 Engprop。
I think you can make a better/reusable code if:我认为您可以在以下情况下制作更好/可重用的代码:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.