|
I have been trying to figure something for last couple of hours, but i'm unable to solve it & need some help.
I have project with 2 forms:
Form1 - MDI container
child_form1 - parent set to Form1
on menu_form i have MenuStrip called "MenuStrip1" and item called "item1".
on the item1 i have following code:
private void item1_Click(object sender, EventArgs e)
{
child_form1 cf1 = new child_form1();
cf1.MdiParent = this;
cf1.Show();
}
now, for problem, i want to be able to modify Form1 menustrip items from the child menu. (specifically i want to uncheck the item1 when form is closed, but for the argument sake i just need to get proper handle/pointer to menu item).
So i've tried doing something like this:
Form main_form = this.MdiParent;
main_form.Controls["menustrip1"].Controls["item1"].Checked = false;
but it seems i can only get pointer/handle to the menustrip as a whole, but not to the item itself.
main_form.Controls["item1"] is not valid pointer
main_form.Controls["menustrip1"].Items does not exists
Am i missing something ??
How do i get handle to form's menustrip item(s) from another child form ?
Would appreciate any help in resolving the issue...
EDIT:
i managed to solve the problem myself, leaving msg as it might help others with same problem.
modified on Saturday, October 31, 2009 4:38 AM
|
|
|
|
|
I found the problem.
The modifiers of the menu item were set to "private", so child form could not "see" it.
Now i've changed to "Public" and this code allow to access it:
Form1 main_form = this.MdiParent as Form1;
main_form.item1.checked = false;
|
|
|
|
|
THat is not a good idea - it works, but it is considered bad practice. Why? Because it locks the child form to the design of the parent form. You cannot now change the design of the parent form unless you check that this will have no effect on the child form.
The recommended way to do this is to generate an event in the child form which is subscribed to and handled by the parent form. The parent form then takes the action depending on what controls it is using.
To do this:
In the child form:
public partial class frmChild : Form
{
public event EventHandler Changed;
protected virtual void OnChanged(EventArgs e)
{
EventHandler eh = Changed;
if (eh != null)
{
eh(this, e);
}
}
private void DoSomethingToChangeData()
{
OnChanged(null);
}
}
----- The assign to eh is in case the handler changes between null check and exec. (Unlikely, but possible)
----- The null check is to ensure there is a handler. If not, better to ignore it gracefully, than to rely on the thrown exception (NullReferenceException)
In the Parent form:
public frmParent()
{
frmChild.Change += new frmChange.ChangeHandler(Changed);
}
private void Changed(object sender, EventArgs e)
{
}
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
thank you for the reply.
I'll do as you advised.
|
|
|
|
|
this code not work in my project so i m doing ao\nother code but this code only one item to be access i want all items access on mdiparent.
my code is
Form 1:
private void pasteToolStripMenuItem_Click(object sender, EventArgs e)
{
// richTextBox1.Paste();
try
{
Form frmChild = this.MdiChildren.First(frm => frm.Name == "@new");
RichTextBox txt = (RichTextBox)frmChild.Controls.Find("richTextBox1", true)[0];
txt.Paste();
//MessageBox.Show(txt.Text);
}
catch (Exception)
{
MessageBox.Show("frmChild is not open");
}
}
|
|
|
|
|
Dear All,
I am using the bellow lines
mshtml.HTMLHeadElementClass elDynHead = null;
foreach (IHTMLElement elcol in (IHTMLElementCollection)document.getElementsByTagName("HEAD"))
{
if (elcol.ToString() == "mshtml.HTMLHeadElementClass")
{
elDynHead = (mshtml.HTMLHeadElementClass)elcol;
}
}
it works in Develpement system, but not in the client system
it throws the following error
Error :: System.InvalidCastException: Unable to cast COM object of type 'System.__ComObject' to class type 'mshtml.HTMLHeadElementClass'. COM components that enter the CLR and do not support IProvideClassInfo or that do not have any interop assembly registered will be wrapped in the __ComObject type. Instances of this type cannot be cast to any other class; however they can be cast to interfaces as long as the underlying COM component supports QueryInterface calls for the IID of the interface.
at PAW_URL.clsURLMON.browser_DocumentComplete(Object pDisp, Object& URL)
so i think i have to Register mshtml in GAC.
But i dont know how to do it.
can some one help me how to Register the mshtml.dll in to GAC.(urgent please)
thanks in Adavnce
|
|
|
|
|
jasome wrote: so i think i have to Register mshtml in GAC.
You are utterly wrong. The mshtml DLL is obviously not present on the target system. It's a COM dll, that's what the error message says. Therefore, it's almost certainly not .NET, and cannot be put in the GAC.
If you were to google the error message, you'd get a ton of previous questions like this[^] one.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Hi Thanks,
Do you have any idea ? How to overcome this problem.
if it is please do guide me
thanks
|
|
|
|
|
Hi all,
any way i'v found the solution.
we need to run a exe called "vs_piaredist.exe"
thanks to all.
|
|
|
|
|
Because it installs it, right.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Hi,
I want to get the current speed of writting into or reading out from my hard disk.
How can I make that? Is there any code resouces ?
|
|
|
|
|
Write a big chunk of data and time it.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Sorry.It's my fault.
I don't want the speed,but the throughput in a period,for example,in one minuter.So how to realize it?
|
|
|
|
|
OK, in that case, I have no idea.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Perhaps over WMI[^]?
I are Troll
|
|
|
|
|
I am starter in C# programming and I tried my hands at multi-threaded programming.I used an algorithm and run its thread concurrently to call a function which has the following body.
lock (currlock) {
if (N[int1] > N[int2]) {
temp = N[int1];
N[int1] = N[int2];
N[int2] = temp;
}
}
I call showArray(N); before and after the execution of the sorting code.
If I run this code there will be no error but the output array displayed will seen unsorted.
However, if I uncomment the showArray(N); or if I put any Console.writeline("..."); the array displayed will come sorted. I am very much surprised as well as confused on this issue... I can't resolve it... I thank you in advance for any help.
Raj
|
|
|
|
|
niranjanR wrote: I am starter in C# programming
niranjanR wrote: multi-threaded programming
These two concepts are mutually exclusive. Learn C# first, then worry about multi threading.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Graus,
Thanks for your advice but one will try to learn what he/she is interested in and what is needed at the time...
Raj
|
|
|
|
|
niranjanR wrote: and what is needed at the time...
How could anything be 'needed at the time' if you're new to C# ? Oh, you're in the third world, so that probably means that you are very new to C# and yet are working as a paid programmer and someone is paying for your first experiments in multi threaded programming. What a disgrace.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
It is so nice of you Graus to comment nonsense than answering the problem...
But I want to remid you that if you can't answer the question.. or you don't want to...answer, nobody is asking you to jot your derogatory comments.... You don't know where I am and what am I doing so stay outta my business.
|
|
|
|
|
niranjanR wrote: But I want to remid you that if you can't answer the question..
Who said I can't answer it ? I suspect no-one can, because you've not posted all the pertinent code, but I have no doubt I could solve the issue if I set myself to doing so, I've done quite a bit of multi threaded code.
niranjanR wrote: nobody is asking you to jot your derogatory comments....
True, I provide that service of my own volition.
niranjanR wrote: You don't know where I am
True, I don't know where you are, niranjan. I think I can guess tho. The questions that start with 'I am new' and go on to some incredibly complex task and show no signs of people having tried to help themselves, tend to all come from the same continent.
niranjanR wrote: what am I doing
You're apparently trying to write multi threaded code despite not even known much C# yet.
niranjanR wrote: so stay outta my business.
Well, don't post here if you don't want me to answer.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
You must be the worst helper...
I posted here seeking some advices nd not insults..... you are not helping in anyway and only trying to frustate and infuriate... so don't reply if you have no answers to the problem raised ..
And for sure.. u r a racist.. u r of no use.. u r urself frustated..
|
|
|
|
|
niranjanR wrote: You must be the worst helper...
Well, to people who are ignorant and unwilling to learn, I probably seem that way.
niranjanR wrote: you are not helping in anyway and only trying to frustate and infuriate...
My aim is always to help. Sometimes the best help I can give is to tell people they are not smart enough or experienced enough for the task at hand. Just because it's not well recieve, doesn't mean it's not good advice. Most people who used to post here a lot, just don't bother anymore, because of people like you.
niranjanR wrote: so don't reply if you have no answers to the problem raised ..
I know the answer, I told you. You don't understand C# enough to be doing multi threading. You have a race condition because your code is not well thought out.
niranjanR wrote: u r a racist..
Not even remotely. I have good indian friends, and I have hired indian programmers many times. The ones I hire, are all in the west. The ones I've hired who were in India, were uniformly useless. And the people who post here asking us to do their work for them, are generally worse than useless. I can't help that. I just tell the truth, but I am certainly not racist.
niranjanR wrote: u r of no use
Not to lazy people, apparently.
niranjanR wrote: . u r urself frustated..
ROTFL !!! Why am I frustrated ? That's just priceless. My life is perfect, I couldn't be happier. The amusement I get out of people who are clueless, ask me for help and then think they can insult me because they don't like the answer, are just the icing on the cake.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
niranjanR wrote: I am very much surprised as well as confused on this issue... I can't resolve it... I thank you in advance for any help.
From the portion of code you have posted it looks to me like it is working as coded. Your program is a set of sequential operations which you try to run in parallel. So sometimes you get the result you expect and sometimes not, depending on which thread gets run first. Your use of threads in this case is superfluous as it does nothing to improve the program.
As Christian said earlier, you would be better to spend more time getting familiar with C# basics before worrying about multi-threading.
|
|
|
|
|
It seems to be a synchronization issue here. When you have the function call there, it slows down each iteration thus resulting in a different execution order of the concurrent calls. The fact that your output is right is coincidental because for a larger array, and on a different machine you may still see the unsorted or wrongly rearranged array.
|
|
|
|