|
Thanks ppl, for all your answers. Appreciate it
|
|
|
|
|
yeah that could be done, but what if the user is currently using the system and the the perform click event occurs after the timer, it would interrupt his work. !!
|
|
|
|
|
It doesn't take control of the mouse and click the button! It just calls the Button's protected OnClick method internally.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Hello Everyone-
I'm learning C#. I am working with adding some images into an application now, for example, on a button. When I select Image, I am presented with a couple of options. I can import an image under "Local Resource" or I can import the image under "Project Resource File". I am wondering what the difference is between the two, and which one I should be using?
It appears that when I select an image to be imported into the project resource file, the next time I compile it, the executable is bigger, so I'm assuming that the images are compiled into the exe? (Ie, so I do not have to distribute individual image files with my application??)
Thank you!
|
|
|
|
|
Yes, the image is compiled into the .exe (in both cases).
A "Project Resource" is shared between all forms in the project, so you can reuse the image in multiple forms.
A "Local Resource" is available only in that single form. You could create multiple local resources with the same image, but that would embed multiple copies of the image in your .exe.
|
|
|
|
|
Ahh! Makes perfect sense! Awesome, thank you!!
|
|
|
|
|
Daniel Grunwald wrote: A "Project Resource" is shared between all forms in the project, so you can reuse the image in multiple forms.
A "Local Resource" is available only in that single form. You could create multiple local resources with the same image, but that would embed multiple copies of the image in your .exe.
Thanks!
Neat, I never knew that. I always just picked "Project resource". That worked, so that was good enough for me.
|
|
|
|
|
But
If you import image from Project Resource File, your Application will NOT RUN after Dotfuscator.
If you import image from Local Resource, your Application will RUN OK after Dotfuscator.
|
|
|
|
|
Is there any way to draw high quality text glyph by glyph using GDI+?
When we draw a String using GraphicsPath.AddString, The SubPathes in the main path are glyph outlines. but it seems in small fonts the quality of Drawing string this way is not acceptable.
Is the result of GraphicsPath.AddString equal to GetGlyphOutline API function?
any help will be appreciated
|
|
|
|
|
Hello. I've done a lot of searching on how to covert text to a wav file using C# and have been able to get it working. However, it seems that when i play that wav file (i've tried it with WinAmp and Windows Media player), it plays at a lower volume than an mp3 file. I've tried setting the volume of the SpeechSynthesizer to 100 but it still doesn't play at the same level as an mp3 file. Can anyone help with this or steer me in a direction? Thanks in advance.
|
|
|
|
|
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.
|
|
|
|