|
Wouldn't that be simply be a case of declaring a public method in the second form which supplies that information, and then calling it from the first form:
class SecondForm : Form
{
...
...
public AdvancedInfo GetAdvancedInfo()
{
...
...
}
...
...
}
class FirstForm : Form
{
...
SecondForm mySecondForm;
...
...
void SomeMethodThatNeedsAdvancedInfo()
{
AdvancedInfo info = mySecondForm.GetAdvancedInfo();
...
}
}
Does that help?
Pete
|
|
|
|
|
Thanks, Pete
But I knew that already, the real problem is that my 1st form needs to know when I've entered the data in the second form. So the 2nd must somehow tell the first one that he's ready.
|
|
|
|
|
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
|
|
|
|