|
Hi.
If I have an object "x", in MFC I can create an array of objects "x" with CObList or CPtrList. In C# how could I do that?, what collection should I use?.
ArrayList??.
My object should be derived from some interface like ICollection or IDictionary?.
My object, (named CParameter), for now, have only two data members: ID and Description, and I have another class, (named CSistem), that have a list of objects CParameter.
Thank you.
|
|
|
|
|
You can create an array just like you can in C/C++:
x[] xes = new x[100]; An array (derives from Array at runtime) implements IList , which implements ICollection , which implements IEnumerable ). You could also use an ArrayList which implements the same interfaces. If you want to have your own typed collection, you could extend CollectionBase which implements all those interfaces or just make one from scratch.
Also, don't prefix your classes with "C". This old notation should not (i.e., that doesn't mean "must not") be used in .NET development. If you look at the FCL (Framework Class Library), you see that there is no Hungarian notation. This is to keep everything consistent, which is important in many development environments (especially RAD environments).
See Naming Guidelines[^] in the .NET Framework SDK for more information.
To serialize arrays, you have two options. One is runtime serialization, and is the most powerful. This uses classes and other elements from the System.Runtime.Serialization namespace and child namespaces. Both a BinaryFormatter and a SoapFormatter are provided in the FCL.
There's also XML serialization, which uses classes and other elements from the System.Xml.Serialization namespace. This is less powerful and offers less control (if you stick to what the documentation says and don't implement the IXmlSerializable interface).
For a discussion of both - and examples using each - see Serializing Objects[^] in the .NET Framework SDK.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
|
To add to Heaths comments....if you are serializing the objects for the purposes of remoting, then all you need to do is define the ArrayList and add the attribute [Serializable].
The BinaryFormatter will handle the serialization and deserialization of your request and you do not need to implement your own ISerializable interface code.
___________________
Forgoing antagonism and separation, one enters into the harmonious oneness of all things. Lao Tzu
|
|
|
|
|
I'm using ClientRectangle to clip my mouse pointer, and while it works, the rectangle is slightly offset from the actualy screen representation by the ammount of the docking.
Where the top left corner should begin at 4,4 due to the 4 pixel docking i am using on the parent control. This element is ignored and it is actualy clipped at 0,0.
Is this a bug?
Cata
|
|
|
|
|
Why should it be a bug? It's doing what it should. The client area is correct. You just need to account for the DockPadding on your control which derives from ScrollableControl (Panel , UserControl , et. al.).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
We have a fairly large project which is a WinForm project.
After working on this project after awhile we began to hit a nasty situation where Intellisense lost it's intelligence, code lost its' color coding, and the Intellisense popup boxes did not display the objects namespace. At its worse, Intellisense, automatic formatting, and all color-coding completely failed. It left us with having to code blindly and hoping the code would compile correctly.
The bigger bugger of it all is that it seemed to happen eratically after working in the IDE for hours-on-end doing continuous change/build/debug cycles with no regular, re-creatable scenarios. We usually had to reboot to try and fix it.
Last week we finally nailed the bugger, reproed it on an un-managed machine and on an MS-built machine which led to the discovery of the cause. Talk about oblique:
If you are building a WinForm application
AND you are adding third party controls
AND the third party controls update the license.licx file
There is a known bug that VS will randomly append an additional
blank line to the end of the file. When this happens, it will
lead to Intellisense going brain dead!!! This will not be fixed
until Widbey.
Workaround: open your license file and delete the extra line.
___________________
Forgoing antagonism and separation, one enters into the harmonious oneness of all things. Lao Tzu
|
|
|
|
|
Interesting. I've had that problem many times in the past, too. Fortunately, we don't often prompt changes to third-party controls (they're pretty much set in place now), but I usually just restarted the IDE and called it good. It is interesting to know "why" (well, the cause anyway) it happened.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
It was a bugger to locate. We pretty much determined that if you add third party controls and this bug occurs, it could be quite a while before you encounter the problem. But all you need to do is add a new form to the existing project (even if it only uses built-in controls) and you are screwed and tattooed.
___________________
Forgoing antagonism and separation, one enters into the harmonious oneness of all things. Lao Tzu
|
|
|
|
|
You should have searched Google Groups because we had the exact same problem this summer and we spent quite some time to figure it out (nobody else figured it out before us according to the newsgroups)...
We decided to post the solution there "for the record"... Next time, spare yourself some sweat and http://groups.google.com
|
|
|
|
|
Yes, well, we were working with onsite Microsoft people. I had mission critical apps to work on and left all of the problem resolution to them. And while I use Google extensively for all types of searches, I usually do not do any searching of Google Groups.
___________________
Forgoing antagonism and separation, one enters into the harmonious oneness of all things. Lao Tzu
|
|
|
|
|
Google Groups is your friend! I search it more often than the web when I have problems!
|
|
|
|
|
Hi,
I’m new to C# and the .NET world. Can anyone tell me how to create a master project populated with sub projects? Ideally I’d like to have my master project depend upon a couple sub projects (like a common library, user info, and database info). How can I create this structure in .NET? Once this structure is created, how do I add project dependencies?
If anyone can show me an example of this that would be great.
Thanks
|
|
|
|
|
If we're talking VS.NET, you should create a Solution to hold all these Projects. If you don't have a Solution open when you create a new project, VS.NET will create one for you.
When you select File > New > Project, the New Project dialog has a pair of radio buttons Add to Solution and Close Solution. Select Add to Solution to keep this project as part of the whole solution. If you have a project you want to add to an existing solution, choose File > Add Project > Existing Project.
To set up dependencies, use the Projects tab of the Add Reference dialog, rather than the .NET tab.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
To add to what Mike said, the reason you use Project references is because it automatically sets up build dependencies and uses the latest version of the dependent assemblies.
Also, in larger, multi-project solutions, DO NOT use automatic versioning (i.e., set AssemblyVersionAttribute so that it doesn't use an asterisk (*)). You can quickly loose control with versions being different, especially when multiple developers are working on the solution.
In .NET, version numbers matter. If you binding against assembly A, version 1.0.0.0, then when assembly B (has a dependency on A) loads, assembly A, version 1.0.0.0 better be there. You can use the .config file and the <assemblyBinding> section to redirect these versions or use a publisher policy (a specially named assembly that goes into the GAC), which is primarily for upgrading your application (so long as backward compatibility is maintained). You certainly don't want to have to worry about this when developing.
If you want to use automatic versioning, expect problems. You can get around them, however. Lets say that each developer has an application test directory (or even a shared one). Using the assembly A as a dependency of assembly B example (lets say B is a .exe), you could use a .config in the same directory as B.exe like this:
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="A" publicKeyToken="0123456789abcdef"
culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535"
newVersion="1.0.1556.500"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration> This will redirect the assembly binding from whatever version it is to version 1.0.1556.500, so make sure you update those config files when you drop a new version of assembly A in the app directory.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I want add KeyUp event to columnStyle
How can I do that pls ?
thanx ..
|
|
|
|
|
columnStyle? Are you talking about the DataGridColumnStyle?
The DGColumnStyle class does not handle keyboard events since it never actually gets the input focus. These are handled by the DataGrid itself. What were you looking to do with KeyUp?
RageInTheMachine9532
|
|
|
|
|
thanx
yes I m talking about DataGridColumnStyle
this code is usefull to add KeyDown event
DataGridTextBoxColumn _datagridtextBox = (DataGridTextBoxColumn) CorpEc.TableStyles[0].GridColumnStyles[0];
_datagridtextBox.TextBox.KeyDown += new System.Windows.Forms.KeyEventHandler(ID_KeyDown);
but I don't know why it doesn't work for kewUp
thanx
|
|
|
|
|
Hey
I have made an client that takes contact with the servern and verifie the user name and password, after this its loging in to the game.
I want to have an animation during contacting server on the front login form, tu it will not load in the gif animation?
I got one button ("LOGIN") this button is makeing a new connection
connection = new Connection(this,txtLoggInName.Text,txtLoggInPass.Text,txtLoggInIp.Text,txtLoggInPort.Text,b.Text);
in the connection contructer it uses this code
public Connection(Client newClient,string name,string pass,string ip,string port,string query)
{
try
{
client = newClient;
if(name==string.Empty)throw new System.FormatException("Username not supplied");
if(pass==string.Empty)throw new System.FormatException("Password not supplied");
name = username(name);
string strHost = string.Empty;
IPHostEntry IPHost = Dns.GetHostByName(strHost);
IPAddress[] IPAdr = IPHost.AddressList;
socket = new TcpClient(ip,Int32.Parse(port));
user = new Transfer.User(name,IPAdr[0].ToString());
password = new Transfer.Password(pass);
switch(query.ToLower())
{
case "login":
request = new Transfer.Database(Transfer.Database.Request.LOGIN);
break;
case "new player":
request = new Transfer.Database(Transfer.Database.Request.CREATE);
break;
}
running = true;
}
catch...........................
I have tried to load the gif picture, first of al in the login button that makes a new connection later on.
But it will not load it, the same is if i load in text to a label it will not load the text, i must just .refresh(); on the control then it draws the picture and set the text in the label. But it will not animate the Gif animation, it only shows the first pictur.
I have tried to start a high priority thread that shows picture after picture in a loop with .refresh() after every picture but this will not paint a singel frame even. this thread i starts in the begining of the login button and then starts before creating the new connection.
I have also tired to load in the gif animation before i hit the login button, and then the animation is playd as i shold, but as soon as i hit the login the animation stops.
Is there any way to fix this problem? it simes like the connection takes al the programs power.
//Snowman
|
|
|
|
|
It seems you're trying to set the image (or the text in a Label ) in a separate thread. You can't do this. You must set any properties that would change the UI in the thread in which the particular UI element was created. See Control.InvokeRequired and Control.Invoke for how to do this. You basically create a delegate to set the text or image or whatever and have the control invoke that delegate in its UI thread.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Yes but if we dont use threads at al, and just use the buttons funktion.
If we press the button we first of al load the gif animation in to the label och picturebox, then we goes on to creat the new connection.
And if i do this the Gif animation will not run at all, it will not even be loaded though it is set first in the button funktion and the connection creation is not until later in the button funktion.
If i whant it to load i have to use contrl.refresh(); and then it loads it, but jus the first frame int the gif.
//Snowman
|
|
|
|
|
Create your connection asynchronously. I'm not sure if the PictureBox animates a GIF in the same UI thread, but if it does it will most likely be lower in priority than the main execution of your code.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi,
I am having trouble using OR in an If loop. I have
if (cboCeaseType.SelectedValue.ToString () == "2") or (cboCeaseType.SelectedValue.ToString () == "5" ){
do something
} else {
do something else
}
It doesn't like this. How do I have an OR in an If loop? What should the above be?
Cheers
Ian
|
|
|
|
|
You need to enclose the whole in brackets and the OR operator in C# is ||
(If you're curious the AND operator is &&)
Your code should look like this:
if ((cboCeaseType.SelectedValue.ToString () == "2") ||(cboCeaseType.SelectedValue.ToString () == "5" ))
I've underlined the changes.
Does this help?
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
"On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question."
--Charles Babbage (1791-1871)
|
|
|
|
|
Brillint, thanks for your quick responce. Saved me hours!
Ian
|
|
|
|
|