|
Do you need to serialize your main form? If not, don't serialize it. Whatever object you're trying to serialize, make sure it doesn't contain a reference to the main form, otherwise it will try to serialize it. If it is referencing the main form for a good reason, then add the NonSerializedAttribute to it.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Is Jesus the Jewish Messiah?
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
OK, I see my problem: the serializable class exports an event. The first pass through does not subscribe to the event and serialization works OK, but the second pass does subscribe to the event and the handler is in the mainform code. Hence the seriealization exception I get.
So I have to move the event out of the serialization class. Wasn't happy with the code anyway.
Stewart DIBBS
|
|
|
|
|
I am using MethodInfo.Invoke() to invoke a method that has a ref keyword on a value type in it's parameter list. Example:
MyMethod(int p1, ref int p2)
However there does not seem to be a way to to tell invoke to pass parameter 2 by reference.
I tried to use ParameterModifier. But it has work just with COM interop.
Please help, I am getting an error because it is trying to pass by value instead of pass by reference.
King Regards,
XironiX
[ _ Always there is another way _ ]
-- modified at 11:48 Monday 8th May, 2006
|
|
|
|
|
int param1 = 5;
int param2 = 10;
object[] arguments = { param1, param2 };
theMethod.Invoke(arguments);
param2 = (int)arguments[1];
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Is Jesus the Jewish Messiah?
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
Dear Judah,
Thanx for your instant reply.I have another problem with pass-by-ref concept.I have two overloaded methods with the following signatures :
public int MyMethod(ref int intParam)
{
intParam += 100;
return Math.Sin(intParam);
}
public int MyMethod(int intParam)
{
intParam += 100;
return Math.Sin(intParam);
}
When I use typeof(MyClass).GetMethod("MyMethod"); ,System.Reflection.AmbiguousMatchException is throw !!
If I use
typeof(MyClass).GetMethod("MyMethod",new Type [] {typeof(int)});
The second overloaded method with the value parameter invokes.
How can I force the CLR to run the first method and pass the parameter to it by reference ?
Regards,
Xironix
[ _ Always there is another way _ ]
-- modified at 3:13 Tuesday 9th May, 2006
|
|
|
|
|
I'm opening the port as a file by pinvoking several win32 calls similar to the Mc++ implementation below. The problem is that each write causes a .1s stall in my app. I'm only writing 4bytes max at a time, and the delay's remained constant from 2400-19200 baud so actually stuffing the bytes into the uart buffer doesn't appear to be the source of my problem.
http://www.codeproject.com/managedcpp/howtocomport.asp
|
|
|
|
|
|
Ok, did an ~20s trial run.
Slowest lines of code were two where I called CSerialPort.Write(...) ~8s net. and the actual write to the stream in Write.
Slowest methods were:
Forms.UnsafeNativeMethods.WaitMessage() 18s
System.Threading.WaitHandle.WaitOne() 8s
UnsafeNativeMethods.* isn't listed in MSDN help.
Honestly, I don't see that I'm any closer to a resolution.
public void Write(byte[] buf)
{
try
{
m_MyStreamWriter.Write(buf);
m_MyStreamWriter.Flush();
}
catch (Exception e )
{
Console.WriteLine(e.ToString());
}
}
|
|
|
|
|
What I think I need is a way to do the write asyncronously, although that potentially opens up a whole new can of worms with multiple writes piling up over top of each other. Agregating multiple messages and sending them in a single chunk would be another option but I don't currently have access to the blackbox I'm interfacing against, nor do I have specs on its uart or how frequently it checks the buffer.
-- modified at 15:23 Monday 8th May, 2006
Something else that's occured to me, could my not having a null modem hooked up be causing the delay with windows trying and failing to send before giving up?
|
|
|
|
|
Hi PrjectCode Team Thank You For Your Successfull Site That Help Many Developers And Beginners To Develop Their Projects Really I'd like To Ask A Question That Question Is:
How Can I Load The SQL Server DataBases Into A Combo Box Using The ADO.Net And C# And Their Tables In Another One According To The Database That I'll Choose From The Combobox1 ?
Thank You For All Your Efforts
Night Attack
|
|
|
|
|
You Might Want To Break Your Question Down Into Specific Problems Or Issues You Are Having, Currently Your Question Is A Bit Garbled And Does Not Make Much Sense.
Also, We Tend To Reserve Upper Case First Characters For The Beginning Of A Sentence, A Person's Name Or A Place Name.
Current blacklist
svmilky - Extremely rude | FeRtoll - Rude personal emails | ironstrike1 - Rude & Obnoxious behaviour
|
|
|
|
|
hi all,
i have two forms one in my language and one in english. first i open the one in my language then i select english one from menustrip (language option).
but i want the first one to be closed when i open the second one.
and vice versa. (if english is open and i select the native one, i want english one to be closed.)
if i use Close(); when opening the second form, both forms are closed
how can i achieve my goal ?
help please,
bye.
|
|
|
|
|
Have you tried hiding the form instead of closing it? form_english.hide()?
|
|
|
|
|
From your post I assume that you've implemented the same form twice, just with different languages for the user interface. That isn't the best way to do it. .NET provides good support for globalization and lovalization of windows applications, which is very good covered on MSDN[^].
To change the lanuage of your user interface at runtime e.g. via the menustrip, take a look at my article: Change culture of user interface at runtime[^].
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook
www.troschuetz.de
|
|
|
|
|
Change your Program.cs file to this:
static class Program
{
public static ApplicationContext CurrentContext;
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
CurrentContext = new ApplicationContext(new Form1());
Application.Run(CurrentContext);
}
}
Then in your handler to close Form1 do this.
Form2 dlg = new Form2();
dlg.Show();
Program.CurrentContext.MainForm = dlg;
base.Close();
"What classes are you using ? You shouldn't call stuff if you have no idea what it does" Christian Graus in the C# forum
led mike
|
|
|
|
|
I'm developing a library, when I try to convert float to string, in case of a point it set a coma, what can I do about it?
|
|
|
|
|
A comma usually denotes a thousands seperator, at least in English numbering. For example, one might write 1000 as
1,000
Is this what you're trying to parse? Or is a comma truely in place of a decimal point, for example, instead of 1.5 it's 1,5?
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Is Jesus the Jewish Messiah?
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
That's exactly what's happening, but the coma are in the point place in one of my projects, not in others, I suspect is something related with my project language, any idea please?
|
|
|
|
|
Specify a fixed culture when converting the float to a string.
float x = (float) 0.6;
x.ToString(new CultureInfo("en-US")));
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook
www.troschuetz.de
|
|
|
|
|
Yes for sure, thats right, the point it's do that in a global level, (in my app domain) anyway was really helpfull you idea Troschutz, wolud you help on that too??? thnx & sorry for the inconvenience.
|
|
|
|
|
If no culture is specified, ToString and similar methods use the value of the CurrentCulture property of the current thread. So do:
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook
www.troschuetz.de
|
|
|
|
|
Thnx, now I'm a mutch better Software engineer..
|
|
|
|
|
No, it gives "0?6" where "?" is replaced by whatever the user specified in regional settings for US English.
float x = (float) 0.6;<br />
x.ToString(new CultureInfo("en-US", false)));
gives "0.6" no matter what the regional settings are as you specifically istruct it to ignore any custimization made for the culture.
|
|
|
|
|
Hello Friends
I have a form with several controls on it,
Now I want to know on what control user clicks,
It means I want to show messagebox like this :
BRAVO! YOU CLICKED ON BUTTON1
I don't want to write a code in all cotrol's MouseDown event and i want to write it in form's mouse click event once.
Thank You
|
|
|
|
|
Won't work like you want because the Click event of the Form won't fire when a control on it is pressed. You could nevertheless write a recursive function to bind all events:
private void BindMouseDown(Control control) {
control.MouseDown += new MouseEventHandler(OnAnyControl_MouseDown);
foreach (Control subControl in controls.Controls)
BindMouseDown(subControl);
}
BindMouseDown(this);
The sender argument in your handler will then tell you which control was clicked.
|
|
|
|