Click here to Skip to main content
15,881,204 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted
Updated 12-Sep-12 20:47pm
v3

1 solution

C#
public partial class Form1 : UserControl

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

Form1 should inherit from Form, not from UserControl.
 
Share this answer
 
Comments
VavaKoshy 13-Sep-12 7:33am    
Thank you Eddy that was really helpful...
saikotturu 6-Sep-17 5:57am    
even am using form as inheritance.am getting same error
Eddy Vluggen 6-Sep-17 10:43am    
That is because it is a generic error; it means that you are pointing to something that is not a form. Where your error is depends on your code - so no, this is not a one-fits-all solution.

Check (on the line of the exception) whether you are using a class that inherits from form, and whether you're pointing to the correct class.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900