|
Hi d@nish,
Thanks for your reply.Its useful to me.
|
|
|
|
|
Yeah, but he wanted design time support, so I didn't bother to point out how to do it in code. What makes more sense to me is
List<TextBox> _textboxes = new List<TextBox>(); // this is a member variable
foreach(Control control in Controls)
{
if (control is TextBox) _textboxes.Add((TextBox)control);
}
So, he gets a list of all textboxes, which he can add in the designer.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Hi Christian Graus,
What you mean by "So, he gets a list of all textboxes, which he can add in the designer."?And where should i insert of your coding?
thanks in advance
regards
coccon
|
|
|
|
|
Hi,
Could you please let me know where can I get the sample XNA solutions. That solution should have used .tga files.
Thanks in advance.
|
|
|
|
|
creators.xna.com
It wouldn't matter if the solution used .tga, .bmp or .jpg... The content pipeline will do all the processing for you.
Cheers,
|
|
|
|
|
I'm coming from an embedded background using the Nucleus RTOS, and programming in C++. The system I worked on made very heavy use of constructs such as Semaphores, Mutexes, Pipes, Queues, and timers. I'm transitioning to a new project that will be using C# and .NET [I am currently unsure of what version it will be using; if it will be using the full blown .NET or the compact framework, however].
I'm trying to learn analogies for these constructs. I see that there are Mutexes, of course, but do the mutexes have timeouts available? i.e. you want to grab some resource, and if you can't grab it in X amount of time, fail, check an error condition {throw an event here instead?} and do something with that error. When we wanted to communicate between threads, we would use Pipes - we could read a pipe and suspend on it indefinitely to wait for data; or suspend on it with a timeout. What is analagous?
Also - I think I could benefit on a book that delves into these types of concepts. Most of the C#, .NET books I"ve looked at tend to go very lightly on the chapters to do with async communication. Most tend to talk about locking critical sections, but don't seem to talk about it further - a few have said these are advanced topics and are the scope of other types of books. Guess what, I need one?
Thanks all.
PS: Wasn't sure if I should post this in the C# forum or the .NET forum... Took a stab at the C# forum. Apologies if it's the wrong place.
|
|
|
|
|
Read more on the subject here[^]
|
|
|
|
|
I'm wondering if it's possible to have a method that accepts an anonymous delegate invoke on that delegate and have the delegate have a return value and then have that method return the value.
The requirements are:
1. The anonymous delegate must be able to incapsulate parameters, like the Action<> object.
2. The anonymous delegate must be able to have a return type like: string returnValue = actionMethod.Invoke();
Example of the concept:
public void CallRetrieveDataFunction()<br />
{<br />
IRandomInterface classMain = new ClassMain();<br />
<br />
Action <irandominterface> invokeMethod = delegate(IRandomInterface executeReference) { executeReference.GetProductByID(productID); };<br />
<br />
object response = RetrieveData(invokeMethod, classMain);<br />
}<br />
<br />
public object RetrieveData(Action<t> methodToExecute, U referenceOfObjectImplementingInterface)<br />
{<br />
object returnValue;<br />
returnValue = methodToExecute.Invoke(U);<br />
return returnValue;<br />
}<br />
</t></irandominterface>
Anybody have any ideas?
|
|
|
|
|
Action delegates don't allow you to return values. I think the Func<> delegate is what you need, it lets you specify up to 4 input parameter types and a return type. Here is your example, using Func:
<br />
public interface IRandomInterface<br />
{<br />
object GetProductById( );<br />
}<br />
<br />
public class ClassMain : IRandomInterface<br />
{<br />
public object GetProductById( ) { return new object(); }<br />
<br />
public static void RetrieveDataFunction( )<br />
{<br />
IRandomInterface classMain = new ClassMain();<br />
Func<irandominterface, object=""> invokeMethod = delegate( IRandomInterface executeReference )<br />
{<br />
return executeReference.GetProductById();<br />
};<br />
<br />
object response = invokeMethod( classMain );<br />
}<br />
}<br />
</irandominterface,>
|
|
|
|
|
Hi,
I was having a read of this article before.
When we override something like a keypress we use the below code:
<br />
protected override void OnKeyPress(KeyPressEventArgs e)<br />
{<br />
<br />
base.OnKeyPress(e);<br />
}<br />
In the article he declares the methods in the abstract class like this:
<br />
public String Delete()<br />
{<br />
return "Employee " + id + " " + <br />
lname + " " + fname + <br />
" deleted";<br />
}<br />
and implements it like this:
<br />
public new String Delete()<br />
{<br />
return base.Delete();<br />
}<br />
Question 1. What happened to the override like in the Microsoft class?
Question 2. How could I declare a method that looks the same as the Microsoft one?
Question 3. Does anyone know where the System.Windows.Forms abstract classes are located? I tryed to find the answer myself on reflector but could not find anything that is overrided under the namespace.
Cheers,
|
|
|
|
|
Hi Mark,
1.
override and new are opposites.
if you have:
class baze {
public virtual jef() {Console.WriteLine("baze.jef");}
public virtual pol() {Console.WriteLine("baze.pol");}}
class inh : baze {
public override jef() {Console.WriteLine("inh.jef");}
public new pol() {Console.WriteLine("inh.pol");}
}
static void main() {
baze D=new inh();
inh J=new inh();
D.jef();
D.pol();
J.pol();
}
you would get:
inh.jef // override means: use the method that fits the actual object
baze.pol // new means: don't override, use the method fitting the variable
inh.pol // dito
2.
by following their pattern? (and accepting their semantics)
3.
WebRequest is an abstract class
not sure there are any abstract classes in Windows.Forms
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
As always, thanks for your excellent answer Luc.
Cheers,
|
|
|
|
|
you're welcome.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
System.Drawing.Brush and System.Drawing.Image are the abstract classes I use most often.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
Let's say we have Computer A with a socket on port 1337, where BeginAccept has been called. Then we have Computer B with a socket that wants to connect to Computer A, but it doesn't not know Computer A's IP address. Is there a way to search for an open socket within a local network?
Thanks.
BTW the "Post Message" button doesn't work in Ubuntu 8.04, Firefox 3 Beta 5
|
|
|
|
|
Sounds like a bad idea.
normally you:
- know which computer you want to address (you may want to use DNS to translate a logical
name, a URL, to a specific IP adr)
- know which port you want to use (typically each protocol has a specific port; exception
is a multi-user server typically has a connection port and provides one of many available
client ports)
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
Well I'm making an inter-network Instant Messenging program. I want a user to be able to create a room, then other users can search for open rooms and connect. I'll make the port constant so they cann't screw with it.
|
|
|
|
|
OK,
I don't know how IM systems do it.
you could broadcast things on a small network, but that wouldn't scale at all.
so it seems to me you need one or more servers that know what rooms are in existence
and how to connect to them.
I would suggest you google for IM protocols; should be readily available.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
The thing is, where I primarily want to use it: there's no internet and I don't have access to the server in the room, and all the IPs are assigned by DHCP.
What I could do (albeit inefficient), is get the network IP, and subnet mask (that's the next question), and try to resolve each IP, example:
network is 192.168.1.0, subnet mask is 255.255.255.0, therefore 254 max users
try to resolve 192.168.1.1
then 192.168.1.2
If the resolve is successful, try to connect the socket.
and so on, and so forth. But I think the room's local IP is a class A address so that would be a lot of network activity.
|
|
|
|
|
Why not have one (or a few) IM servers in the network,
either store their IP addresses on every machine or do a broadcast to get one's attention,
then take it from there?
if there is no dedicated server, make that a dynamic role, assigned to the first machine
trying to enter a room, and passing it on when the machine exits (or no longer responds).
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
But there's still one problem: DHCP assigned IP's. I could store the MAC addresses of the NIC's then do a RARP to get the IP's, although I don't know how to do that either. Regarding the second paragraph: how would the first machine get the IP of the Host?
I do have the password for the Admin user but there's problems with putting a Server program onto that machine: it may not be on and I may get into trouble.
|
|
|
|
|
FYI: I haven't done this, and don't know any details, but I would expect WMI is capable
of enumerating current machines (by name I guess) in the workgroup or domain.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
|
Hi all, first time poster so i apologize in advance if my question is malformed or simply stupid, that being said, let me get on to the question itself:
I have create an application that is a context menu on folders that uses a text file in order to check if any of the words in it, appear in the folder name (I'm obviously simplifying it in order to make the question more focused).
My problem is that the file should be read every time that the application is run and it looks for it in the folder that hosts the folder I'm looking at with the context menu (for example: if I'm right clicking "c:\program files\visual studio 2008" it looks for the file at "c:\program files")
I've tried deploying it using the publish wizard in the visual studio and other methods i saw in the site (iexpress for example) but i couldnt tell the application that it will be installed to c:\program files\app for example and that it should look for the file there.
this is the code that reads the config file:
static string[] readConfigFile(string fileLocation)
{
return System.IO.File.ReadAllLines(configFileName);
}
where configFileName = "config.txt" - no path really, i've tried using ".\config.txt" and other methods to no avail - the only way to make it work is to have it read the file from a fixed location and copying it there myself - but that makes no sense since i can't ask the person who installs it to copy one file there and the other someplace else etc...
what i need is a way to tell the application to look for the file only where the application itself resides or better yet - a way to make an installer that is easily customizable.
Thanks a bunch,
Elad Katz.
|
|
|
|
|
Ok, sounds like you have a couple of questions:
- How can I read a file when my application is deployed using ClickOnce? (that's the deploy built into Visual Studio)
- How can I specify that my program be installed into program files?
The answer to the first question is, you'll need to make your config.txt be deployed with your application. Here's how: right-click on the file in Visual Studio solution explorer, click properties. From the properties window, on the Build Action drop down, select Content .
That's it. Republish your solution again, then when you go to read the file, don't specify a path. It should work.
Another way to accomplish this is to use the built-in stuff -- no reading files explicitly required. Check out application settings in Visual Studio 2005 (and 2008)[^]
To answer your second question, you'll need to build a setup program and don't use ClickOnce deployment. There are articles on this site to help you with that.
|
|
|
|