|
Hi All,
I'm being good and moving all my hardcoded strings into my applications resources, but I've run into difficulties.
I'm using "\r\n" in my hardcoded strings to represent a newline, and this is fine as the compiler converts this to 0x0a, 0x0d for me. If I embed this in a string resource, the "\r\n" is kept as a 4 character literal - not the two control character I'm after. So, how do I represent a newline in a resource string?
Anyone know a simple solution to this?
Thanks
Rob Philpott.
|
|
|
|
|
First, it's recommended you use Environment.NewLine instead of \r\n.
To answer your question, you should be able to paste in your string in the Visual Studio app resources string table. To add a new line, just hit CTRL+Enter when editing the string resource, and it will add the new line for you.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Morality Apart from God
Judah Himango
|
|
|
|
|
Thanks for the reply.
I accept what you say about Environment.NewLine in the general case when using newlines in a particular environment, but I'm developing a server application which satifies a particular communications protocol that states newlines must be '\r\n', so using an environment dependant 'constant' is not good for me.
It's making my head hurt now this supposedly simple thing. Windows uses '\r\n', Linux just '\n'. I actually am coming round to thinking that its not possible to explicity specify a newline or any other control character in xml. Here's an example:
create a 20 char string: "1\r\n2\r\n3\r\n4\r\n" serialize it to disc using XmlSerializer, then deserialize it - its now 12 chars: "1\n2\n3\n4\n". It seems when xml is read in '\r's are just ignored - making this a highly ineffective way of storing strings which may have control characters in them.
Rob Philpott.
|
|
|
|
|
does anybody know how to set the limit to the download speed and upload speed of a computer?
|
|
|
|
|
There's no easy way to do this and no support for anything like this in the .NET BCL. What your asking about, in general terms, requires driver-level programming.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hi, I have a Delphi 6 DLL that I need to run from C#.Net 2.0. I have some problems with it though.
Here Goes:
The Delphi Decalration is :
<br />
function M_Login(ip : PChar; port : LongInt; uci : PChar; vol : PChar; pass : PChar; user : PChar) : LongInt; stdCall;<br />
And the C# Declaration is :
<br />
[DllImport("iMSMAPI.DLL", CallingConvention = CallingConvention.StdCall, CharSet=CharSet.Ansi)]<br />
private static extern Int64 M_Login(string ip, Int64 port, string uci, string vol, string pass, string user);<br />
This gives me an AccessViolationException at RunTime when I call M_Login.
I can Change the Delphi Declaration to expect Strings instead of PChars, this avoids the AccessViolationError, but this causes the values passed to the Delphi DLL to be incorrect. i.e. contain characters that the C# Application did not pass. I passed the value "127.0.0.1" as the ip parameter in C# and when I inspected the ip parameter in Delphi it was '1'#0'2'#0'7'#0'.'#0'0' .
Can anyone help.
Thanx!
Dave Shaw
History admires the wise, but elevates the brave. - Edmund Morris
|
|
|
|
|
Just guessing here, but I think it's the different sizes of char that is the problem. A char is two bytes in C# and I *think* it's not getting interpreted that way in Delphi.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Thanks Senthil,
I have now overcome this problem, however. I am now getting a BroadcastEventWindow.2.0.0.0.33 when I close my application. I am then getting RunTime Error 217 once then getting RunTime Error 216 followed by 'The Memory Could not be "Read"' message in a Continuous Loop until I Kill my Application.
Any Ideas?
Thanks.
Dave
Thanx!
Dave Shaw
History admires the wise, but elevates the brave. - Edmund Morris
|
|
|
|
|
I've declared several public static members in a card function.
<br />
class Card<br />
{<br />
public static int VALUE_HEART = 0;<br />
public static char CHAR_HEART = 'h';<br />
pubic static int VALUE_DEUCE = 0;<br />
public static char CHAR_DEUCE = '2';<br />
}<br />
It is part of a class library used in several applications that pass data back and forth to make sure that the values are always the same.
I just realized however, the my switch statements using these values throw errors:
"A constant value is expected."
But, declaring them as public static const int and public static const char throws errors as well:
"The constant 'Cards.Card.VALUE_HEART' cannot be marked static."
So, how do I fix this problem? The values need to be constant, but I need to be able to access them as static members:
<br />
public static Suit ConvertToSuit(int i)<br />
{<br />
switch (i)<br />
{<br />
case VALUE_HEART:<br />
return Suit.Hearts;<br />
case VALUE_DIAMOND:<br />
return Suit.Diamonds;<br />
case VALUE_SPADE:<br />
return Suit.Spades;<br />
case VALUE_CLUB:<br />
return Suit.Clubs;<br />
}<br />
return Suit.Null;<br />
}<br />
... Suggestions, please? As always, Thanks.
|
|
|
|
|
|
static doesn't mean its constant. It could be set from the outside to another value.
You should declare your variables like the following:
public const int VALUE_HEART = 0;
|
|
|
|
|
Hi!
We have to visualize a maschine scheduling plan in a winform-application...
An example of such a plan in ascii-style:
machine |00:00|00:10|00:20|00:30|00:40|00:50
--------|---------------------------------------
M1 |Job1A| |Job2A|Job3C| |Job1B
M2 | |Job3B| | | |
M3 |Job3A| |Job1A|Job2B|Job3C|
------------------------------------------------
| | | | | |
I hope you get the idea
First idea:
Find a free control that can display gantt-charts --> no (appropriate) found
--> the good ones are not free, unfortunately these are no option for a university assignment
Second idea:
We use a datagrid, with many, many columns. Each column represents a certain timespan.
The rows are the machines, and a marked cell means that the machine y is busy at time x.
For each job that was scheduled, we wan't to use a different color, part-jobs of the same job have
the same color.
Unfortunatelly we encountered several problems:
We use a datatable as datasource for the grid, and "..Columns.Add(...)"
seems to have severe performance problems for #columns>2000, for #columns>10000
the computation time is inacceptable. The same problems, in an even more akward fashion
occured while binding the DataTable ot the datagrid.
I think the problem is that we have many columns (>100.000) with only a few
rows (<100).
If anyone has an idea how to get over these performance problems
or how to visualize the machine scheduling plan in a completely different way,
your help would be greatly appreciated...
with kind regards,
Benjamin Jung
|
|
|
|
|
Just paint it in a user control - how hard could it be?
100,000 objects is too big for any C# model - figure a way to paint only the part the user can see, incrementally reading the necessary data.
You can usually do this pretty well by creating a matrix of cells which fills the user control, and then "rolling" the data behind them as the user scrolls.
|
|
|
|
|
I've got a second form (LogonUser) that I'm opening with a ShowDialog() method inside a button event; I would like to pass this second form the value of a boolean public variable (IsLoggedOn) I have declared in Form1. Any help would be greatly appreciated.
This is how I'm opening the second from========================
LogonUser validateLogonUser = new LogonUser();
validateLogonUser.MyParentForm = this;
validateLogonUser.StartPosition = FormStartPosition.CenterParent;
validateLogonUser.ShowDialog();
|
|
|
|
|
Just expose a property on the second form and set it from the first form.
Like this.
class SecondForm : Form
{
bool val;
public bool IsLoggedOn
{
set { val = value; }
}
}
class FirstForm : Form
{
public void SomeMethod()
{
SecondForm sf = new SecondForm();
sf.IsLoggedOn = this.IsLoggedOn;
...
sf.ShowDialog();
}
}
Or, if you are passing "this" to the second form (like you did in your sample code), you can directly access the public variable, provided MyParentForm is typed strongly.
I'd recommend the first approach though.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Thanks for responding. I've been chipping away at this problem and I've had some success with the following code blocks:
form1.cs=====================================
LogonUser validateLogonUser = new LogonUser();
validateLogonUser.MyParentForm = this;
validateLogonUser.loggedOnUser = this.validatedUser;
validateLogonUser.StartPosition = FormStartPosition.CenterParent;
validateLogonUser.ShowDialog();
LogonUser.cs=================================
public Form1 MyParentForm;
private void LogonUser_Load(object sender, EventArgs e)
{
this.textBoxUserName.text = this.loggedOnUser;
}
I don't seem to be using any reference to MyParentForm or Form1 properties to access the value passed from Form1? It works, but I don't know why.
|
|
|
|
|
It works because of this line
rich_wenger wrote: validateLogonUser.loggedOnUser = this.validatedUser;
You are setting the value of the loggedOnUser variable in LogOnUser to the one in Form1.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Hi. You can do it bay many ways.
one of the simplest way is to write the value of boolean to the hard desk and then to read it from the second form.
in the first form:
private void SaveInfo()
{
try
{
FileStream file = new FileStream("info.txt",FileMode.Create);
StreamWriter sw = new StreamWriter(file);
sw.WriteLine(IsLoggedOn.ToString(),true);
sw.Close();
}
catch(System.Exception se)
{
MessageBox.Show(se.ToString());
}
}
and then you have to call this method from the method that call the other form.
in the second form:
private bool ReadInfo()
{
try
{
FileStream file = new FileStream("info.txt",FileMode.Open);
StreamReader sr = new StreamReader(file);
bool b = sr.ReadLine();
sr.Close();
}
catch(System.Exception se)
{
MessageBox.Show(se.ToString());
}
return b;
}
so now bool b has the value of IsLoggedOn.
There are other ways but this on is simple.
Thanks.
Asaad Mamoun Hassan
Bc in Computer Science.
|
|
|
|
|
Whoa, don't you think it is overkill to write to the hard disk just for passing a value to an in-memory object? And what would happen if two instances of the form are launched at the same time?
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Guys, beginner question
Some times when you get some code examples from the web, you stack with problem that code snippet doesn’t contain namespace “using” section
e.g. code : HttpUtility.HTMLDecode(“blah”)
if you don’t know in witch namespace HttpUtility present, you are in troubles
so, is some Visual Studio tool can search for a namespace ?
thanks for you attention
KZ
and may the source be with you
|
|
|
|
|
Just search for "HttpUtility class" in the documentation (index in MSDN Library or msdn.microsoft.com). The class overview shows the complete namespace.
---
b { font-weight: normal; }
|
|
|
|
|
Guffa - 10x a 1000000
exactly what i wanted
and may the source be with you
|
|
|
|
|
I've been reading about sockets for the past two days. I've got a few questions, mostly relating to the differences between synchronous and asynchronous behavior.
I'm writing the following application:
Data Server: Must be able to have multiple clients connected. Once a client has connected, it must be able to recieve data from that client and return data to that client at all times. It will need to be able to recieve and processing data from more than one client at a time.
Data Client: The client simply connects, then sends data either at intervals (1-4 XML formated data strings per second), or manually when a user chooses. The data needs to be sent to the server (while connected) and then the client needs to wait for a response.
From what I've read, using the TcpListener/TcpClient interface is synchronous: If there are multiple clients connected - if one client is sending data, another cannot be sending data. But if I use a threaded socket interface using asynchornous methods, then data from multiple clients can be recieved at the same time. Am I understanding this correctly?
Can someone recommend a good solution for this? Do I need to use the asynchronous socket methods? Do I need to use threads? I've found many examples of tcp/client interfaces, but most of the authors don't explain the benefits/limitations of their code - so it's hard to know if I should base my work from what they're presenting. Does anyone know of a good tutorial that will meet my needs for this project?
... as always, Thanks for the help.
|
|
|
|
|
I have recently written something similar to you Data Server, and it works as follows. In the main thread I spawn a new thread which just listens (using TcpListener ) for incoming TCP connections.
When a new connection arrives the TcpListener passes a Socket object on the way out of AcceptSocket . I pass this socket to a ThreadPool worker thread which will handle the rest of the communication for that connection, meanwhile the listener thread loops back and waits for another socket connection. That provides a straight-foward multithreaded server approach - the server can communicate with several clients at the same time with each conversation in isolation from the others.
As far as the client goes, that should be just straight forward socket stuff using either Socket or TcpClient .
It's gone midnight here and I'm going to bed, but if you'd like me to send some sample source code through drop me a line and I'll do it tomorrow.
Rob Philpott.
|
|
|
|
|
Hi out there,
I try to add an new column to a ListView at runtime. When I initial the ListView everything works perfectly. But when I use:
ListView.Columns.Add("SomeText",-2,HorizontalAlignment.Center);
within the programm nothing happens. Even if I add an update or refresh argument.
Any ideas?
thx for your support.
woops00
|
|
|
|