|
|
If all you want is to have the ListBox show the content of the array, then either:
string[] myArray = new string[] {"one", "two", "three"};
myListBox.Items.AddRange(myArray);
or
string[] myArray = new string[] {"one", "two", "three"};
myListBox.DataSource = myArray;
will do the trick.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Where does setting save values in C#
Demo30.Properties.Settings d = new Demo30.Properties.Settings();
d.DayOfYear = DateTime.Now.DayOfYear;
d.Save();
Does it save the values in Registry.
|
|
|
|
|
Without knowning what Demo30 is, it is impossible to tell. What type is Demo30 and where did it come from?
|
|
|
|
|
|
So it is your code? Otherwise, what project?
|
|
|
|
|
its project
Properties.Settings
|
|
|
|
|
Thanks, now I know what the problem is: wetware failure.
|
|
|
|
|
I just wanna to know where does it save the values
|
|
|
|
|
|
jojoba2011 wrote: Does it save the values in Registry.
No its value is not Save in Registry. Its[Setting value] value is Save in app.config file.
|
|
|
|
|
Hard to say from that little information you provided, but I recommend to have a look at http://msdn.microsoft.com/en-us/library/k4s6c3a0.aspx[^]
You will learn there that the file Demo30.exe.config file should be attached to your project - assuming you are working on a C# console application. Note that many .Net libraries use individual kind of properties and settings and that these might change from version to version of the framework. Also note, that this has nothing to do with C# as a language, this is the functionality provided by Microsoft's libraries and is well supported by Visual Studio IDE.
|
|
|
|
|
i have prolem with uloadinge image to server
i try to upload image and send data (POST) method a the same time
i use this code
HttpWebResponse response;
Stream resStream;
StreamReader objSR;
CookieContainer cookieContainer = new CookieContainer();
ASCIIEncoding encoding = new ASCIIEncoding();
HttpWebRequest request;
string sResponse;
string postData;
byte[] data;
string UrlLogin;
UrlLogin = "http://localhost:63637/whois/test0.aspx";
string uploadfile = "C:\\fax\\pics\\7130570.jpg";
string fileFormName = "userfile";
string contenttype = "image/pjpeg";
postData = "?wm_flag=" + "0";
postData += ("&action=" + "process");
postData += ("&hi=" + "ft");
request = (HttpWebRequest)WebRequest.Create(UrlLogin + postData);
request.KeepAlive = true;
request.CookieContainer = cookieContainer;
string boundary = "----------" + DateTime.Now.Ticks.ToString("x");
request.ContentType = "multipart/form-data; boundary=" + boundary;
request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)";
request.Method = "POST";
request.AllowAutoRedirect = true;
data = encoding.GetBytes(postData);
StringBuilder sb = new StringBuilder();
sb.Append("--"); sb.Append(boundary); sb.Append("\r\n"); sb.Append("Content-Disposition: form-data; name=\""); sb.Append(fileFormName); sb.Append("\"; filename=\"");
sb.Append(Path.GetFileName(uploadfile)); sb.Append("\""); sb.Append("\r\n"); sb.Append("Content-Type: "); sb.Append(contenttype); sb.Append("\r\n"); sb.Append("\r\n");
string postHeader = sb.ToString();
byte[] postHeaderBytes = Encoding.UTF8.GetBytes(postHeader);
byte[] boundaryBytes = Encoding.ASCII.GetBytes("\r\n--" + boundary + "\r\n");
FileStream fileStream = new FileStream(uploadfile, FileMode.Open, FileAccess.Read);
long length = postHeaderBytes.Length + fileStream.Length + boundaryBytes.Length;
request.ContentLength = length;
Stream requestStream = request.GetRequestStream();
requestStream.Write(postHeaderBytes, 0, postHeaderBytes.Length);
byte[] buffer = new Byte[checked((uint)Math.Min(4096, (int)fileStream.Length))];
int bytesRead = 0;
while ((bytesRead = fileStream.Read(buffer, 0, buffer.Length)) != 0)
requestStream.Write(buffer, 0, bytesRead);
requestStream.Write(boundaryBytes, 0, boundaryBytes.Length);
response = (HttpWebResponse)request.GetResponse();
resStream = response.GetResponseStream();
objSR = new StreamReader(resStream);
sResponse = objSR.ReadToEnd();
this code workfinewithout any problem with uploading photo
but my problem with i request.form["wm_flag"] in the server i got error because i must send it as POST and i don't know how to do it ?? please HELP ...
Palestine
|
|
|
|
|
Hello i am now currently working on a project that requires me to get the min and max color from the listbox.
the listbox is as show below:
http://img257.imageshack.us/img257/4391/help1a.jpg
Is there any way i can extract all the values of R, G and B and find the min and max value of the RGB from there?
|
|
|
|
|
Ummm... what? I bet the max of each is 255 and the min of each is 0.
What exactly are you trying to do?
|
|
|
|
|
I can't see a problem here; create a loop, parse each line, and calculate min/max. It is elementary.
|
|
|
|
|
sorry for the brief explanation. I am trying to find out the so called average color of an image. for example a red flower right i have to find the min and max color of the red flower in order to do a background strip using the min and max color found. right now i want to find the average R, average G and average B. as u can see from the pic in the link i have posted above, all the color values are listed in a listbox. how can i extract just the RGB values from it and find the min and max color value of the particular red flower as an example.
|
|
|
|
|
Looking at the image, I think you have directly added the colors to the Items collection of the ListBox, so what you see in the list is what ToString() method returns for each one of them. So having each color is as simple as using a foreach loop.
I think the problem you have here is the question itself. How will you define what color is bigger than other one? I mean: Blue color RGB values are 0, 0, 255; Red color RGB values are 255, 0, 0. So, which one is bigger?
Calculating the average color of an image has nothing to do with min or max color or RGB component. You just have to sum the RGB components separatedly, divide each sum by the number of pixels of your image, and you will have the RGB components of the average color of it.
|
|
|
|
|
oh thank you. is there any way i can find the min and max color range of the example the case of a red flower?
I manage to get the RGB color value of every pixel in that image and is being stored in an array which have 100 entries. is it possible to just select example array[0], array[4] and array[8]?
modified on Sunday, November 7, 2010 2:11 AM
|
|
|
|
|
You're still not getting it. How do you define what makes a "minimum color" and "maximum color"?? Since a color is made up of 3 to 4 seperate values, combined, there is no "min" and "max" color as defined by these mathmetical terms.
|
|
|
|
|
Ok I decided to give it a try using Async sockets. I'm trying to get the client and server to talk. Right now I can get the SERVER to receive data from the client.. but when I try to get the server to send data back to the client it doesn't work!!
Client:
static void Checkin()
{
IPEndPoint endPoint = new IPEndPoint(serverIp, 5555);
Socket sendSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
sendSocket.Connect(endPoint);
Operations ops = new Operations();
ops.Task = Operations.Tasks.CHECKIN;
ops.NetBios = System.Environment.MachineName;
ops.ClientId = 1;
IFormatter formatter = new BinaryFormatter();
NetworkStream ns = new NetworkStream(sendSocket);
formatter.Serialize(ns, ops);
ns.Flush();
ns.Close();
Console.WriteLine("Beginning to get data");
Receive(sendSocket);
receiveDone.WaitOne();
sendSocket.Shutdown(SocketShutdown.Both);
sendSocket.Close();
}
private static void Receive(Socket client)
{
try
{
StateObject state = new StateObject();
state.workSocket = client;
client.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0,
new AsyncCallback(ReceiveCallback), state);
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
static void ReceiveCallback(IAsyncResult iar)
{
StateObject state = iar.AsyncState as StateObject;
Socket client = state.workSocket;
try
{
int recv = client.EndReceive(iar);
if (recv > 0)
{
state.ms.Write(state.buffer, 0, recv);
client.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0,
new AsyncCallback(ReceiveCallback), state);
}
else
{
if (state.ms.Length > 0)
{
state.ms.Seek(0, 0);
IFormatter formatter = new BinaryFormatter();
Operations ops = (Operations)formatter.Deserialize(state.ms);
Console.WriteLine("Got: " + ops.Task.ToString());
Console.ReadKey();
}
receiveDone.Set();
}
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
Console.ReadKey();
}
}
Server:
private void StartListening(object p)
{
int port = Convert.ToInt32(p);
try
{
socketlistener = new Socket(AddressFamily.InterNetwork, SocketType.Stream,
ProtocolType.Tcp);
IPEndPoint iep = new IPEndPoint(IPAddress.Any, port);
socketlistener.Bind(iep);
socketlistener.LingerState.Enabled = false;
socketlistener.Listen(100);
Logging.Debug("Socket initialized and listening on port " + p.ToString());
while (true)
{
allDone.Reset();
socketlistener.BeginAccept(new AsyncCallback(AcceptClient), socketlistener);
allDone.WaitOne();
}
}
catch (Exception ex)
{
Logging.Log(ex.ToString());
}
}
private void AcceptClient(IAsyncResult iar)
{
allDone.Set();
try
{
Socket old = iar.AsyncState as Socket;
Socket client = old.EndAccept(iar);
Logging.Debug("Client (" + client.RemoteEndPoint.ToString() + ") connected");
StateObject state = new StateObject();
state.workSocket = client;
client.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0,
new AsyncCallback(GetClientData), state);
}
catch (Exception ex)
{
Logging.Log(ex.ToString());
}
}
private void GetClientData(IAsyncResult iar)
{
StateObject state = iar.AsyncState as StateObject;
Socket client = state.workSocket;
try
{
int recv = client.EndReceive(iar);
if (recv > 0)
{
state.ms.Write(state.buffer, 0, recv);
client.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0,
new AsyncCallback(GetClientData), state);
}
else
{
if (state.ms.Length > 0)
{
state.ms.Seek(0, 0);
IFormatter formatter = new BinaryFormatter();
Operations ops = (Operations)formatter.Deserialize(state.ms);
Logging.Debug("Client (" + client.RemoteEndPoint.ToString() + ") sent action " + ops.Task.ToString() +
" with " + Convert.ToInt32(state.ms.Length) + " bytes of data");
Actions.PerformAction(ops);
ops = null;
state = null;
Send(client);
}
Logging.Debug("Client (" + client.RemoteEndPoint.ToString() + ") is disconnecting.");
client.Shutdown(SocketShutdown.Both);
client.Close();
}
}
catch (Exception ex)
{
Logging.Log(ex.ToString());
}
}
private void Send(Socket client)
{
try
{
Operations ops = new Operations();
ops.Task = Operations.Tasks.UPDATE_DEVICES;
ops.NetBios = Environment.MachineName;
Logging.Debug("Sending task (" + ops.Task.ToString() + ") to client " + client.RemoteEndPoint.ToString());
IFormatter formatter = new BinaryFormatter();
NetworkStream ns = new NetworkStream(client);
formatter.Serialize(ns, ops);
ns.Flush();
ns.Close();
client.Disconnect(false);
client.Close();
}
catch (Exception ex)
{
Logging.Log(ex.ToString());
}
}
So what am I doing wrong here? I am trying to get the client to send info to the server (this works if I don't put the code on the client for getting info from the server) and when the server gets it, it needs to send information back to the CLIENT. (this doesn't work).
So Client contacts server and says "Here is the information", the server puts it in a database (not shown), then the server sends information back saying "This is the actions you need to perform right now".
|
|
|
|
|
Figured it out... I wasn't paying attention...
In my code I was only reading the first 1024 bytes. So if it was under 1024 bytes it would work fine. I put in code to check if the amount read equaled the buffer size and then called the beginreceive again until we read all the data.
|
|
|
|
|
Just a friendly suggestion. When you answer your own question like this (or in fact, if anyone answers it well), add "[solved]" to the subject of the original. Helps people searching the archives.
Cheers,
Peter
Software rusts. Simon Stephenson, ca 1994.
|
|
|
|
|
Ahh will do! Thanks for the tip! Sorry I didn't do it before
|
|
|
|
|
Good You did what you want.. Keep it up
|
|
|
|
|