Re: Parameter is not valid
Can you put the code that is causing this? The exception message gives you a hint...
Quote:
at BarcodeLabelPrinter.Program.Main() in E:\BarcodeLabelPrinter\BarcodeLabelPrinter\Program.cs:line 17
You don't need to put the whole code file just the method/function or part of the function. Particularly close to the line 17 in your Program.cs. And needless to say...use the code tags ;)
Re: Parameter is not valid
Quote:
Originally Posted by nelo
Can you put the code that is causing this? The exception message gives you a hint...
You don't need to put the whole code file just the method/function or part of the function. Particularly close to the line 17 in your Program.cs. And needless to say...use the code tags ;)
LINE WHERE THIS ERROR OCCURS
Application.Run(new MainForm());
THIS IS LINE 17 OF PROGRAM.CS
Re: Parameter is not valid
Quote:
I am developing an application in which this error occurs some time when my program is running....
This error occurs sometime not redundant..
Ok. Maybe we need to understand the problem better. Do you get the exception everytime you run the program? What do you have in your MainForm?
Re: Parameter is not valid
Quote:
Originally Posted by nelo
Ok. Maybe we need to understand the problem better. Do you get the exception everytime you run the program? What do you have in your MainForm?
NO I DID NOT GET THIS PROBLEM EVERY TIME WHEN I RUN MY APPLICATION IT COMES SOME TIME WHEN MY APPLICATION IS RUNNING. WHETHER I AM DOING CERTAIN TASK WITH MY APPLICATION OR NOT....
IN THIS APPLICATION I AM ADDING FONTS TO MY APPLICATION I AM SENDING CODE THAT I HAVE USED TO ADD FONTS
class PrivateFonts
{
[DllImport("Gdi32.dll", CharSet = CharSet.Auto, SetLastError = true, ExactSpelling = true)]
private static extern IntPtr AddFontMemResourceEx(IntPtr pbFont, int cbFont, int pdv, ref int pcFonts);
public System.Drawing.Text.PrivateFontCollection GetFont(string[] FontResource)
{
//Get the namespace of the application
string NameSpc = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name.ToString();
System.IO.Stream FntStrm;
System.Drawing.Text.PrivateFontCollection FntNc = new System.Drawing.Text.PrivateFontCollection();
int i;
for (i = 0; i <= FontResource.GetUpperBound(0); i++)
{
//Get the resource stream area where the font is located
FntStrm = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(NameSpc + "." + FontResource[i]);
//Load the font off the stream into a byte array
byte[] ByteStrm = new byte[(int)FntStrm.Length];
FntStrm.Read(ByteStrm, 0, Convert.ToInt32((int)FntStrm.Length));
//Allocate some memory on the global heap
IntPtr FntPtr = System.Runtime.InteropServices.Marshal.AllocHGlobal(System.Runtime.InteropServices.Marshal.SizeOf(typeof(byte)) * ByteStrm.Length);
//Copy the byte array holding the font into the allocated memory.
System.Runtime.InteropServices.Marshal.Copy(ByteStrm, 0, FntPtr, ByteStrm.Length);
//Add the font to the PrivateFontCollection
FntNc.AddMemoryFont(FntPtr, ByteStrm.Length);
Int32 pcFonts;
pcFonts = 1;
AddFontMemResourceEx(FntPtr, (int)ByteStrm.Length, 0, ref pcFonts);
//Free the memory
System.Runtime.InteropServices.Marshal.FreeHGlobal(FntPtr);
}
return FntNc;
}
}
------------------------------------------------------------------------------------------------
ON BUTTON CLICK
string[] fontNames = { "IDAutomationXC39M.ttf" };
PrivateFonts privateFonts = new PrivateFonts();
System.Drawing.Text.PrivateFontCollection FntNc = privateFonts.GetFont(fontNames);
labelBcode.Font = new System.Drawing.Font(FntNc.Families[0], 12);
Re: Parameter is not valid
You are getting that error because MainForm() is not an ApplicationContext nor is it a Form.
I suspect you are trying to do one of two things.
either
1. start a new process
2. open up a new form
to start a new process use
System.Diagnostics.Process.Start(fileToStart);
for opening a new form you can either open it is a dialog or as just a new form
that would be
this.Show(theForm);
or
this.ShowDialog(theForm);
Re: Parameter is not valid
Quote:
Originally Posted by joe1985
You are getting that error because MainForm() is not an ApplicationContext nor is it a Form.
I suspect you are trying to do one of two things.
either
1. start a new process
2. open up a new form
to start a new process use
System.Diagnostics.Process.Start(fileToStart);
for opening a new form you can either open it is a dialog or as just a new form
that would be
this.Show(theForm);
or
this.ShowDialog(theForm);
sir i did not understand it please can u explain it......
i am not using any other form except this one......