|
You found the first solution - cancel the closing event and hide it instead. This does not require a delegate. If your delegate does fire, then you need to set your instance of Form2 inside Form1 to null, and then your code will find that it is null and create a new instance when it wants to show it. This fixes the 'accessing disposed object. error b/c you instead know to create a new one. However, it will mean that you lose any data, so the solution you're using is the right one, I think.
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.
|
|
|
|
|
This does not require a delegate.
this delgate was there before i asked the question
: )
then you need to set your instance of Form2 inside Form1 to null
how to set a class to NULL or destroy it?
p.s. i also bought a mac, i wanted to know how it's like.
after 30 minutes of usage i already saw it was far superior in usage.
so many handy gadgets that make profesional users more productive.
: )
p.p.s i'm not a proefesional coder, i'm more advanced than a beginner due to the years i have been doing it, but i learned alot last night.
Bad = knowing 2 much
|
|
|
|
|
I am trying to teach myself C# and I have started writing a web browser based on mozilla gecko. Right now I am working on storing and retrieving bookmarks from an xml document.
I can save and read the bookmarks just fine. However in order to see a bookmark I just added I must exit the program and restart it. I have tried calling the function that populates the menu after the new bookmark is written to the xml file but it runs and loads everything but the new bookmark.
Below is the code I use to populate the menus.
public void PopulateBM()
{
string filename = "bookmarks.xml";
if(File.Exists(filename))
{
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(filename);
XmlNodeList xmlnode = xmldoc.GetElementsByTagName("Bookmark");
for (int i = 0; i < xmlnode.Count; i++)
{
ToolStripMenuItem item = new ToolStripMenuItem();
item.Text = xmlnode[i].FirstChild.InnerText;
item.Tag = xmlnode[i].LastChild.InnerText;
item.ToolTipText = xmlnode[i].LastChild.InnerText;
item.Click += new EventHandler(this.item_Click);
this.bookmarksToolStripMenuItem.DropDownItems.Insert(3,item);
}
}
}
|
|
|
|
|
...And your problem exactly is?
Life is a stage and we are all actors!
|
|
|
|
|
When I add a bookmark I want the dynamic menu to update and show the new bookmark without me having to restart the program.
|
|
|
|
|
You should post the code you are using to update the bookmarks,not the code used to load from the file.
Life is a stage and we are all actors!
|
|
|
|
|
the code I posted does both.
|
|
|
|
|
You just need to update the menu in the same manner as you used to populate it from file.You really needn't to use logic based on FileSystemWatcher.
Life is a stage and we are all actors!
|
|
|
|
|
Thats just it. When I run the code again nothing happens. It completes and the menu stays the same. I tested this by not populating it on application start and only trying to populate after adding a new bookmark. When I do that the menu stays empty.
|
|
|
|
|
anyone else have any ideas? I am stuck until I figure this out
|
|
|
|
|
Try looking into a FileSystemWatcher instance. Set it to the file's directory, and every time you get told that a file has changed, compare the changed filename to "Bookmarks.xml" or whatever you've called your bookmarks file. If your file has changed, then repopulate the menu.
Alternatively, you could add an item to the menu every time you bookmark something. That would be a lot simpler, but would only work if your application was the only one using the file
Between the motion
And the act
Falls the Shadow
|
|
|
|
|
What I am asking is how do I "repopulate" the menu?
|
|
|
|
|
You would repopulate it using the same method you populated it to start with
Between the motion
And the act
Falls the Shadow
|
|
|
|
|
Hi,
If i have a lot of function there is an easy way to insert them by runtime and not by code?
For example instead of this:
public class A
{
MyEvent m_Event;
List<MyEvent> m_EventList;
public bool Func_1(int num) { MessageBox.Show("1"); return num > 1 ? true : false; }
public bool Func_2(int num) { MessageBox.Show("2"); return num > 2 ? true : false; }
public bool Func_3(int num) { MessageBox.Show("3"); return num > 3 ? true : false; }
public bool Func_4(int num) { return num > 4 ? true : false; }
public bool Func_5(int num) { return num > 5 ? true : false; }
public bool Func_6(int num) { return num > 6 ? true : false; }
public bool Func_7(int num) { return num > 7 ? true : false; }
public bool Func_8(int num) { return num > 8 ? true : false; }
public A()
{
this.m_Event += new MyEvent(Func_1);
this.m_Event += new MyEvent(Func_2);
this.m_Event += new MyEvent(Func_3);
this.m_Event += new MyEvent(Func_4);
this.m_Event += new MyEvent(Func_5);
this.m_Event += new MyEvent(Func_6);
this.m_Event += new MyEvent(Func_7);
this.m_Event += new MyEvent(Func_8);
}
}
I want this code to look like this:
public class A
{
MyEvent m_Event;
List<MyEvent> m_EventList;
public bool Func_1(int num) { MessageBox.Show("1"); return num > 1 ? true : false; }
public bool Func_2(int num) { MessageBox.Show("2"); return num > 2 ? true : false; }
public bool Func_3(int num) { MessageBox.Show("3"); return num > 3 ? true : false; }
public bool Func_4(int num) { return num > 4 ? true : false; }
public bool Func_5(int num) { return num > 5 ? true : false; }
public bool Func_6(int num) { return num > 6 ? true : false; }
public bool Func_7(int num) { return num > 7 ? true : false; }
public bool Func_8(int num) { return num > 8 ? true : false; }
public A()
{
for(int i=1;i<=8;i++)
this.m_Event += new MyEvent(Func_ + i.ToString());
}
}
is there some way to do something like this?
|
|
|
|
|
Yes. You can use System.Reflection and Delegate.CreateDelegate to help. The basic sequence of events is:
- Get the class' Type
- Get the EventInfo representing m_Event of that Type
- Iterate from one to eight
- Get the method "Func_" + i.ToString()
- Use Delegate.CreateDelegate(typeof(MyEvent), [MethodInfo you just retrieved in the last step])
- Store the return value of that function call in a variable
- Call the AddEventHandler(this, [Delegate you just created and stored in a variable])
That's the basic sequence of events. If you wanted something simpler, but less modular, you could just create a List<MyEvent> and store the functions in there. Then just iterate and add the handler like you normally do.
Between the motion
And the act
Falls the Shadow
|
|
|
|
|
Thanks for your help , it's works
|
|
|
|
|
Cool. I'm glad that you found a solution!
I would have used a (yuck) macro. But, from what I could find, C# doesn't support macros. huh?
However, I did find the following:
A Macro Preprocessor in C#
_____________
Joe
|
|
|
|
|
I just use the C-preprocesor.
|
|
|
|
|
|
Hi I am new to asp.net and c# programming. Can someone give me a clear or line by line explanation of the following code that I can understand and explain somebody about it.
Thanks in advance and the code is
using System;
using System.Collections;
using Claims.SSC.MasterPages;
using CommonService;
using System.Collections.Generic;
namespace Claims.SSC
{
/// <summary>
/// Summary description for Confirmation.
/// </summary>
public partial class Confirmation : System.Web.UI.Page
{
protected string m_sPolicyNumber = string.Empty;
protected string m_sClaimNumber = string.Empty;
//to get the session
CommonService.CommonService SSCS = new CommonService.CommonService();
private UserInfo _UserInfo;
protected void Page_Load(object sender, System.EventArgs e)
{
_UserInfo = SSCS.GetUserInfo(Session.SessionID, false, false, false, false, false);
Master.SetHeader("Claims Service Center", _UserInfo.FullName.ToUpper(), string.Empty,
_UserInfo.PolicyNumber.Length > 0 ? _UserInfo.PolicyNumber : string.Empty);
if (_UserInfo.Origin.ToLower() == AuthenticationService.AuthenticationOrigin.nph.ToString())
{
Master.SetApplicationNavigation(SSCMaster.AuthenticationMethod.NonHolder);
}
else
{
Master.SetApplicationNavigation(SSCMaster.AuthenticationMethod.Holder);
}
Master.TabsToShow = new List<SSCMaster.TabsShown>();
Master.TabsToShow.Add(SSCMaster.TabsShown.MainTab);
Master.ActiveTab = SSCMaster.TabsShown.MainTab; Master.MainTabText = "Confirmation";
// display message
string Msg = SSCS.GetSessionString(Session.SessionID, "ConfirmationMsg");
Message.InnerHtml = Msg;
if (Request.QueryString["Number"] != null && Request.QueryString["Number"] == "false")
{
fldsetClaimSummary.Visible = false;
Master.BottomContent.Visible = true;
Master.BottomContent.InnerHtml = "<br/><br/><br/><br/><br/> ";
}
}
}
}
|
|
|
|
|
I think your question is beyond the scope of this forum. Also, I suspect that Claims.SSC.MasterPages is not a namespace in Microsoft's .NET distribution so any explanation of its functionality would be pure speculation.
|
|
|
|
|
Hi,
I am new to the Dot net C# applications.In my application I have created a toolbar with fixed size and based on the events i need to change the visibility to true or false.On button click when i change the visibility of few of the toolbar buttons the size of the total toolbar buttons is getting changed.
Can someone tell me the right approach to avoid this kind of shrinking in the size of the toolbar buttons.
I used the following code for changing the visibility of the buttons in the toolbar:
toolBar1->Buttons->Item[3]->Visible= false;
Thanks in advance...
|
|
|
|
|
Hey!
I have some features build in but when i command two lines in nothing work!
What is wrong at this two lines?
Code from Server:
//string[] get_Split = get.Split('~');
//int zeit = Convert.ToInt32(get_Split[1]);
if (get.Contains("rHerunterfahren"))
{
System.Diagnostics.Process.Start("shutdown", "-s -t " + zeit.ToString());
}
|
|
|
|
|
What are you trying to do with your code?
Life is a stage and we are all actors!
|
|
|
|
|
When you comment the two lines, zeit and get_Split aren't set to anything or even declared, so the code shouldn't build!
|
|
|
|