|
What does the following do:
try{
int index = table.Count;
double[] a = new double[index];
}
catch(Exception e1){
...
}
A man said to the universe:
"Sir I exist!"
"However," replied the Universe, "The fact has not created in me A sense of obligation."
-- Stephen Crane
|
|
|
|
|
Now it throws an exception. Though it seems strange that no exception is thrown just because you have an embedded statement instead of an assignment. I will do some testing to see if this happens in general or just in my program.
Thanks to everyone for their help.
|
|
|
|
|
As I expected it does exactly as it should outside the context of my program
|
|
|
|
|
Hi,
I was wondering if I could open a MainMenu menu via code?
.NET 1.1
Thanks,
Ron
-- modified at 14:14 Monday 14th August, 2006
|
|
|
|
|
Hi,
I have a process called from a main application, which invokes another 3rd party excutable program having its own UI. The main application has to wait untill the process finishs. My code is:
<br />
process1.StartInfo.FileName = exeFile;<br />
process1.StartInfo.Arguments = argFile;<br />
process1.Start();<br />
process1.WaitForExit();<br />
I hope the 3rd party program will run as a model dialog, but when it's running, the background main application UI can't be seen. Any way to refresh the main application so that user can see its UI when running 3rd party program?
Thanks.
-- modified at 16:12 Thursday 17th August, 2006
|
|
|
|
|
First, place the code above into its own thread. When WaitForExit returns, use Control.Invoke to send a message back to the UI thread. To stop the user from being able to interact with the application, set the form's Enabled property to false , then set it to true when the third-party program exits.
|
|
|
|
|
Hi Mike,
Thanks for your reply. I'm still not sure where to use Control.Invoke. Here is my code:
<br />
private void mainFrameButton_Click(object sender, EventArgs e)<br />
{<br />
ThreadStart worker = new ThreadStart(WorkerThreadMethod);<br />
Thread t = new Thread(worker);<br />
t.Start();<br />
<br />
this.Invoke(worker);<br />
this.Enabled = false;<br />
}<br />
<br />
public void WorkerThreadMethod()<br />
{ <br />
this.process1.StartInfo.FileName = ExeFile;<br />
this.process1.StartInfo.Arguments = ArgFile;<br />
this.process1.Start();<br />
this.process1.WaitForExit();<br />
}<br />
<br />
private void process1_Exited(object sender, EventArgs e)<br />
{<br />
this.Enabled = true;<br />
}<br />
It didn't work, and the worse thing is the third-party program poped up twice, and even it's closed, the main application UI was still disabled.
Some help please? Thanks.
|
|
|
|
|
i use list view that have control in this page
http://www.codeproject.com/cs/miscctrl/ListViewEmbeddedControls.asp
* if i have database with 3 recode ex:
------
field 1
------
5
7
8
-----
i want to add 3 row in the listView with first colum must be button(ClickMe)
the problem new
-----------------
1 - how i make my app when i click in the fisrt (ClickMe) button -> open new Form with 5 as parameter - > new Form(5);
and second button new Form(7);
|
|
|
|
|
private void button1_Click(object sender, EventArgs e)
{
enum MyTemp
{
cold = 0,
fp = 32
}
day1Miles.Text = textBox1.Text;
}
I get an error on 2 ( error says: } expected )
What am I missing in the concepts here? Why can't I define an enumerated constant at top of the button click? I can replace the enum statement with something like int cold = 0; and it works fine, so why can't I put an enum statement here?
For example this compiles without error:
private void button1_Click(object sender, EventArgs e)
{
int cold = 0;
day1Miles.Text = textBox1.Text;
}
-- modified at 12:49 Monday 14th August, 2006
|
|
|
|
|
Try defining the enum outside of your function.
|
|
|
|
|
Defining the enum outside the function is exactly what is needed, but I just don't understand why I would need to define the enum outside of the function.
|
|
|
|
|
Because it is pointless to define the enum in that scope. It wouuld only be valid for the scope of the function, and useless outside of it (you could not pass in a parameter of the enum type, nor return a an object of the eunum's type.
|
|
|
|
|
Thank-you for trying to help, but I am still confused....
Maybe here are some better examples of my dilema in undertanding where I can define an enum? I know I can make the example work by moving where the enum is defined, but I still do not understand why it needs to be moved. Why can't the enum constant be used just like a symbolic constant as my examples below demonstrate?
This does NOT work..... I would think it would, and still cannot understand why not.
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
enum temps
{
cold = 0,
fp = 32
}
System.Console.WriteLine("freezing is {0}", (int)temps.fp);
}
}
}
But the following does compile...
namespace ConsoleApplication2
{
class Program
{
enum temps
{
cold = 0,
fp = 32
}
static void Main(string[] args)
{
System.Console.WriteLine("freezing is {0}", (int)temps.fp);
}
}
}
And this works, if ditch the idea of using an enum, and use named constants
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
int cold = 0;
int fp = 32;
System.Console.WriteLine("freezing is {0}", cold);
}
}
}
|
|
|
|
|
Because the C# Language Specification says so. You can't do it because Enum's are an implementation of an abstract class (System.Enum), among other things. Since your really creating a concrete class by inheriting from System.Enum, you're bound by the rules of creating a new class. Classes can only be define at the Namespace and Class levels. You cannot define a class inside a method, so you can't define an Enum either.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
:-DAh makes sense now! Thank-you so much Dave and others too.
Just as a final blessing/followup. I thought I would try to show how classes cannot be defined within a method.
The example below does not compile - because you cannot define a class within a method ( you get the compile error: "} expected" on the line after the Main method) . And so the same problem would occur with the Enum - because you defining a class.
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
class temps
{
public int cold;
public int fp;
public temps()
{
cold = 0;
fp = 32;
}
}
temps xTemps = new temps();
System.Console.WriteLine("freezing is {0}", xTemps.fp);
}
}
}
If you move the definition of the class where it can legally be defined (in namespace or within another class - in this case I moved it to the namespace)... then all works well.
namespace ConsoleApplication2
{
class temps
{
public int cold;
public int fp;
public temps()
{
cold = 0;
fp = 32;
}
}
class Program
{
static void Main(string[] args)
{
temps xTemps = new temps();
System.Console.WriteLine("freezing is {0}", xTemps.fp);
}
}
}
|
|
|
|
|
How can u get sytem properties like used memory, avilable free memmory total memory, processer spec etc using C#.net
|
|
|
|
|
See the System.Management classes.
|
|
|
|
|
How can i create OCX files in C#.Net... I want to use a custom control and make an OCX file from it(instead of dll).. can i?
|
|
|
|
|
No. You can, however, add the necessary registration code to your control, and then register if as a COM control and use it like an OCX..(it will need a strong name and must be installed to GAC)
|
|
|
|
|
can u tell me how to create it using C#.net?
please provide some help if u have.
|
|
|
|
|
Any .Net DLL can be used as a COM object. There are a number of articles like this one[^] on Code project.
|
|
|
|
|
i was asking can we create .ocx file for usercontrol as we does in vb 6.0?
|
|
|
|
|
You can create a user control as a dll and use it in non-C# code. see the article I linked (it discusses using the result in VB6), and search for COM interop. OCX is just a file extension It's the registry entries that matter.
|
|
|
|
|
Right-click on your dll project in the Solution Explorer window within Visual Studio. Go to the "Build" tab. There is a checkbox on that page for "Register for COM Interop". Check that, and your .dll will automatically be registered for COM interop, meaning you could use it from COM.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: And in this corner, the Party of Allah
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|