无法创建组件 [英] Failed to create component
问题描述
我已经将我的VB.Net组件转换为C#,但是有一个我看不到的转换错误......
这是代码......
使用System;
使用System.Collections.Generic;
使用System.Linq;
使用System.Text;
使用System.Drawing.Drawing2D;
使用System.Windows.Forms;使用System.Drawing
;
命名空间OctoWords_cs
{
public class slideOutPanel:Panel
{
private Point [] polygon;
private int closedWidth;
private int captionHeight;
private int maxWidth = 300;
private string caption ="找到的字词";
private bool closing = false;
private System.Timers.Timer tmr = new System.Timers.Timer();
public slideOutPanel()
{
this.Dock = DockStyle.Right;
SizeF s = this.CreateGraphics()。MeasureString(caption,this.Font);
GraphicsPath gp = new GraphicsPath();
polygon = new Point []
{
new Point(0,0),
new Point(300,0),
new Point(300,495) ,
new Point((int)s.Height,495),
new Point((int)s.Height,(int)s.Width),
new Point(0,( int)s.Width),
new Point(0,0)
};
gp.AddPolygon(polygon);
this.Region = new Region(gp);
closedWidth =(int)s .Height;
captionHeight =(int)s.Width;
this.Width =(int)s.Height;
polygon [3] .X + = 1;
polygon [4] .X + = 1;
polygon [4] .Y - = 1;
polygon [5] .Y - = 1;
tmr.Interval = 100;
}
private void slideOutPanel_Paint(object sender,System.Windows.Forms.PaintEventArgs e)
{
e.Graphics.DrawPolygon(Pens。黑色,多边形);
e.Graphics.RotateTransform(270);
e.Graphics.DrawString(标题,this.Font,Brushes.Black,(captionHeight * -1),0);
e.Graphics.ResetTransform();
}
protected override void OnMouseEnter(System.EventArgs e)
{
closing = false;
tmr.Enabled = true;
base.OnMouseEnter(e);
}
protected override void OnMouseLeave(System.EventArgs e)
{
Point p = this.PointToClient(Cursor.Position);
if(!this.Region.IsVisible(p))
{
closing = true;
tmr.Enabled = true;
tmr.Start();
}
base.OnMouseLeave(e);
}
public delegate void tmr_TickCallback(object sender,System.EventArgs e);
private void tmr_Tick(object sender,System.EventArgs e)
{
if(this.InvokeRequired)
{
this.Invoke(new tmr_TickCallback) (new System.EventHandler(this.tmr_Tick)),sender,e);
}
else
{
if(closing)
{
this.Width =(this.Width - Math.Min(50,(this。宽度 - closedWidth)));
}
其他
{
this.Width =(this.Width + Math.Min(50,(maxWidth - this.Width)));
}
tmr.Enabled =((this.Width == closedWidth)||(this.Width == maxWidth))? false:是的;
}
}
}
}
谁能告诉我错误在哪里?
感谢您的帮助
< blockquote>
您好,
此组件是否在VB.NET中使用Option Strict On? 如果您有Option Strict Off然后转换为C#,这可能是问题的根源,所以我将使用Option Strict On构建VB.NET版本以确保它仍然有效。
一般来说一个设计良好的组件在使用C#到VB.NET或VB.NET到C#从一种语言转到另一种语言时不应该抛出异常。
I've converted a VB.Net component of mine to C#, but there's a conversion error that i can't see...
This is the code...
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Drawing.Drawing2D; using System.Windows.Forms; using System.Drawing; namespace OctoWords_cs { public class slideOutPanel : Panel { private Point[] polygon; private int closedWidth; private int captionHeight; private int maxWidth = 300; private string caption = "Words found"; private bool closing = false; private System.Timers.Timer tmr = new System.Timers.Timer(); public slideOutPanel() { this.Dock = DockStyle.Right; SizeF s = this.CreateGraphics().MeasureString(caption, this.Font); GraphicsPath gp = new GraphicsPath(); polygon = new Point[] { new Point(0, 0), new Point(300, 0), new Point(300, 495), new Point((int)s.Height, 495), new Point((int)s.Height, (int)s.Width), new Point(0, (int)s.Width), new Point(0, 0) }; gp.AddPolygon(polygon); this.Region = new Region(gp); closedWidth = (int)s.Height; captionHeight = (int)s.Width; this.Width = (int)s.Height; polygon[3].X += 1; polygon[4].X += 1; polygon[4].Y -= 1; polygon[5].Y -= 1; tmr.Interval = 100; } private void slideOutPanel_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { e.Graphics.DrawPolygon(Pens.Black, polygon); e.Graphics.RotateTransform(270); e.Graphics.DrawString(caption, this.Font, Brushes.Black, (captionHeight * -1), 0); e.Graphics.ResetTransform(); } protected override void OnMouseEnter(System.EventArgs e) { closing = false; tmr.Enabled = true; base.OnMouseEnter(e); } protected override void OnMouseLeave(System.EventArgs e) { Point p = this.PointToClient(Cursor.Position); if (!this.Region.IsVisible(p)) { closing = true; tmr.Enabled = true; tmr.Start(); } base.OnMouseLeave(e); } public delegate void tmr_TickCallback(object sender, System.EventArgs e); private void tmr_Tick(object sender, System.EventArgs e) { if (this.InvokeRequired) { this.Invoke(new tmr_TickCallback(new System.EventHandler(this.tmr_Tick)), sender, e); } else { if (closing) { this.Width = (this.Width - Math.Min(50, (this.Width - closedWidth))); } else { this.Width = (this.Width + Math.Min(50, (maxWidth - this.Width))); } tmr.Enabled = ((this.Width == closedWidth) || (this.Width == maxWidth)) ? false : true; } } } }
Can anyone tell me where the error is?
thanks for any help
Hello,
Did this component work in VB.NET with Option Strict On ? If you had Option Strict Off then converted to C# this might be the source of the problem so I would build the VB.NET version with Option Strict On to ensure it works still.
Generally speaking a well designed component should not throw an exception when going from one language to another with C# to VB.NET or VB.NET to C#.
这篇关于无法创建组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!