|
Create it as a member variable and then use the reference to the open one. For instance:
private DisplayForm _display;
public void ShowForm()
{
_display = new DisplayForm();
_display.Show();
}
public void DoSomethingElse()
{
if (_display != null)
{
txtMyDisplay.Text = _display.SomeTextValue;
}
} It's that simple.
|
|
|
|
|
Hi,
one option of printing is print to file, that prints the cse in a file.
how can I print the file using a printer?
Best wishes
|
|
|
|
|
Hi,
I've got a problem, I am trying to receive WMI events, from remote machine. When I am using asynchronous events, unfortunately I can't connect (I'm getting different errors, mostly access denied). I found that's propably because of using system Win XP SP2. So, I'm receiving events synchronously. But, here is a problem. I have this method:
public void Listen()
{
while (true)
{
ManagementBaseObject mbo = event.WaitForNextEvent();
// do something
}
}
And I am running it on another thread and it's working fine. Another but , I have no idea how to stop WaitForNextEvent method. I've tried abort thread, call Stop method for ManagementEventWatcher and it's still working, until next event come. Does anyone know how to stop this method? Or maybe someone know how to use asynchronous events with Win XP SP2?
Thanks in advance.
Greetings,
Dawid Mazuruk
|
|
|
|
|
Hi,
I've used the following code to do this.
Set the watcher to timeout and code your timeout handler to allow the loop to exit when you've had enough.
AlanN
ManagementEventWatcher watcher = new ManagementEventWatcher(eventQuery);
watcher.Options.Timeout = new TimeSpan(0, 0, 2);
Boolean keepGoing = true;
do {
try {
ManagementBaseObject e = watcher.WaitForNextEvent();
} catch (ManagementException me) {
if (me.ErrorCode = ManagementStatus.Timedout) {
if (I want to stop) keepGoing = false;
} else {
throw me;
}
}
} while (keepGoing);
watcher.Stop();
|
|
|
|
|
Thank you for answer, I have already done it same way, but without if statement, so I have just added it and it's working a little better. So thanks, again.
Greetings,
Dawid Mazuruk
|
|
|
|
|
Hello,
Can you point me out in some directions of how to create a thumbnail of the currently opened web page in my browser, something similar to what Alexa is doing? I would like to loop through all my web site templates and generate a gallery web page.
Thank You,
Razvan
drinking beer is fun
|
|
|
|
|
I've got a feeling that the WebBrowser control allowed you to draw the rendered page to a bitmap. Perhaps that'll help.
|
|
|
|
|
Thank you Ed!
Indeed the web browser has a function - DrawToBitmap which is hidden to the intellisense. Although the summary of the functions states that the function is not supported by the web browser it works very well for all my local templates, but when trying to make a thumbnail of codeproject or yahoo the image returned is blank but strangely enough google.com works
drinking beer is fun
|
|
|
|
|
Hello, I am using the TreeView control (version 2.0) in a Visual Studio 2008 Windows application. Everything works fine on the development computer but when I deploy the program to the client's machine the control produces the following error when the user makes a few clicks on the nodes:
/////////////////////////////////////////////////////
See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.
************** Exception Text **************
System.DivideByZeroException: Attempted to divide by zero.
at System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at System.Windows.Forms.NativeWindow.DefWndProc(Message& m)
at System.Windows.Forms.Control.DefWndProc(Message& m)
at System.Windows.Forms.TreeView.WmMouseDown(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.TreeView.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
************** Loaded Assemblies **************
mscorlib
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
----------------------------------------
CarRent
Assembly Version: 1.0.0.0
Win32 Version: 1.0.0.0
CodeBase: file:///C:/Program%20Files/ISS/CarRent%20Setup/CarRent.exe
----------------------------------------
////////////////////////////////////////////
I couldn't find any reasonable cause for this error, and I couldn't catch it! I surrounded all my code with try/catch blocks and none of them was able to catch the error!
One more thing to mention, the project that contains the control was originally developed in VS 2005 and then converted to VS 2008 format (I don't know if this has anything to do with the error, but I mentioned it, just in case).
|
|
|
|
|
What's the code in your treeView's MouseDown/MouseClick/Click methods?
|
|
|
|
|
That's weird.. it looks like a DivideByZeroException...~!
Is the code dividing values? Maybe you could set up an if statement to say if the denominator is 0 then throw a custom exception?
Have you tryed using the step-by-step debugger to see what line is throwing the exception?
Mark.
|
|
|
|
|
I have had this error before when using mono...
The scrollbar in the treeview (I beleive), whilst trying to calculate its position and size, is causing the divide-by-zero exception.
I think I solved this by setting the scrollbars to be always visible.
But as I say, this was with mono so this may not work under your circumstances.
(You could try installing the latest verion of .net on the target machine).
Hope this helps.
Matthew Butler
|
|
|
|
|
Hi,
I want to compare Empty String but confused, which method is more performant, I have 2 solutions. would you please let me know which solution to choose ? Solution 1 or Solution 2 ?
Solution 1:
--------------
string a = TextBox1.Text;
if(a == String.Empty)
{
}
Solution 2:
---------------
string a = TextBox1.Text;
if(a == "")
{
}
|
|
|
|
|
Neither.
They perform equally, but both your solutions do a string comparison, which is unnecessary. You only need to check the length of the string:
if (a.Length == 0) {
Experience is the sum of all the mistakes you have done.
|
|
|
|
|
Thanks,
So, you mean, checking length ==0 is more performant than comparing with empty string, right ?
By the way, if I use,
if(a.Trim().Length == 0)
then, am I causing same performance cost as (a.Trim() == "") ?
|
|
|
|
|
bashiwala wrote: So, you mean, checking length ==0 is more performant than comparing with empty string, right ?
Yes. Comparing strings aren't very expensive, but it still involves things like getting the culture info to use for the comparison. Comparing the length is a simple integer comparison.
bashiwala wrote: By the way, if I use,
if(a.Trim().Length == 0)
then, am I causing same performance cost as (a.Trim() == "") ?
No, checking the length is still somewhat faster than comparing two strings.
Experience is the sum of all the mistakes you have done.
|
|
|
|
|
Hi,
Thanks for your suggession. I just found some exception where comparing Empty String is necessary than comparing zero length.
For example, I am checking if any Key in a NameValueCollection is Empty or not,
I can check like this,
if(MyCollection["myKey"] == String.Empty) ...
this works fine if the key does not exist, but if i use
if(MyCollection["myKey"].Length == 0) ...
then I get Exception "Object Reference Not set to an instance of an object"....
Same result I got when I check the Emptyness of a string value property like this
public string myProperty
{
get { return "hi";
set { if(value.Length == 0) ...; } // Exception is thrown, but if I use value == String.Empty, it works..
}
|
|
|
|
|
Do you really mean that if the value is null, you want to use the value?
Otherwise, there is a method in the string class for checking if a value is null or empty:
if (string.IsNullOrEmpty(MyCollection["myKey"]) ...
set { if (string.IsNullOrEmpty(value)) ...; }
Experience is the sum of all the mistakes you have done.
|
|
|
|
|
But in that case you should check MyCollection.ContainsKey("myKey") before trying to reference the value.
Plus, won't if(MyCollection["myKey"] == String.Empty) return false ? The same as a non-empty string?
|
|
|
|
|
There isn't any performance difference. Checking if the string length is 0 is probably the better way to go, as Guffa said.
"I guess it's what separates the professionals from the drag and drop, girly wirly, namby pamby, wishy washy, can't code for crap types." - Pete O'Hanlon
|
|
|
|
|
i think
TextBox1.Text.Trim().Equals(string.Empty)
would be a better option
|
|
|
|
|
If you are using .NET 2.0, you could use System.String.IsNullOrEmpty(a) .
-----
You seem eager to impose your preference of preventing others from imposing their preferences on others. -- Red Stateler, Master of Circular Reasoning and other fallacies
If atheism is a religion, then not collecting stamps is a hobby. -- Unknown
God is the only being who, to rule, does not need to exist. -- Charles Baudelaire
|
|
|
|
|
|
how i have a gridimage for load map with episodic block in c#
i have a map blockly
i want with mouse move on map load block
please help me
|
|
|
|
|
Ok now i am creating a button to send data to a website with POST method
it works fine but the problem is when i press the button it shows me invalid referrer
Is there anyway to change webBrowser referrer?
|
|
|
|