moving auto generated event handlers? Steve from adzac wrote:
If this is not possible, what's the best practice for overly large form code files Moving the non auto-generated stuff is only a partial answer. The use of TabPages can make a form's code file huge even with only the event handlers.
Steve
Well, other than...
private void someControl_Click( object sender, EventArgs e)
{
handleSomeControl_Click( object sender, EventArgs e); // which is in some other file
}
Steve Tag: Visual C# General How can I import a c++ static library file to C# project Visual C#
How to make a program unstoppable No offense but it seems like a key logger or something Tag: Visual C# General How can I import a c++ static library file to C# project Visual C#
How to separate logic from GUI? The easiest and most effective way is to move all business logic classes out into their own assembly. If at that point, one can run the business logic classes from a console application or Unit tests, such as Nunit, it shows that the business logic is not tied to the GUI. Tag: Visual C# General How can I import a c++ static library file to C# project Visual C#
Case of construct What language are you pulling that out of That looks like lisp.... Tag: Visual C# General How can I import a c++ static library file to C# project Visual C#
What [STATHREAD] do? Hi,
STA stands for Single Threaded Apartment, there is a good explanation of why it is needed at: http://blogs.msdn.com/jfoscoding/archive/2005/04/07/406341.aspx
Mark. Tag: Visual C# General How can I import a c++ static library file to C# project Visual C#
Delete a datasource Hmm, I'll admit, I don't do much of my data bindings through the wizards (well... none), but I'm guessing you mean that little window that shows up when you click on the "Choose Data Source" or DataSource in the properties combo box First, make sure you don't still have anything pointing to it, if something is, point it to what it belongs to or select none Next, look under the form in your form designer and find the object with the same name (something like tableNameBindingSource for example) click on it, and check on it's datasource. Record it's name (i.e. databaseNameDataSet) now you can delete those two things (just click on them and hit delete). Finally find the the item called something like TableNameTableAdapter (it should have a similar name to the BindingSource anyway, and it will be of type visualQue.DatabaseNameDataSetTableAdapters.TableNameTableAdapter) And delete that. And now you've undone the huge amount of code the designer created for you automatically. -mwalts Tag: Visual C# General How can I import a c++ static library file to C# project Visual C#
InvalidOperation Exception was unhandled I assume then that the error is occuring within your application rather than the IDE itself. If you're not sure then try running your app outside the IDE to verify.
The error sounds like your form is trying to work with a collection after the form has closed. This is common when dealing with event handlers. The call stack should give you a better idea of what is going wrong. It is accessible from the exception object.
Michael Taylor - 6/12/07
http://p3net.mvps.org Tag: Visual C# General How can I import a c++ static library file to C# project Visual C#
Why does List<T> not implement ISerializable/IDeserializationCallback?? Part of the differences are evolutionary, part are due to actual differences between the collections. I'll try to take them one at a time.
List<T> is not designed to be serialized. Period. While technologies like WCF are able to serialize almost any kind of enumerable type given certain constraints, List<T> was designed to be an optimized local utility class. In no circumstances should you serialize List<T> outside the local app domain. Part of the optimized implementation won't deal nicely with versioning, for example. In fact, if you create a serializable object and include a property of List<T>, then run code analysis, it will give you a warning to remove it.
Queue and Stack do not have normal ICollection<T> semantics. That is to say, ICollection<T> has behavioral contracts for adding and removing items, which do not apply to stacks and queues.
ICollection was created back before generics. This drew two limitations - 1, you could have read-only collections, and 2, without generics, it could only provide typeless Add methods, which are less than optimal. For those reasons, and possibly some others, ICollection left it up to the implementer to specify type-specific methods such as Add, and did not create the typeless contract. If it did, you would have two conflicting Add methods, because Add(object) and Add(MyType) could resolve to the same overload in certain situations due to the variance between MyType and Object.
ICollection could overcome some of these limitations with typed parameters, so it did more of the heavy lifting for you. Tag: Visual C# General How can I import a c++ static library file to C# project Visual C#
instance does not exist in the current context Hi,
do you have the exact error that is shown
Mark. Tag: Visual C# General How can I import a c++ static library file to C# project Visual C#
How to change Disk's volume Serial using System;
using System.Collections.Generic;
using System.Text;
using System.Management;
namespace WMIDiskSerial
{
class Program
{
static void Main( string [] args)
{
ManagementObject diskObj = new ManagementObject ( "win32_logicaldisk.deviceid=\"c:\"" );
diskObj.Get();
Console .WriteLine(diskObj[ "VolumeSerialNumber" ].ToString());
Console .ReadLine();
}
}
} Tag: Visual C# General How can I import a c++ static library file to C# project Visual C#
How can I control already open IE windows? Hi Brene The answer is "yes" and it requires API calls and SendKeys <shudder>. I've written code that does this before: I'll try to dig it up and distill it into a short sample for you. It's not elegant, but it works. -Jeff Tag: Visual C# General How can I import a c++ static library file to C# project Visual C#
Casting question Generics aren't covariant , meaning you can't cast one generic to another despite using the same templated class (generic). See http://www.fotia.co.uk/fotia/DN.01.CoVariantGenericList.aspx for an overview of Generics and covariance and the problems that would arise if you could do what you're asking to do. Tag: Visual C# General How can I import a c++ static library file to C# project Visual C#
string to hexadecimal string To convert a string to a byte-array which represents the ascii chars you can use
Code Snippet byte [] bytes = System.Text. Encoding .ASCII.GetBytes(str);
When you have the bytes, you can easily convert them to a new string. Tag: Visual C# General How can I import a c++ static library file to C# project Visual C#
config and ini??? I would not recommend you using an INI file.Today you have more comfortable formats to store data in for manipulating it later.
You can use the XML file for storing the username and password, so it is very easy to store and retrieve data from it.
You can you a simple 'MS Access' database file with a single table for storing user login details.
Check the option of using the cookies, but you must be ready for loosing the data in the cookies because user can in any time delete the cookies.
Anyway, remember to think about the encryption if data is sensitive. Tag: Visual C# General How can I import a c++ static library file to C# project Visual C#
Rotating Two Dimensional Arrays After reviewing my notes from before my post I'm come to the conclusion that the following for loop will work, however it doesn't and I'm not sure why. for (int y = 0; y < rotatedShape.Rank; y++) { for (int x = 0; x < rotatedShape.Length / rotatedShape.Rank; x++) { rotatedShape[x, y] = currentShape[y, rotatedShape.Length / rotatedShape.Rank - 1 - x]; } } My only speculation is that I am unsure how to get the width of a two dimensional array. On dimension is easy, you just use the Length of the array, but that gives the area of a multidimensional array. Tag: Visual C# General How can I import a c++ static library file to C# project Visual C#
Code to have a button "Paste" text into a Rich Text Box... Hi,
Copy and paste stuff can be done with the ClipBoard.
Here is the reference and examples: http://msdn2.microsoft.com/en-us/library/system.windows.forms.clipboard.aspx
http://www.codeproject.com/csharp/clipboard01.asp
Hope it helps. Thanks. Tag: Visual C# General How can I import a c++ static library file to C# project Visual C#
Trying to understand IComparable 'this.' referes to current instance of a class, but you can remove it if you don't like it. CompareTo method implemented as a requirement of IComparable interface can't be static so it must be called on previously created instance of the class. Tag: Visual C# General How can I import a c++ static library file to C# project Visual C#
Application settings lost upon new assembly Jef,
First, I suggest adding the System.Configuration namespace to your imports section as the top of your code file:
using System.Configuration;
The Properties.Settings class is meant to be instantiated as in:
Properties.Settings mySettings = new Properties.Settings();
This will give a user specific instance of the settings which you can update and save:
mySettings.ASetting = oSettingValue;
mySettings.Save();
Additionally, the mySettings object will now yield methods including Upgrade() in your intellisense.
Dan Tag: Visual C# General How can I import a c++ static library file to C# project Visual C#
memcpy to C# Have you tried using Array.Copy (or Array.CopyTo) Tag: Visual C# General How can I import a c++ static library file to C# project Visual C#
Cryptographic Exception - Length of the data to decrypt is invalid Most crypto algorithms require data to be of a fixed size. Based upon my reading of MSDN this particular provider requires 8 byte blocks. Therefore you should pass it a block of 8 bytes (8, 16, 24, etc). You should have been given the entire block when you encrypted the data (it pads it before it is returned during encryption). If each block isn't 8 bytes then the function will fail.
Michael Taylor - 10/26/07
http://p3net.mvps.org Tag: Visual C# General How can I import a c++ static library file to C# project Visual C#
How to make VS 2005 IDE understand dotnet 3.0 framework? Hi,
What is your windows and VS 2005 version
The steps should be first install the sp1 for Visual Studio 2005 and then .NET Framework 3.0 after that Visual Studio 2005 extensions for .NET Framework 3.0.
For your information: visual studio 2008 beta2 (with .NET framework 3.5) has released: http://msdn2.microsoft.com/zh-cn/vstudio/aa700831.aspx
Thanks Tag: Visual C# General How can I import a c++ static library file to C# project Visual C#
Using P/Invoke to create instance of class I don't think you can use P/Invoke to do what you describe. The DllImportAttribute is decorated with the value AttributeUsageAttribute (AttributeTargets.Method) meaning it can only be applied to a method, not to a class or any of the orther possible AttributeTargets.
You could implement a CFactoryMethod in your Win32 DLL that returned a pointer to class C instance as a result and could invoke that factory method using P/Invoke. That would allow you to instantiate a C object as an IntPtr but by itself that IntPtr isn't much use.
You could also have your Win32 DLL implement an MWrapper method that took all the same parameters as the method M's parameters plus an extra pointer to C parameter. You could call MWrapper using P/Invoke and could pass the IntPtr returned by the factory method as the "pointer to C" parameter.
Of course all that only works if you can modify your Win32 DLL.
Update: The first paragraph above is just wrong.
The CallingConvention enumeration contains a value "ThisCall" specifically to allow calls to exported Class methods. You are still limited to only calling methods on the class, you can't (for example) directly access public member fields. The whole exercise looks somewhat non-trivial. I haven't tried this myself yet, but this code-project article seems to offer some guidance:
http://www.codeproject.com/useritems/usingcppdll.asp Tag: Visual C# General How can I import a c++ static library file to C# project Visual C#
"new"? Arguments when creating an object? (Help the beginner?) "new" is how you create a new object (forget about the heap or stack, you don't need to think about that for the moment). It goes: SomeType myVariable = new SomeType(..parameters...) Where SomeType is the name of a type (such as FileStream or StreamReader) and ..parameters.. is a list of zero or more things used to initialise the new object. The thing that is used to create a new object is called a "Constructor" (for obvious reasons . A type can have many Constructors, each of which takes different numbers and types of parameters. In the case of FileStream and StreamReader: They both have several different constructors. One of the FileStream constructors happens to have exactly the same types of parameters as one of the StreamReader constructors, which you have noticed. It is not really a coincidence, since both those types allow you to read from a file. There is overlap in the things that those types can do, but there are some differences too. Tag: Visual C# General How can I import a c++ static library file to C# project Visual C#
Protection of C# source code you can use the Dotfuscator Community Edition tool that ships with the Microsoft Visual Studio. This tool obfuscate .NET Assembly which can not be disassembled. Tag: Visual C# General How can I import a c++ static library file to C# project Visual C#
Removing items in a list while iterating through it In this code, I get a SystemInvalidOperation execution and I know why.
List<int> list = new List<int>(); for (int i = 1; i < 10; i++) { list.Add(i); } foreach (int i in list) { list.Remove(i); } I replaced the foreach with for:
List<int> list = new List<int>(); for (int i = 1; i < 10; i++) { list.Add(i); } for (int i = 0; i < list.Count; i++) { int remove = list ; list.Remove(remove); } After the loop exits, I still have 4 items in the list. How do I delete a few items in the list while iterating through it http://generally.wordpress.com/2007/10/24/removing-items-in-a-list-while-iterating-through-it/ Tag: Visual C# General How can I import a c++ static library file to C# project Visual C#
Microsoft.Tools.WinRes.ResourcesLoader namespace does't work with me That's the namespace internal to WinRes.exe. Most of the classes in there (including ResourceLoader) are internal, so you can't use them in your application. Tag: Visual C# General How can I import a c++ static library file to C# project Visual C#
How can I find whether the current thread is exited or not? Maybe this would help :- http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=564684&SiteID=1 Tag: Visual C# General How can I import a c++ static library file to C# project Visual C#
Wierd error : Attempted to read or write protected memory. This is often an indication that other memory is corrupt Mike Martin wrote: Ok I have a project that runs fine from the IDE, the problem is if I install the app or run it from the bin\release folder then I get this error on one of my method calls. I have tried this on a test machine and on my development machine and the results are the same. I have spent hours trying to figure this one out....... The crazy thing is, the method shows up in the stack trace but there is not code at all executed in that method.
This shouldn't happen in managed code. It's even odder that the error only happens when not debugging. Can you give the code for the method that causes the problem
Michael Tag: Visual C# General How can I import a c++ static library file to C# project Visual C#
Start a new process using a windows service Because you're trying to run your application from a service, you're running with a non-interactive desktop heap. This heap is much smaller than than the interactive heap and probably isn't large enough to run the service and your application. See KB824422 (the example used is SQL Server; but it would apply to any service) on how to correct this. Tag: Visual C# General How can I import a c++ static library file to C# project Visual C#
Why I cannot see some of the methods in other classes? MaximumResponseHeadersLength is documented as not being supported by the .NET Compact Framework. If you're creating code for a device that property isn't available. Tag: Visual C# General How can I import a c++ static library file to C# project Visual C#