|
I have Class A with Properties Foo and Bar and
Class B which has an indexer to an Array of Class A objects.
I have a button for each element in B's array of A's.
I want to refer to these A objects through the Tag property of each button:
<br />
private B b = new B(2);<br />
<br />
button1.Tag = b[0];<br />
button2.Tag = b[1];<br />
I think my problem lies in the fact that many times the elements in the array will be null, which leaves the tags as null. I would like the tag, however, to refer to the space in the array in the Class B object, so I can do something like :
<br />
(A)button1.Tag = new A(FOO, BAR);<br />
thereby creating a new Class A object within b's array. Along with this I would like to be able to set the properties like:
<br />
((A)button2.Tag).Foo = NEWFOO;<br />
I come from C++ so I always think in pointers. Do I need pointers to do this, or just a different approach?
Tym!
|
|
|
|
|
1) When my app is running a large process it freezes up the app so that you can't move it or minimize it, etc. until the process is done. How do you avoid this. I tried threads and that didn't seem to do it, is there a function to the give control back to the app like repaint or something
2) I have a paragraph of text that I need to escape chr(10) and chr(13) characters from. How would you do this using the string.replace function?
Thanks in advance, sorry for the lame questions, still learning.
-Brent
|
|
|
|
|
Greets,
It is annoying when your UI isn't repainting when performing lengthy operations. However, Application.DoEvents() may do the trick for sending the appropriate messages required to repaint.
In C#, "\r\n" is the same as the chr(10) and chr(13) pair. That is what they are if you need to find them. "\r" is chr(10) (carriage return) and "\n" is newline. In the old days, a person that didn't send a newline really made things difficult to read.
BTW, the .NET library has a platform specific way of using a carriage return / newline pair, that's using the System.Environment.Newline property.
Regards,
Joe
|
|
|
|
|
bscott3125 wrote:
1) When my app is running a large process it freezes up the app so that you can't move it or minimize it, etc. until the process is done. How do you avoid this. I tried threads and that didn't seem to do it, is there a function to the give control back to the app like repaint or something
Your program is currently single threaded. When you are preforming lenghty operations your application will not perform UI operations. To prevent this, you can run lengthy operations on a separate thread.
Jared
jparsons@jparsons.org
www.prism.gatech.edu/~gte477n
|
|
|
|
|
Jared is proberly right about your app being single threaded. If you are absolutely shure you have tried multiple threading and the problem is still there, you encountered another problem.
In this case it's very likely your 'large process' is eating up all the system cpu resource. This does cause other applications to hang too and you will probably only have acces to the windows task manager. At least untill you process has finished.
To avoid this kind of problem, you will probably have to lower the process priority of your 'large process' its threat. I don't exactly know how to do this in C#.NET.
I hope this helps you a little further, but be shure to check first whether or not your app is really multi threathed.
|
|
|
|
|
Hello,
1. when adding an ActiveX on a .NET WinForm one or more dlls will be created and added to project. can somebody please explain what are these dlls and what do they do?
2. If there is some version of an ActiveX on a system and my app uses another version (newer or older) of the same ActiveX, what happens if I install and register my version on that system for my app?
will some sort of conflict occur??
thank you
|
|
|
|
|
Hi,
From what I have seen, the DLLs created are the generated interop assemblies used to access the COM object your project uuses. It looks like .NET adds a (arguably) nice wrapper object over COM in order to marshall the calls between the managed code and the component in use.
Not all questions answered, sorry.
Regards,
Joe
|
|
|
|
|
1) These are called interop assemblies. Interop assemblies are the bridge between the .NET world and the unmanaged world. As you can figure out, interop assemblies forward back and forth COM method calls.
Dropping an ActiveX control onto a form is like using the aximp.exe tool from the command line. It imports the type library and then creates one or more dll files, usually 2 with ActiveX components (and only one for a simple "non-visual" COM component).
2) Since the interop assemblies only forward method calls, including the component creation steps, versioning is not worse nor better. The component is eventually instantiated based on its clsid, that's why your .NET code will always try to create that component, not a more recent one.
RSS feed
|
|
|
|
|
Regards,
How can I set an icon for my UserControl dll so that when adding it into the toolbox it represents its custom icon instead of that default icon?
Appreciates,
- nSun
- -- --- ----- --- -- -
"Art happens when you least expect it"
|
|
|
|
|
Add the following attribute above the your class declaration:
[ToolboxBitmap(typeof(YourNamespace.YourClassName), "YourImage.bmp")]
-Nick Parker
DeveloperNotes.com
|
|
|
|
|
Thank you Nick it works but:
Colors are damaged and ugly in the it's icon while in toolbox, can you tell me the correct format/color number that the bitmap should use?
|
|
|
|
|
Two things, make sure the bitmap or icon is 16x16 and the color green is used as the transparency color (i.e. RGB(0,255,0)). HTH
-Nick Parker
DeveloperNotes.com
|
|
|
|
|
How can I Modify registry keys with C#?
|
|
|
|
|
Look at the Microsoft.Win32.Registry and Microsoft.Win32.RegistryKey classes.
When I can talk about 64 bit processors and attract girls with my computer not my car, I'll come out of the closet. Until that time...I'm like "What's the ENTER key?"
-Hockey on being a geek
|
|
|
|
|
<br />
operator float() { return m_fNum; }<br />
I am working on a port from C++ to C# of an AI method. But I found this method and don't know how to port this one to C#. Anyone does?
Greetings....
|
|
|
|
|
Hi Willem,
It looks like an overloaded cast operator. You'd probably want to consider using a 'Single' data type first of all in C#, but when it comes to the code using "(float)MyClass" on your particular class, you'd probably want to replace that with a method call or property that returns the single-point floating result.
Regards,
Joe
|
|
|
|
|
MultiThread wrote:
but when it comes to the code using "(float)MyClass" on your particular class, you'd probably want to replace that with a method call or property that returns the single-point floating result.
Why wouldn't he just keep it as an overloaded cast operator?
When I can talk about 64 bit processors and attract girls with my computer not my car, I'll come out of the closet. Until that time...I'm like "What's the ENTER key?"
-Hockey on being a geek
|
|
|
|
|
Hi David,
He probably could, but that would be due to my ignorance. I did some research and found that the cast operator in C# can't be overloaded, but that C# did allow the use of "explicit" and "implicit" as keywords to allow for that sort of behavior.
Regards,
Joe
|
|
|
|
|
I found the solution
<br />
public static explicit operator float(Fuzzy f1)<br />
{<br />
return f1.fuzzNum;<br />
}<br />
You can then do this:
<br />
float x;<br />
Fuzzy y = new Fuzzy(56.34);<br />
<br />
x = (float)y;
Greetings....
|
|
|
|
|
Cool...glad we could help. Although, you may want to use operator overloading sparingly. Only use it when it makes sense to have an object cast to another object...etc.
When I can talk about 64 bit processors and attract girls with my computer not my car, I'll come out of the closet. Until that time...I'm like "What's the ENTER key?"
-Hockey on being a geek
|
|
|
|
|
I am trying to create a Windows Installer package, can anyone lend some advice on best route if my software needs to connect and deploy some stored procedures?
Thanks in advance
Terance Emory
|
|
|
|
|
Hi Terance,
If your code needs to deploy items which don't already have .NET framework code to do so (i.e. message queues, etc.), you can add an installation component to your application which has callbacks that can act in the context of installing and uninstalling your application.
If you use "Add new item..." to your project, you should find an installer class. This derived class has overrides you can use during the installation process to do work during the install, rollback, commit and uninstall portions of installation.
MSDN online provides a walkthrough on how to create a database, the same example can be adapted to add your stored procedure to the database during installation.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vsintro7/html/vxwlkWalkthroughUsingCustomActionToCreateDatabaseDuringInstallation.asp
Regards,
Joe
|
|
|
|
|
Thanks Joe,
This looks like exactly what I needed many thanks
|
|
|
|
|
Hi guys,
I would like to hear you opinion about writing the code for database access in general. I have like 15 books that discuss database access, have read numerous articles, but I am still not sure of the best practices in this area. There are many solution to this and they all work, different authors offer different approaches, but it is just too time consuming.
I make client applications to access data from SQL server, and as I said I am writing too much code for that. I mean it works, but I should be able to code in shorter period of time. Some common approaches, and my opinion:
1. Use of MS application blocks: this is not such a big help, if I call the stored procedures in one line of code, or 5, it is all same to me, cause I auto-generate it anyways.
2. Use of different data access layers: they all are too complicated, and it only adds to the complicity of my code. I do not need such approach so that I can be flexible to easily switch my code from accessing SQL server to accessing Oracle, or anything like that, cause I will never be doing that.
3. Use of binding context: this is the biggest crap I have seen in .Net. It is not flexible at all, have to basically make binding context for each different control on the form, have no control over the process, very hard to keep grid and controls data in sync... Will never use it.
I usually make a class for each window, cause I always represent data from multiple tables, there are usually grid control, some combo boxes and number of other controls, then I handle moving through data sets and take care of inserting, updating or deleting data in data set by using appropriate methods in that class. Of course, I do it in a locally accessible data set, then I update a database, keeping the local data set view updated. This is all fine, but it takes TOO MUCH TIME to code like this for every window I need.
I just wanted to hear you opinion about this, I mean there has to be a quicker way to this.
Thanks in advance.
|
|
|
|
|
I used a 3 layer method. I have the database, a special class I designed to do the Read,Insert,Update,Remove things for me. And the user part.
This works fine for me. Ok, I have 40.000 lines of code at the moment. But the application is fast, has a lot of features and zero errors. (At least the users say so )
But you can also use plain and simple: the data adapters and datasets from the .NET Framework. Less code to write, but it uses up more memory then probably needed.
Greetings....
|
|
|
|