|
Did you try the Dns.GetHostByName method?
If that doesn't help, please give some more information. What information do you have about the machine whose ip you want to retrieve? For what do you need the IP?
www.troschuetz.de
|
|
|
|
|
Hi guys
Is it possible in C# .Net to assign your own "custom" shortcuts to MenuItems? I want to have a shortcut like the following:-
- Alt + Left Arrow
- Alt + Right Arrow
- Alt + Home
The problem is that MenuItem.ShortCut property accepts only enumerated values from the ShortCut enumeration. Is it possible to convert the text to an enumeration and then assign the new value to the property?
Thanks in advance
|
|
|
|
|
I think you can in .NET2 (at least you get a window that actually lets you define the shortcut, rather than picking from a list), but in .NET1.x it seems you're stuck with the built in enum
--
Help me! I'm turning into a grapefruit!
Phoenix Paint - back from DPaint's ashes!
|
|
|
|
|
Not with the MenuItem.Shortcut property - or the MenuItem class itself, for that matter. You can use the Keys enumeration (which is a 1-1 mapping of the VK native enumeration) for the ToolStripMenuItem.ShortcutKeys property, which is part of the new WinBars implementation.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Unless the implementation that accepts the enumeration validates the value, you can cast any numeric expression to the enumeration type. The set accessor for the MenuItem.Shortcut property is one such implementation, as are most implementations that deal with enumerations in the .NET BCL.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
In C++\STL i can create pairs of values using make_pair so I could, for example, look up a value in a map/dictionary using a 2 value key:
XXX::iterator it = m_map.find(make_pair(x,y));
Is there an equivalent in C# or if not a way around it?
TIA
|
|
|
|
|
A Hashtable stores key/values pairs that are both object s, meaning that you can store anything (since every Type in .NET extends System.Object ). This means that you can store, for example, a class (best to use reference types to avoid boxing and unboxing performance penalties) with a couple of properties like so:
public class Person
{
string name, DateTime birthday;
public string Name
{
get { return name; }
set { if (value == null) throw new ArgumentNullException(); name = value; }
}
public DateTime Birthday
{
get { return birthday; }
set { birthday = value; }
}
} Then create an IComparer implementation to compare whatever property or properties you want, or have your class implement IComparable so that the default Comparer can juse use your implementation (this option is often best when defining your own types as it works without implementing and using a separate Type).
If you read the documentation for the Hashtable , however, you'll notice that if you don't pass an IComparer to the constructor the default comparer it uses will use the Equals override. So, you could also override Object.Equals (which implies you should override Object.GetHashCode ) and not pass a comparer, or implement IComparable on your class and pass Comparer.Default to the Hashtable constructor, or implement IComparer and pass your implementation to the Hashtable constructor. This will allow you to compare keys, not values, though. For that, enumerate the Hashtable.Values collection or enumerate (using the IDictionaryEnumerator ) the entire Hashtable to compare values so that you have both the key and value.
As far as whether to override Equals or implement IComparable , you could do both.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Thanks - I was looking at Hashtables when I got your reply, your explanation is certainly more approachable than the stuff I was reading
Rugby League: The Greatest Game Of All.
|
|
|
|
|
You might look into classes that implement IDictionary , such as HybridDictionary[^]. The method access will be different but you will find what you need for version 1.1 of the framework to implement it. With version 2.0 of the .NET Framework you can do something as simple as the following with generics:
public class pair<T1, T2>
{
public T1 First
{
get {return this.t1;}
set {this.t1 = value;}
}
public T2 Second
{
get { return this.t2; }
set { this.t2 = value; }
}
public pair(T1 type1, T2 type2)
{
this.t1 = type1;
this.t2 = type2;
}
private T1 t1;
private T2 t2;
}
private void button1_Click(object sender, EventArgs e)
{
pair<int, int> i = new pair<int, int>(5, 10);
MessageBox.Show(string.Format("First value:{0}, second value:{1}",
i.First.ToString(), i.Second.ToString()));
}
- Nick Parker My Blog | My Articles
|
|
|
|
|
|
|
How we can Dynamically generate a MS Word document using ASP.Net?
Jijo kuruvila
software developer
trivandrum
|
|
|
|
|
hi,
I was going to make an article about it;)
I suppose you have Word2003, ASP.NET1.1 and VS.NET2003. It may be ok with lesser verions.
try some of folowing steps:
1)read MSDN - especially this[^]
2)download & install Office PIA[^]
3)reference PIA in ur project
4)run Start->ControlPanel->AdministrativeTools->ComponentServices
5)ComponentService->Computers->MyComputer->DCOMConfig
find "Microsoft Word Document" and set permissons for user ASPNET
6) use Word's object to generate document... see MSDN
hope it helps, I got stuck on it for a while some time ago
best regards,
David 'DNH' Nohejl
Never forget: "Stay kul and happy" (I.A.)
|
|
|
|
|
As I said in my reply (BTW, John, please hit "Submit" only once and please delete duplicate posts in the future), you must be careful using Word on a multi-threaded server application ASP.NET. It is not recommended. The caller is responsible for thread-safety in many cases. Some solutions will use pessimistic concurrency to ensure thread safety (letting only one caller run at a time and queuing the rest) and that will degrade performance becanse your multi-threaded application all of a sudden acts like a single-threaded process.
Depending on your requirements, using XHTML with the right ProgID processor instruction or the Word 2003 XML Schema will allow you to use a 100% managed solution and still generate content that Word would have no problem with (and in the case of the Word 2003 XML schema - you can do everything Word can do generating a 100% compatible Word Document).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
|
How we can Dynamically generate a MS Word document using ASP.Net?????
Jijo kuruvila
software developer
trivandrum
|
|
|
|
|
If all you need to support was Word 2003, you can use the published Word 2003 XML Schema that you can download (as well as documentation) at http://www.microsoft.com/downloads/details.aspx?familyid=fe118952-3547-420a-a412-00a2662442d9&displaylang=en[^]. Generate XML through a variety of means (using the DOM with the System.Xml classes or using an XSLT using the System.Xml.Xsl classes) and - if you display the generated content in Internet Explorer and have Word 2003 installed - it should open up in Word.
If you need to support downl-level versions, I suggest you use XHTML (XML with a default namespace to mimic HTML for older browsers) with the following processor instruction at the top:
<?xml version="1.0">
<?mso-application progid="Word.Document"?> This would be supported by Word 2000 and newer.
If you want to support older clients yet and generate binary content, then you'll have to use automation (generating an RCW (runtime callable wrapper) from the Word typelib usign VS.NET->Add Reference->COM or tlbimp.exe), which isn't safe in a multi-threaded server application like ASP.NET. You'd be responsible for thread safety.
If you must use that route, be sure to create an RCW (an "interop assembly") from the oldest typelib you want to support. Since Office components (and all COM servers should be written this way, though that's not always the case) are backwards compatible, they support older interfaces. You could even generate an RCW from a new typelib, but you must be sure not to use interfaces that are new to a version you might want to support.
Because this would be on a server you would most likely control, however, you should get some control over what version is installed.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Thanx a lot....
Jijo kuruvila
software developer
trivandrum
|
|
|
|
|
Hi!
Does any one knows how to put a Form in the center of the screen? i.e. how to find its (screen) middle point?!
Thsnks!
AlexMartins
|
|
|
|
|
There's this property StartUpPostion (or something like that) that you can set to CenterScreen to achieve that effect when the form is created.
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
AlexMartins wrote:
Does any one knows how to put a Form in the center of the screen? i.e. how to find its (screen) middle point?!
As mentioned, you can set the form startup position. More info about the screens can be found using the Screen class.
BTW, don't forget that a lot of machines, like mine, have more than one monitor, with different resolutions each. Always show things on the same screen than your application is running and everything will be fine.
Yes, even I am blogging now!
|
|
|
|
|
i have simple question what are the benefits of using SqlTypes (especially regarding performance). I know there is the IsNull property but what else?
|
|
|
|
|
There is no Type called SqlTypes in the BCL. Do you mean the SqlType enumeration? You should use this when using parameterized queries and adding DataColumn s to ensure that data is represented correctly, as well as for design-time purposes and using classes like the SqlCommandBuilder . This helps determine what type of data is represented.
Imagine if all properties on every class were simply defined as object . How do you know what type of data to assign to a property in such a case?
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
I think he is referring to the various struct s defined in the System.Data.SqlTypes namespace.
Charlie
if(!curlies){ return; }
|
|
|
|
|
Perhaps, but that's why one should be a little more descriptive.
To the original poster, the documentation for the System.Data.SqlTypes (if that is, in fact, what you meant) explains it quite clearly:The System.Data.SqlTypes namespace provides classes for native data types within SQL Server. These classes provide a safer, faster alternative to other data types. Using the classes in this namespace helps prevent type conversion errors caused in situations where loss of precision could occur. Because other data types are converted to and from SqlTypes behind the scenes, explicitly creating and using objects within this namespace results in faster code as well.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|