|
Does anyone know what the C# WinForm equivalent is of the old VB6 DoEvents() method on forms???
This is the process where a tight loop will allow the form to process events before going back into its' loop.
Thanks!
_____________________________________________
The world is a dangerous place. Not because of those that do evil, but because of those who look on and do nothing.
|
|
|
|
|
Application.DoEvents(). But in many cases it's better to use multiple threads.
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
Well...I have the methods I am calling broken out into a DLL. And I did find the Application.DoEvents() to be fairly non-responsive. (2 or 3 button clicks to end the process)
But I'm not really familiar with spawning threads in a WinForm client. What are the basic steps I would need to do to make the component an independant thread? Or if you know of a tuturial...?
Thanks,
MJ
_____________________________________________
The world is a dangerous place. Not because of those that do evil, but because of those who look on and do nothing.
|
|
|
|
|
There's sure to be one on CodeProject somewhere, but here's a brief example:
using System.Threading;
Thread thread=null;
thread=new Thread(new ThreadStart(this.ThreadMethod));
thread.IsBackground=true;
thread.Start();
Thread.Sleep(0);
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
Does anybody know how I can access the MessagBoxIcons directly? I want to stick one on a Form (not a MessageBox). Is there some sort of internal imagelist in the Framework?
|
|
|
|
|
If you use Reflector to decompile the .net framework you will see that the native MessageBox method is called. The MessageBoxIcon is just an enum. The value is passed to the native func as an int.
I suggest opening the native lib with VS.NET and ripping the icons.
|
|
|
|
|
in this folder : ( where your drive goes inplace of " D " )
D:\Program Files\Microsoft Visual Studio .NET\Common7\Graphics\icons
there you will find them , listed under " Computer " i think , although they are embeded in .net for the messagebox's
Vb:
<font color="blue">Public Function</font> TwinsOnWay(<font color="blue">ByVal</font> twins <font color="blue">As String</font>) <font color="blue">As String <br> Select Case</font> twins<br> <font color="blue">Case</font> "Gender" <br> <font color="blue">Return</font> "Two Girls" <br> <font color="blue">End Select <br> End Function</font> <br>
|
|
|
|
|
The icons are not part of the .NET Framework. The internal implementation of MessageBox.Show just calls the Platform SDK function MessageBox , passing a flag value that specifies the icon you want displayed. The icons themselves are stored as resources in user32.dll.
|
|
|
|
|
Hey all,
How can I create a get/set method that returns the Nth item of an array?
|
|
|
|
|
What do you mean?
The easiest way is to just do array[x]
What exactly are you trying to do?
|
|
|
|
|
Well, I have a class Foo(). Inside Foo is a private array of another class, Bar().
public Foo()
{
private Bar[] myBars = new Bar[10];
}
When I instantiate Foo, I need to be able to assign a value to the array of Bars:
myFoo.myBars[n].someValue = 10;
So how can I do this?
|
|
|
|
|
Such a property is called an indexer. You can read a tutorial on them in the MSDN documentation (under "indexers->tutorial (C#)")The following is an example...
public class MyArray {
...
public Object this[int index] {
get {
return _Items[index];
}
set {
_Items[index] = value;
}
}
private Object[] _Items;
}
|
|
|
|
|
I am having trouble figuring out how to progamatically save images from a website using this class. I tried this:
private void SaveImages(string url)
{
int s = Application.StartupPath.IndexOf("bin\\Debug");
Bitmap img = new Bitmap(url);
img.Save(Application.StartupPath.Remove(s,9) + "image1.gif", ImageFormat.Jpeg);
} I get this error message though:
URI formats are not allowed.
Do I have to use a stream object to do this? If so how do I load the remote image into the stream?
Thanks cause I'm lost;)
Steve
McLenithan
Is Bert Evil? | Homer: "Hello, operator, gimme the number for 911!"
|
|
|
|
|
here ya go , by chance i built this a few days ago to help someone on another forum
C#:
<font color="blue">private</font> <font color="blue">void</font> button1_Click(<font color="blue">object</font> sender, System.EventArgs e) <br> { <br> System.Net.WebClient web=<font color="#0000FF">new</font> System.Net.WebClient(); <br> System.IO.StreamReader sr=<font color="#0000FF">new</font> System.IO.StreamReader(web.OpenRead("http://www.codeguru.com/forum/images/icons/icon8.gif")); <br> System.Drawing.Image i=System.Drawing.Image.FromStream(sr.BaseStream); <br> <font color="DarkGreen">
hope it helps
Vb:
<font color="blue">Public Function</font> TwinsOnWay(<font color="blue">ByVal</font> twins <font color="blue">As String</font>) <font color="blue">As String <br> Select Case</font> twins<br> <font color="blue">Case</font> "Gender" <br> <font color="blue">Return</font> "Two Girls" <br> <font color="blue">End Select <br> End Function</font> <br>
|
|
|
|
|
[Mr. Burns Eexxcellent!] Thanks dynamic
Steve
McLenithan
Is Bert Evil? | Homer: "Hello, operator, gimme the number for 911!"
|
|
|
|
|
Also ....
Instead of using .Remove(s,9) you can use the System.IO.Path static methods: GetParentDirectory()
|
|
|
|
|
Thanks AK. I didn't even realize that was there;)
Steve
McLenithan
Is Bert Evil? | Homer: "Hello, operator, gimme the number for 911!"
|
|
|
|
|
I have a XML setting file which has symbol "&" inside.The below code
got exception from ReadXML since the "&"
DataSet ds = new DataSet();
ds.ReadXml(m_xmlPath);
Please help me how to use ReadXML or other methods to solve the problem.
|
|
|
|
|
If the '&' is in the text it works
XmlDocument xd = new XmlDocument();
xd.AppendChild(xd.CreateNode(XmlNodeType.Element, "test", ""));
xd["test"].InnerText = "&";
But if the '&' is in the XML tags it will fail
xd.AppendChild(xd.CreateNode(XmlNodeType.Element, "&", ""));
I'm not sure, but I think that there is a '&' included somewhere inside the XML tags by the DataSet
|
|
|
|
|
Have you tried to replace the & charatcter with & entity reference? I think that all special characters in an XML (or HTML) file should be replaced by their character entity references or numeric references (especially in element attributes) i.e.
& for ampersand (&)
' for apostrophe (')
" for double quote (") etc.
Let me know if this helped.
Rado
|
|
|
|
|
This is how it should be
& for ampersand (&)
' for apostrophe (')
" for double quote (") etc.
Rado
|
|
|
|
|
Cool,it works well.
thank you a lot.
John:
|
|
|
|
|
I have an update polling task on a thread that checks an internet server for updates. If an update is available it fires an event. It turns out that the event handler gets executed on the same thread as the task (sound logical).
BUT
I need the polling thread to die and the handler method to execute on the main thread. How can I do this?
I had a similar problem with Threads and Winforms. Only the owner thread can interact with the control. The solution to that one was a simple Control.Invoke().
|
|
|
|
|
I had to do something similar to this but because I come from the Win32 C++ world I took an API approach so there may be a better C# way of doing this. Anyway, what I did was an override of the WndProc method on the main thread and used post message from the polling thread. As I recall I was under pressure for a fast workaround and did not have time to thoroughly research an optimal solution. I would be interested in what you come up with.
|
|
|
|
|
Hey!!
That is exactly the first thing that i came up with before I figured out how to do Thread<->Winforms properly.
However this is a different problem - there is no WndProc to override.
I decided to put the poller on a seperate thread because polling the server can really delay application startup. The application is running from an ApplicationContext. The Init method of the app context calls the Updater.Check() method, which attaches an event handler, kicks off the poller thread, and continues. When the event is fired the handler will execute on the same thread as the poller. This will not work for me because I have no idea how long the update will take. Btw, I have the downloader run on its own thread. Obviously, using the event will not work.
|
|
|
|