|
Yay. I just made a file go from serialization to byte[] form. Thank you so much, bro.
|
|
|
|
|
Heyas all,
I was hoping someone could give me a hand with a problem.
I have an external file that holds location information on a user defined amount of places (the user can add or remove locations that can be chosen from.) I was making the file format like so:
-name;address;cross_streets;last_visited
What I need to do is to randomly choose a location on an event. The information would then be shown in a read only textEdit but formatted differently with each attribute (name, address, etc.) being on it's own line.
So I was thinking that on program start to load each line of the file into some sort of collection.
Could anyone give me any clues or a push on how to go about doing something like this? Is there an easier way than to load it into a collection? Am I way off in my design?
Thanks,
John
|
|
|
|
|
There are many ways you could go about this, and no way to cover all the bases in a practical reply.
If you're not tied to the existing file format, you might consider using XML. If you're not tied to using the file system, you might consider using a database, etc.
Assuming you want to stick with the current system, then you should probably use a FileStream and some flavor of StreamReader to read individual lines from the file (assuming logical records are separated by Newline characters), then you could use the String.Split(char) method to get a string array of the elements on each line, and go from there.
A couple of the benefits of using XML are flexibility and readability. You'd potentially have a little easier time changing the data you're storing, allowing for nulls or empty values or whatever.
You might also want to consider creating a structure or a class to hold the individual data elements that comprise a location (name, address etc.) - you'll probably want a class as the size of your type is likely to exceed 16 bytes (best practices limit on struct sizes since they're allocated on the stack), and you may also choose to investigate implementing your own custom collection of location objects (see CollectionBase for ideas).
Hope this is sufficient to get you started.
The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’
|
|
|
|
|
hi,
how can i design my own window with c#? i want to change the look of the window, the functionality should be the same like a regular window. does anyone know how to do this or a helpful link?
thanks for help
|
|
|
|
|
You can use a graphics path to make irregularly shaped forms. You can turn off the control boxes (minimize, maximize, close), and set your form's background to be an image or a different color, or partially transparent, and so on. Is that what you're looking for?
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: He has a funny face. And he's my son.
Judah Himango
|
|
|
|
|
You can make the formBorderStyle to None to do your own close and minimize btns and also make the form shaped by the this.Region = new Region(your graphics path);
ByMindOnlyYouCanDoIt
|
|
|
|
|
Hello all
I was under the impression that if I make a call into a static function which uses the value of a static class variable, if I recall the function later the value of the static class variable would reset back to the default coded value.
Now as the following example prooves I am obviously wrong.
I have a test application/dll that has the following code :
StaticLib.dll
using System;
namespace StaticLib
{
public class MyStaticLib
{
private static int val = 0;
public static int GetNumber()
{
return val++;
}
}
}
Console Application (which references StaticLib.dll)
using System;
using StaticLib;
using System.Threading;
namespace StaticTest
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
while(true)
{
Console.WriteLine(MyStaticLib.GetNumber());
Thread.Sleep(1000);
}
}
}
}
When I ran this for the first time I expected to get the following output
0
0
0
0
0
0
But I actually get
1
2
3
4
5
6
7
Could anybody explain why this is?
post.mode = postmodes.signature;
SELECT everything FROM everywhere WHERE something = something_else;
> 1 Row Returned
> 42
|
|
|
|
|
MrEyes wrote:
I recall the function later the value of the static class variable would reset back to the default coded value.
That is not correct. The value will not reset unless you have code to explicitly reset it.
MrEyes wrote:
Could anybody explain why this is?
That is the correct behaviour. A static is a value that exists for all instances of the class. If some code modifies it then all instances of the class (and any static methods/properties) see the modification.
Some people think of a static that is a global value within the class.
Does this help?
My: Blog | Photos
WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and More
|
|
|
|
|
This behavious is correct. Static variable has lifetime of global variable but it has a scope of local variable. Hence the value of static variable persists across multiple calls to the function.
Unlike nonstatic members where each instance of object has its own copy of variables, the static variable is shared across all instances i.e. only one copy od static variable is available across all instances of objects.
Ravindra Sadaphule
MCSD.NET
|
|
|
|
|
Hi,
I want to locate the listViewItem when the mouse is dragged over the
listViewItems in a listView. I try to locate which listViewItem is dragged over by the mouse by using the listView.getItemAt(e.X,e.Y) in the dragOver handler, but it can't return the listViewItem located by the mouse(it can return the right x, y of the mouse location)?
Why ?
Many thanks
|
|
|
|
|
Because the GetItemAt method looks at a coordinate local to the control, not the screen (i.e. Point(0, 0) to the control is the upper left corner of the list view, whereas Point(0, 0) to the cursor is the upper left corner of the screen).
Here's some example code that should work for you:
Point localCoordinate = listView.PointToClient(MousePosition);
listView.GetItemAt(localCoordinate.X, localCoordinate.Y);
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: He has a funny face. And he's my son.
Judah Himango
|
|
|
|
|
I have a routine which reads a header record from a file, that header record tells how many subsequent records to read, each record having another header which says how long that record is in bytes.
Is it more efficient to allocate an array of (say) 10,000 bytes at the beginning of the loop which process the records then use:
BinaryReader.Read(buffer,0,reclength);
or is it better to just allocate the bytes required on the fly:
byte[] buffer = BinaryReader.ReadBytes(recLength);
For this example the recLength will never exceed 10,000 but could be anything between 1 and 10,000 - the loop can require between 40 and 200 iterations.
|
|
|
|
|
Especially since this is C#, I would code whichever method is easiest for you and then only worry about it if there is an actual performance problem.
When you get to that point, creating one large buffer will typically go on the large object heap and requires more memory at one time, which might be faster on a single user system with few memory constraints.
Your second approach will use more memory during processing, however it will give the garbage collector a chance to collect already processed buffers.
A third approach is to use the stream directly, one pre-allocated buffer and read the data from the stream into the buffer without any allocations in your loop. This is more difficult especially if the records are not fixed size, but will typically perform the best of all the options since there is no allocation in the loop.
However, your loop needs to be driving an efficient processing operation for optimizing reading to make sense. If you are just creating an array of record objects in your loop for example, these changes won't make much of a difference.
I can imagine the sinking feeling one would have after ordering my book,
only to find a laughably ridiculous theory with demented logic once the book arrives - Mark McCutcheon
|
|
|
|
|
|
Hi,
For developing interop dll in developer's pc, GacUtil and RegAsm is used in dos command prompt environment. But for deploying the dll in customer computers, what should be done ?
Many thanks
|
|
|
|
|
Use your installer program to call gacutil and regasm on your interop files. As long as the end user has .NET runtime installed, they'll have gacutil and regasm.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: He has a funny face. And he's my son.
Judah Himango
|
|
|
|
|
Use a Windows Installer-compatible installer, such as the Visual Studio deployment project. Instruct the installer to register the assembly and to place it in the GAC.
If you use a Visual Studio deployment project, you can do this by going to the File System view, then right-click in the left-hand pane and choose Add Special Folder > Global Assembly Cache Folder. Drop your assembly into this folder. To register, select the assembly in Solution Explorer or the File System view, then in Properties, set "Register" to "vsdraCOM".
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
hi frds
i m facing problem tht how to get mac address of my system and how can i restrict a packet to use a specific NiC for communication (programmatically)when making my own packet for checking network statistics ............
if any body can plz guide me some soltution
waitng auxiously
bye
|
|
|
|
|
look if you want to deal with device and get what ever info you want. most network devices implements SNMP protocol which allow you to query and gets device info.
SNMP is application layer protocol. so to know device mac address you must implement SNMP class whith your hand which produce an array of bytes whith spesific values that represent SNMP header and your request.then send this array in udp message to device you want to know it's MAC. and when you get response from udp socket which you send msg from. you must get MAC back from the recieved array of bytes
marcoryos
|
|
|
|
|
Keep in mind this will only return the first MAC Address. You can iterate through each adapter to find each of the MAC's
public class Ethernet
{
public static String MacAddress
{
get
{
if (macAddress == null)
{
ManagementClass mc =
new ManagementClass(
"Win32_NetworkAdapterConfiguration");
foreach (ManagementObject mo in mc.GetInstances())
{
if (((bool)mo["IPEnabled"]) == true )
{
String address =
(String)mo["MACAddress"];
if (address.Length != 0)
{
macAddress = address;
break;
}
}
}
}
return macAddress;
}
}
private static String macAddress;
}
-
Drew
|
|
|
|
|
Appdomain.AddPrivatePath("..\otheassemblies\")
I need the assembly loader to look into the otherassemblies directory that is directly above the BaseDirectory of the application, that is
c:\otherassemblies\
c:\myprogram\ <- BaseDirectory
The way I understand I need to tell the AppDomain about this privatepath using the AddPrivatePath method RELATIVE to the BaseDirectory account.
When I run the program it seems like both directories were accepted but the assembly prober doesn't even touch the \otherassemblies\ directory. That is privatepath is being ignored.
I also get the "Policy not being applied referenced."
Guillermo
|
|
|
|
|
The private path needs to be under the base directory.
|
|
|
|
|
Hi!
Im using a custom made doublebuffer transparent control over a mediaplayer-control. I would like to be able to pause the movie and then draw red marker rectangles on the transparent control. I would like to be able to see these rectangles while playing the movie. Everything works fine except for the last part, the rectangles dissappear as soon as I resume the movie. This is a test onPaint method in my transparent control:
protected override void OnPaint(PaintEventArgs e)
{
if(_backBuffer==null)
{
_backBuffer=new Bitmap(this.ClientSize.Width,this.ClientSize.Height);
}
Graphics g=Graphics.FromImage(_backBuffer);
//Copy the back buffer to the screen
e.Graphics.DrawImageUnscaled(_backBuffer,0,0);
// Get the graphics object
Graphics gfx = e.Graphics;
// Create a new pen that we shall use for drawing the line
Pen myPen = new Pen(Color.Red);
// Loop until the coordinates reach 250 (the lower right corner of the form)
for(int i = 0; i < 250; i = i + 50)
{
// Draw a 50x50 pixels rectangle
gfx.DrawRectangle(myPen, i, i, 50, 50);
}
g.Dispose();
gfx.Dispose();
}
Any tips?
THanks for your help
/Rickard
|
|
|
|
|
is the focus transfered to the movie when resuming try transControl.bringToFront()
orit is refreshed ?
ByMindOnlyYouCanDoIt
|
|
|
|
|
Hi!
Thanks for your answer, bringToFront() makes no difference. refresh() does, but only temporary, it seems like i need to refresh the transControl continuously while the movie is playing, and I dont like that solution, also it makes the rectangles flicker.
/Rickard
|
|
|
|