|
The volume of WMP is the same, what is different is the level in your wav file. You can use filters to increase that level, but you'd do better to change your existing code to record at a higher level, if you can.
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.
|
|
|
|
|
How can I convert Glyph Index to Unicode encoding?
The GetCharacterPlacement API function is useful for convert a sequence of unicode carachters to Glyph Indices, but is there a solution for convert a sequence of Glyph Indices to unicode carachters?
any help will be appreciated.
|
|
|
|
|
it has problay discussed lots of times before, but i can't find the solution.
private void button1_Click(object sender, EventArgs e)
{
Form2 mw2 = new Form2();
mw2.Show();
}
this way keeps creating new instances of the same class and therefor new windows/forms.
i would like to do it as in the code below, create only one instance and keep it active and if i like to see it, make it visisble again.
i would like to creatre a sort of test window, where i can see in a richtext what my main class is doing.
thnx for reading in advance.
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Modales_window
{
public partial class Form1 : Form
{
Form2 mw2 = new Form2();
public Form1()
{
mw2.closingeventhandler += new Form2.ClosingEventHandler(mw2_closingeventhandler);
InitializeComponent();
}
void mw2_closingeventhandler()
{
}
private void button1_Click(object sender, EventArgs e)
{
if (!mw2.Created)
{
mw2.Show();
}
else
{
MessageBox.Show("already open", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
private void button2_Click(object sender, EventArgs e)
{
textBox1.Text = Application.OpenForms.Count.ToString();
}
}
http://www.codeproject.com/Messages/3043750/Re-two-forms.aspx[^]
Bad = knowing 2 much
|
|
|
|
|
You need to hook up to the closing event in form2, so that form1 knows when form2 is closed, and resets it to null. Then use a null check to create a new form. OR change the code in form2 so that it never gets closed, it just hides itself.
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.
|
|
|
|
|
wel, my goal was to keep the class going.
as a sort of debugging window and make a reapear when needed.
using the same button that created the original window.
i know there are other possibilites to do this.
by creating a simple class, store data, a array to hold the classes and create a new instance of Form2.
Form2 contains a RichTextBox so i can display things of interest to me.
i added a FormClosing Event + a Callback in Form2
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
namespace Modales_window
{
public partial class Form2 : Form
{
public delegate void ClosingEventHandler();
public event ClosingEventHandler closingeventhandler;
public Form2()
{
InitializeComponent();
}
protected virtual void OnClosingEventHandler()
{
if (closingeventhandler != null)
{
closingeventhandler();
}
}
private void ModalesWindow2_FormClosing(object sender, FormClosingEventArgs e)
{
OnClosingEventHandler();
}
}
}
but this solution doesn't prevent the 'Cannot access a disposed object' error mw2.Dispose();
public Form1()
{
mw2.closingeventhandler += new Form2.ClosingEventHandler(mw2_closingeventhandler);
InitializeComponent();
}
void mw2_closingeventhandler()
{
mw2.Dispose();
}
now i tried this, the same button creates/togles the visibillity of the window.
but once you close Form2 with the 'close' button of the form i return to 'Cannot access a disposed object' error
private void button1_Click(object sender, EventArgs e)
{
if (!mw2.Created)
{
mw2.Show();
}
else
{
if (mw2.Visible == true)
{
mw2.Visible = false;
}
else
{
mw2.Visible = true;
}
}
}
having come this far, i'm intrested in both.
1 - how to work around 'Cannot access a disposed object'
if you try to open the window again with the same button once you closed it with the RED X button of the form.
You need to hook up to the closing event in form2, so that form1 knows when form2 is closed, and resets it to null. Then use a null check to create a new form
2 - prevent the RED X button to close it and mw2.Visible = true
change the code in form2 so that it never gets closed, it just hides itself.
please show me what you have in mind.
thank you and kind regards
p.s. as a non native english speaker, i hoped to explained myself wel
p.p.s the most simple work around is to set the FormBorderStyle = none , but i like to learn
: )
Bad = knowing 2 much
|
|
|
|
|
i found 1 solution
private void ModalesWindow2_FormClosing(object sender, FormClosingEventArgs e)
{
OnClosingEventHandler();
e.Cancel = true;
this.Hide();
}
works flawles.
: )
but now i like to know the second answer.
how to work around 'Cannot access a disposed object'
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Modales_window
{
public partial class Form1 : Form
{
Form2 mw2 = new Form2();
public Form1()
{
mw2.closingeventhandler += new Form2.ClosingEventHandler(mw2_closingeventhandler);
InitializeComponent();
}
void mw2_closingeventhandler()
{
}
private void button1_Click(object sender, EventArgs e)
{
if (!mw2.Created)
{
mw2.Show();
}
else
{
if (mw2.Visible == true)
{
mw2.Visible = false;
}
else
{
mw2.Visible = true;
}
}
}
private void button2_Click(object sender, EventArgs e)
{
textBox1.Text = Application.OpenForms.Count.ToString();
GetOpenFormTitles();
}
private void GetOpenFormTitles()
{
Collection<string> formTitles = new Collection<string>();
try
{
foreach (Form f in Application.OpenForms)
{
formTitles.Add(GetFormTitle(f));
}
}
catch (Exception ex)
{
formTitles.Add("Error: " + ex.Message);
}
this.listBox1.DataSource = formTitles;
}
private delegate string GetFormTitleDelegate(Form f);
private string GetFormTitle(Form f)
{
if (!f.InvokeRequired)
{
return f.Text;
}
else
{
GetFormTitleDelegate del = GetFormTitle;
object[] param = { f };
System.IAsyncResult result = f.BeginInvoke(del, param);
System.Threading.Thread.Sleep(10);
if (result.IsCompleted)
{
return "Different thread: " + f.EndInvoke(result).ToString();
}
else
{
return "Unresponsive thread";
}
}
}
private void button3_Click(object sender, EventArgs e)
{
mw2.Close();
}
}
}
i added a Third button
mw2.Close(); closes the window, but doesn't free up the used recources
but private void GetOpenFormTitles() still shows the class is somehow active.
Application.OpenForms.Count.ToString(); results in 2
how do i free up the used recources and start all over again?
kind regards
Bad = knowing 2 much
|
|
|
|
|
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.
|
|
|
|
|