|
Nice, thanks very much.
"I am a lair" Is this statement true or false ?
|
|
|
|
|
Hi,
I want to develop an application with menus. I want to make only one event handler method which handles a whole group of menu items by firstly identifying which MenuItem sends the click event and then performing the appropriate action. But I don't find any way to retrieve any info telling me which specific MenuItem sends a click event at the moment. The sender and e parameters seem to carry some very general information, not from a specific MenuItem sending the click event.
This info must exist somewhere, because Windows knows which menu shall be performed at the moment…, but C# seems to hide it for the programmer!
Is there a way to get that info?
Regards,
M Shafaat
|
|
|
|
|
M Shafaat wrote: But I don't find any way to retrieve any info telling me which specific MenuItem sends a click event at the moment. The sender and e parameters seem to carry some very general information, not from a specific MenuItem sending the click event.
No prob. You just have to cast the sender parameter to a MenuItem to get the info you want.
this.mnuFileSave.Click += new System.EventHandler(this.MenuHandler);
this.mnuFileSaveAs.Click += new System.EventHandler(this.MenuHandler);
.
.
.
private void MenuHandler(object sender, EventArgs e) {
MenuItem selectedMenu = (MenuItem)sender;
switch (selectedMenu.Name) {
case "mnuFileSave" :
MessageBox.Show(this, "Save selected");
break;
case "mnuFileSaveAs" :
MessageBox.Show(this, "SaveAs selected");
break;
}
}
Share and enjoy.
Sean
|
|
|
|
|
This is principally right but I would do it this way:
if (sender == mnuFileSave)
MessageBox.Show(this, "Save selected");
else if (sender == mnuFileSaveAs)
MessageBox.Show(this, "SaveAs selected");
else
MessageBox.Show(this, "'Unknown' selected");
This way removing/renaming MenuItems will immediatly result in an compilation error so that you have the chance changing it accordingly.
|
|
|
|
|
Thnaks a lot
Regards
M Shafaat
|
|
|
|
|
I'm using mciSendString to play an .avi file.
The problem is if i play the file in fullscreen when i click on the screen it came back in windowed mode but it stop the movie.
Why?
How can i avoid to make came back in windowe mode after click when it is fullscreen?
Or how can i handle a function when it happens so to continue to play the movie?
I hope to be explained good, in contrary case please ask me.
Regards.
|
|
|
|
|
Hi all,
I've encountered a strange behaviour of one of my objects. After it updates itself in a method(updates some private fields) the changes happen when the method is being executed but when execution returns to the line where the method was called, the object is the same as before. Let me show you the code which does this.
<pre>
public enum DConfMode
{
Normal,
NoInit
}
public class DConf
{
private String hostname;
private String database;
private String username;
private String password;
public DConf(DConfMode Mode)
{
switch (Mode)
{
case DConfMode.Normal:
this.Init();
break;
case DConfMode.NoInit:
break;
}
}
public void Init()
{
XmlTextReader reader = new XmlTextReader(DGlobals.ConfFile);
while (reader.Read())
{
switch (reader.Name)
{
case "hostname":
this.hostname = reader.Value;
break;
case "database":
this.database = reader.Value;
break;
case "user":
this.username = reader.Value;
break;
case "password":
this.password = reader.Value;
break;
}
}
reader.Close();
}
public String DbHostname
{
get
{
return this.hostname;
}
}
public String DbDatabase
{
get
{
return this.database;
}
}
public String DbUsername
{
get
{
return this.username;
}
}
public String DbPassword
{
get
{
return this.password;
}
}
}
</pre>
<pre>
DConf conf = new DConf(DConfMode.NoInit);
conf.Init();
Console.WriteLine(conf.DbHostname);
</pre>
So DConf does the problem. In the second code excerpt, echoing conf.DbHostname doesn't do anything, but when I've debugged it, in conf.Init(); the values are clearly populated. So I'm quite confused why this happens. Here's some sample xml which you could use:
<code>
<configuration>
<user>username</user>
<password>samplepass</password>
<hostname>localhost</hostname>
<database>dbname</database>
</configuration>
</code>
As a sidenote, is it safe calling Init(); in DConf's constructor? I suppose no, since it changes fields and the object hasn't been guaranteed to have been fully set up, am I correct? Any help is greatly appreciated.
Regards,
gamehack
-- modified at 19:29 Saturday 29th October, 2005
|
|
|
|
|
I've found my mistake. It's in my xml handling code. Thanks for reading.
Regards
|
|
|
|
|
Hi!
I have a binary file that contains strings one after the other and I want to replace a string at offset x. The existing string is, let's say 10 bytes long, but the new one is 12 bytes long. How do I replace the old string at position x without overwriting the first 2 bytes of the next string and without rewriting the entire binary file from offset x.
Thanks already in advance!
|
|
|
|
|
You don't.
---
b { font-weight: normal; }
|
|
|
|
|
You can't. You MUST rewrite the entire file. Read the the part up to the point where you are replacing the string, write it to a new file. Append the new string, then read the file from the point after the string your replacing and append that to the new file.
There is NO other way to do this.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I see. Thanks for your help guys!
|
|
|
|
|
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.
|
|
|
|