|
Sounds like a candidate for events. Basically form2 'publishes' a 'FormChanged' event, and then form1 'subscribes' to that event.
If you haven't dealt with events and delegates in C# before, be warned: it can be confusing at first MSDN and CodeProject articles will explain it a lot better than I can..
That said, you'll want something along the lines of:
public class form2 : Form
{
public event EventHandler FormChanged;
...
...
protected void SomeClassThatChangesForm2()
{
...
...
if( FormChanged != null )
FormChanged( this, new EventArgs() )
...
}
...
}
public class form1 : Form
{
...
...
protected void Form2ChangedHandler( object sender, EventArgs e )
{
...
...
}
...
...
public form1()
{
...
this.form2.FormChanged +=
new EventHandler( Form2ChangedHandler );
...
}
...
}
Does that make any sense at all to you
Hope it's helped a little,
Pete
|
|
|
|
|
Hi,
For ages now, I've not been able to insert ANY user controls into my windows forms, they appear on the toolbar, but when i go to insert them, it just says that it cant find the object. this is happening in all of my applications now, and even reseting the toolbar and then adding references from scratch doesn't work. has anyone had any problems like this? or any ideas of how to solve it? all my work has ground to a halt, because i use user controls all the time, and not being able to insert them, and then fiddle with the properties etc makes it very difficult. I can insert them programmatically without any errors though.
any ideas?
thanks in advance!
Dave Kerr
focus_business@hotmail.com
www.focus.esmartweb.com
|
|
|
|
|
I had a coworker with the same problem. His solution was to reinstall visual studio which did the trick for him.
Daniel E. Blanchard
|
|
|
|
|
I have had some luck in deleting the .suo file associated with the project. It seems that this file containes references that sometimes get out of sync with the rest of the project. Visual Studio.NET will recreate the file the next time you load the project.
|
|
|
|
|
I have asked this before but I'm asking it again (sorry):
Does a web reference require source code changes and recompilation if the URL for the web service is changed?
Does this mean that a change of an URL requires a change of namespaces?
Thank you!
Z.
|
|
|
|
|
AFAIK, the only place where the WS URL is specified in the proxy is in the Proxy's Constructor, something along the lines of this.Url = "http://foobar.com/webservice_1".
That property (WebClientProtocol.Url) is public, so you can just change it straight after the proxy is constructed, which means you don't need to recompile the proxy.
|
|
|
|
|
I'm kinda new to the properties. I saw a property example somewhere and I couldn't understand what it does. Could you please tell me what this code does? Here's the code:
public Customers Customers
{
get
{
return new Customers(this);
}
}
|
|
|
|
|
OK, if you had a class called, i don't know, Company, with the property you mentioned in it, then you could do this...
Company someCompany = new Company();
// do stuff with someCompany.
Customers someCompaniesCustomers = someCompany.Customers;
All it means is you have a property called 'Customers', which is of type 'Customers', and when you try to 'get' it (like i did in the example above) the 'get' block is executed, so in this case, it returns a new Customers object, initialsed with the company. It works the other way round too, if the source was this...
public Customers Customers
{
set
{
this.customers = value;
}
}
now you can do this...
sameCompany.Customers = someCustomers;
And the 'set' block is called. I've used 'this' to make it explicit that i'm setting a member variable, thats not actually needed, but it gets the idea across. The example you have is quite unusual however, normally the properties are much more simple, heres a better example.
public class Cat
{
protected string name;
protected string breed;
protected int age;
public int Age // Read only property, you can only 'get' it.
{
get{return age;}
}
public string Name // Read/Write property.
{
get {return name;}
set {name = value;}
}
}
this is more simple. If you've ever used C++, then they're a way of having accessors (GetAge, SetAge etc) which is more user friendly. You can do all sorts with properties, for example, if you make a user control, you can make things like the text color a property, and tell .NET to use a color selector to show the property, so more and more things can be set in design time. Have a read through the MSDN examples on properties, they're very exhaustive.
Dave Kerr
focus_business@hotmail.com
www.focus.esmartweb.com
|
|
|
|
|
That was a great explanation Dave, thank you.
So if I understood it right, the code I posted has a data type of Customers (because it returns a Customers object) and it's also named Customers, am I right?
|
|
|
|
|
|
Hello,
How to fill a listview (detail mode) with one dataset (or more) ? Is it possible ?
Thanks for the response.
Frédéric
|
|
|
|
|
Databinding is not directly exposed to other controls than the datagrid, but you'll find a bunch of entry points on the web ("listview databinding" is a good keyword), including this article[^].
You will also find numerous articles filling Windows Forms controls by hand[^].
|
|
|
|
|
Question 1 (20 Marks):
Compare and contrast the int.Parse() and Convert.ToUint32() methods available in the .NET Framework. Extra credit will be awarded for RTFMs
Seriously though, what's the differences and advantages/disadvantages between the two?
Cheers,
Pete
|
|
|
|
|
Convert.ToInt32 is actually based on ... Int32.Parse.
public static int Convert.ToInt32(string value) {
if (value == null)
return 0;
return Int32.Parse(value);
}
|
|
|
|
|
Thanks!
I suspected that was the case (or vice versa)
So the only difference is that Convert handles nulls then?
BTW, if that code the actual method within the framework, or just an example of how it's probably implemented? If it is the actual method, how did you find it?
|
|
|
|
|
moredip wrote:
If it is the actual method, how did you find it
It is the actual code. Anakrino[^] (.NET decompiler which produces C# and MC++ code).
|
|
|
|
|
Huh! That's cool
|
|
|
|
|
Or you can have a look in the shared source, nicer looking code there
I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02
|
|
|
|
|
Hey, just tell me where to find it
|
|
|
|
|
I have the following problem:
I use the folowing code on client side:
TcpClient client =...
byte[] buffer = new byte[MaxSize];
while(...)
{
networkStream ns = client.getNetworkStream();
readCount = ns.Read(buffer,0,MaxSize)
}
The loop is run on a separate thread, and it is deliberately
run forever. If the TcpClient really has something to
get from server, it really reads it (most probably from
intermediate buffers filled by lower level mechanisms)
And now description of the problem:
When I use this loop for the first time all works fine.
I mean that the complete first Read routine works fine.
(e.g when I want to get 500 KB data from socket, it is
partially fetched in chunks)
When the communication is over, the remote server closes
both stream and TcpClient:
SubsequentClient.Close();
SubsequentClientNS.Close();
In this moment I think, that the client code should
encouter some exception, but nothing is thrown... (?)
The things get worse when i want to use the loop again
and pool the TcpClient (which should me marked invalid now)
whether somethig has arrived =>
i call again Read method, and instad of some error/exception
i just get 0 (no data has been read) (this means, that the server
has not sent any data to client yet)
The question is:
How to make the client code know when the server has really closed
it's network stream (which it uses to send data to the client)
and/or closed TcpClient (which it obtained via Accept() method)
Thanx for any sugestions
|
|
|
|
|
If you want to know the internal socket status, just inherit the TcpClient class and add this code :
public class MyTcpClient : System.Net.Sockets.TcpClient
{
public MyTcpClient()
{
}
public bool Connected
{
get
{
return Client.Connected;
}
}
}
PS : Client is a protected property referencing the internal socket.
|
|
|
|
|
The Client.Connected boolean value allows me to find out whether _my_ code has closed the connection, not the remote side.
I've written a _very_ simple applications: Client and server:
If You can run this, You will see that the client, even after
closing the connection by the remote side can write to (or at least
it thinks so) or read from the stream.
The code:
Client:
static void Main(string[] args)
{
TcpClient tcpClient = new TcpClient("localhost",3000);
NetworkStream ns = tcpClient.GetStream();
byte[] bytesOut = Encoding.Unicode.GetBytes("disconnect_me");
ns.Write(bytesOut,0,bytesOut.Length);
ns.Write(bytesOut,0,bytesOut.Length);
}
The Server
static void Main(string[] args)
{
TcpListener listener = new TcpListener(3000);
listener.Start();
Console.WriteLine("The server is listening..");
TcpClient tcpClient = listener.AcceptTcpClient();
Console.WriteLine("Some client has connected to the server..");
NetworkStream ns = tcpClient.GetStream();
bool listening=true;
const int MaxSize=100;
int bytesRead=0;
byte[] buffer = new Byte[MaxSize];
while(listening)
{
bytesRead = ns.Read(buffer,0,MaxSize);
string command = Encoding.Unicode.GetString(buffer,0,bytesRead);
if(command.CompareTo("disconnect_me")==0)
{
Console.WriteLine("Client wants to be disconnected");
listening=false;
}
}
ns.Close();
tcpClient.Close();
Console.WriteLine("The connection with client has been closed.");
Console.ReadLine();
}
Thanks for any suggestions
|
|
|
|
|
I ought to know this by now, but how do you get a character by its ASCII character code? I'm simply wanting to make a character out of character code 176 ("°"). I don't know how to do it simply because I didn't need to until now. I've done some scouting around on MSDN, but haven't found anything that tells me.
"Do unto others as you would have them do unto you." - Jesus
"An eye for an eye only makes the whole world blind." - Mahatma Gandhi
|
|
|
|
|
Char c = (Char) 176;
MessageBox.Show ("char is " + c);
|
|
|
|
|
Hi, ive been working on porting some php code to c# and have hit an error....
the number two when encoded by the php pack() funditon to a double doesnt get read correctly by c# or im doing it wrong.
eg.
the number 1 gets packed and has the byte representation
63 240 0 0 0 0 0 0
8 byte representation.
the string that contains it contains "?ð "
i get 63 240 0 0 0 0 0 0 as the ascii codes when reading em byte by byte and typecasting to an int.
reading the 8 bytes using the BinaryReader.readDouble()
gives me 3.16202013338398E-322
BinaryReader.ReadUInt64(); gives 64
BinaryReader.ReadInt64(); gives 64
the number was encoded on a windows machine and is being read on a windows machine so the byte ordering should be the same.
the php documentation says using the "d" flag with the pack function gives a "d double (machine dependent size and representation) " the function is the same as the pack function in perl.
the number is packed using pack("d", $value) & unpacked using same flag....
1 = 63 240 0 0 0 0 0 0
2 = 64 0 0 0 0 0 0 0
3 = 64 8 0 0 0 0 0 0
4 = 64 16 0 0 0 0 0 0
i just cant seem to convert a string with those as the char code for each byte into the correct double.
any help would be great cause ive spent a week on this... ive got everything else working except for this which makes all the work ive put in useless...
if i know the algo to read and cant convert a double to the same format and that would be perfect...
is there something im not doing right?
thanks in advanced
nik
|
|
|
|