错误:无法从"Bcode.Form1"转换为"System.Windows.Forms.Form" [英] Error : cannot convert from 'Bcode.Form1' to 'System.Windows.Forms.Form'

查看:337
本文介绍了错误:无法从"Bcode.Form1"转换为"System.Windows.Forms.Form"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我在调试以下提到的程序时遇到错误.该程序将生成条形码.我在下面的代码中提到了pls help;

命名空间Bcode
{
公共局部类Form1:UserControl
{

私有AlignType align = AlignType.Center;
私有字符串字母39 ="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-.$/+%*";
私有字符串代码="1234567890";
私有字符串[] coded39Char =新字符串[] {
"000110100","100100001","001100001","101100000","000110001","100110000","001110000","000100101","100100100","001100100","100001001","001001001","101001000" ," 000011001," 100011000," 001011000,
"000001101","100001100","001001100","000011100","100000011","001000011","101000010","000010011","100010010","001010010","000000111","100000110","001000110" ," 000010110," 110000001," 011000001,
"111000000","010010001","110010000","011010000","010000101","110000100","011000100","010101000","010100010","010001010","000101010","010010100"
};
私有容器组件= null;
private Font footerFont = new Font("Courier",8f);
private Font headerFont = new Font("Courier",18f);
私有字符串headerText ="BarCode Demo";
私人int高度= 50;
private int leftMargin = 10;
专用面板panel1;
私有PrintDocument printDocument1;
私人布尔showFooter;
私人布尔showHeader;
private int topMargin = 10;
私人BarCodeWeight重量= BarCodeWeight.Small;

[STAThread]
静态void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
//以上错误
}

公共Form1()
{
InitializeComponent();
}

私有void BarCodeCtrl_Resize(对象发送者,EventArgs e)
{
this.panel1.Invalidate();
}

受保护的重写void Dispose(布尔处置)
{
if(处置&&(this.components!= null))
{
this.components.Dispose();
}
base.Dispose(处置);
}

私有void InitializeComponent()
{
this.panel1 =新的System.Windows.Forms.Panel();
this.printDocument1 =新的System.Drawing.Printing.PrintDocument();
this.SuspendLayout();
//
//panel1
//
this.panel1.BackColor = System.Drawing.SystemColors.Window;
this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;
this.panel1.Location =新的System.Drawing.Point(0,0);
this.panel1.Name ="panel1";
this.panel1.Size = new System.Drawing.Size(302,228);
this.panel1.TabIndex = 0;
this.panel1.Paint + =新的System.Windows.Forms.PaintEventHandler(this.panel1_Paint);
//
//printDocument1
//
this.printDocument1.PrintPage + =新的System.Drawing.Printing.PrintPageEventHandler(this.printDocument1_PrintPage);
//
//Form1
//
this.ClientSize = new System.Drawing.Size(302,228);
this.Controls.Add(this.panel1);
this.Name ="Form1";
this.Resize + = new System.EventHandler(this.BarCodeCtrl_Resize);
this.ResumeLayout(false);

}

当我运行此程序时,出现错误无法从Bcode.Form1转换为system.windows.forms.form

Hi frnds i am facing an error while debugging the below mentioned program. The program is to generate barcode. I am mentioning the code below pls help;

namespace Bcode
{
public partial class Form1 : UserControl
{

private AlignType align = AlignType.Center;
private string alphabet39 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%*";
private string code = "1234567890";
private string[] coded39Char = new string[] {
"000110100", "100100001", "001100001", "101100000", "000110001", "100110000", "001110000", "000100101", "100100100", "001100100", "100001001", "001001001", "101001000", "000011001", "100011000", "001011000",
"000001101", "100001100", "001001100", "000011100", "100000011", "001000011", "101000010", "000010011", "100010010", "001010010", "000000111", "100000110", "001000110", "000010110", "110000001", "011000001",
"111000000", "010010001", "110010000", "011010000", "010000101", "110000100", "011000100", "010101000", "010100010", "010001010", "000101010", "010010100"
};
private Container components = null;
private Font footerFont = new Font("Courier", 8f);
private Font headerFont = new Font("Courier", 18f);
private string headerText = "BarCode Demo";
private int height = 50;
private int leftMargin = 10;
private Panel panel1;
private PrintDocument printDocument1;
private bool showFooter;
private bool showHeader;
private int topMargin = 10;
private BarCodeWeight weight = BarCodeWeight.Small;

[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
//ERROR ABOVE
}

public Form1()
{
InitializeComponent();
}

private void BarCodeCtrl_Resize(object sender, EventArgs e)
{
this.panel1.Invalidate();
}

protected override void Dispose(bool disposing)
{
if (disposing && (this.components != null))
{
this.components.Dispose();
}
base.Dispose(disposing);
}

private void InitializeComponent()
{
this.panel1 = new System.Windows.Forms.Panel();
this.printDocument1 = new System.Drawing.Printing.PrintDocument();
this.SuspendLayout();
//
// panel1
//
this.panel1.BackColor = System.Drawing.SystemColors.Window;
this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;
this.panel1.Location = new System.Drawing.Point(0, 0);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(302, 228);
this.panel1.TabIndex = 0;
this.panel1.Paint += new System.Windows.Forms.PaintEventHandler(this.panel1_Paint);
//
// printDocument1
//
this.printDocument1.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(this.printDocument1_PrintPage);
//
// Form1
//
this.ClientSize = new System.Drawing.Size(302, 228);
this.Controls.Add(this.panel1);
this.Name = "Form1";
this.Resize += new System.EventHandler(this.BarCodeCtrl_Resize);
this.ResumeLayout(false);

}

When i run this i am getting an error "Cannot convert from Bcode.Form1 to system.windows.forms.form

推荐答案

/+%*";
私有字符串代码="1234567890";
私有字符串[] coded39Char =新字符串[] {
"000110100","100100001","001100001","101100000","000110001","100110000","001110000","000100101","100100100","001100100","100001001","001001001","101001000" ," 000011001," 100011000," 001011000,
"000001101","100001100","001001100","000011100","100000011","001000011","101000010","000010011","100010010","001010010","000000111","100000110","001000110" ," 000010110," 110000001," 011000001,
"111000000","010010001","110010000","011010000","010000101","110000100","011000100","010101000","010100010","010001010","000101010","010010100"
};
私有容器组件= null;
private Font footerFont = new Font("Courier",8f);
private Font headerFont = new Font("Courier",18f);
私有字符串headerText ="BarCode Demo";
私人int高度= 50;
private int leftMargin = 10;
专用面板panel1;
私有PrintDocument printDocument1;
私人布尔showFooter;
私人布尔showHeader;
private int topMargin = 10;
私人BarCodeWeight重量= BarCodeWeight.Small;

[STAThread]
静态void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
//以上错误
}

公共Form1()
{
InitializeComponent();
}

私有void BarCodeCtrl_Resize(对象发送者,EventArgs e)
{
this.panel1.Invalidate();
}

受保护的重写void Dispose(布尔处置)
{
if(处置&&(this.components!= null))
{
this.components.Dispose();
}
base.Dispose(处置);
}

私有void InitializeComponent()
{
this.panel1 =新的System.Windows.Forms.Panel();
this.printDocument1 =新的System.Drawing.Printing.PrintDocument();
this.SuspendLayout();
//
//panel1
//
this.panel1.BackColor = System.Drawing.SystemColors.Window;
this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;
this.panel1.Location =新的System.Drawing.Point(0,0);
this.panel1.Name ="panel1";
this.panel1.Size = new System.Drawing.Size(302,228);
this.panel1.TabIndex = 0;
this.panel1.Paint + =新的System.Windows.Forms.PaintEventHandler(this.panel1_Paint);
//
//printDocument1
//
this.printDocument1.PrintPage + =新的System.Drawing.Printing.PrintPageEventHandler(this.printDocument1_PrintPage);
//
//Form1
//
this.ClientSize = new System.Drawing.Size(302,228);
this.Controls.Add(this.panel1);
this.Name ="Form1";
this.Resize + = new System.EventHandler(this.BarCodeCtrl_Resize);
this.ResumeLayout(false);

}

当我运行此程序时,出现错误无法从Bcode.Form1转换为system.windows.forms.form
/+%*";
private string code = "1234567890";
private string[] coded39Char = new string[] {
"000110100", "100100001", "001100001", "101100000", "000110001", "100110000", "001110000", "000100101", "100100100", "001100100", "100001001", "001001001", "101001000", "000011001", "100011000", "001011000",
"000001101", "100001100", "001001100", "000011100", "100000011", "001000011", "101000010", "000010011", "100010010", "001010010", "000000111", "100000110", "001000110", "000010110", "110000001", "011000001",
"111000000", "010010001", "110010000", "011010000", "010000101", "110000100", "011000100", "010101000", "010100010", "010001010", "000101010", "010010100"
};
private Container components = null;
private Font footerFont = new Font("Courier", 8f);
private Font headerFont = new Font("Courier", 18f);
private string headerText = "BarCode Demo";
private int height = 50;
private int leftMargin = 10;
private Panel panel1;
private PrintDocument printDocument1;
private bool showFooter;
private bool showHeader;
private int topMargin = 10;
private BarCodeWeight weight = BarCodeWeight.Small;

[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
//ERROR ABOVE
}

public Form1()
{
InitializeComponent();
}

private void BarCodeCtrl_Resize(object sender, EventArgs e)
{
this.panel1.Invalidate();
}

protected override void Dispose(bool disposing)
{
if (disposing && (this.components != null))
{
this.components.Dispose();
}
base.Dispose(disposing);
}

private void InitializeComponent()
{
this.panel1 = new System.Windows.Forms.Panel();
this.printDocument1 = new System.Drawing.Printing.PrintDocument();
this.SuspendLayout();
//
// panel1
//
this.panel1.BackColor = System.Drawing.SystemColors.Window;
this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;
this.panel1.Location = new System.Drawing.Point(0, 0);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(302, 228);
this.panel1.TabIndex = 0;
this.panel1.Paint += new System.Windows.Forms.PaintEventHandler(this.panel1_Paint);
//
// printDocument1
//
this.printDocument1.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(this.printDocument1_PrintPage);
//
// Form1
//
this.ClientSize = new System.Drawing.Size(302, 228);
this.Controls.Add(this.panel1);
this.Name = "Form1";
this.Resize += new System.EventHandler(this.BarCodeCtrl_Resize);
this.ResumeLayout(false);

}

When i run this i am getting an error "Cannot convert from Bcode.Form1 to system.windows.forms.form


public partial class Form1 : UserControl

Application.Run(new Form1()); // fails because it's not a form


Form1应该从Form继承,而不是从UserControl继承.


Form1 should inherit from Form, not from UserControl.


这篇关于错误:无法从"Bcode.Form1"转换为"System.Windows.Forms.Form"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆