|
I posted a response to your first post a few pages into this forum.
Cheers - James
James Simpson
Web Developer
imebgo@hotmail.com
|
|
|
|
|
When an load event occur, you can call the function [FormName]_Load(object sender, System.EventArgs e) to deal, also or call the function On_Load(System.EventArgs e). What's diffrent between them?
=== Game is power! ===
|
|
|
|
|
YourForm.OnLoad is an override of Form.OnLoad , which actually raises the event. Using this override would, for example, allow you to prevent the event from being fired, by not calling base.OnLoad .
YourForm_Load is an event handler for the Load event and allows you to perfrom some action when the Load event occurs. To follow the previous example, you would not be able to prevent the event from being fired as it already has been.
Derek Lakin.
The great thing about being a slayer: is kicking ass is comfort food. Buffy
Salamander Software Ltd.
blog: Digital Thoughts
|
|
|
|
|
I am trying to write a char in hexadecimal format to a binary file. I'm using the following:
FileStream fs = new FileStream("test.bin");
BinaryWriter bw = new BinaryWriter(fs);
char c = '\xABCD';
bw.Write(c);
What I get in the file is EA AF ..... instead of expected
AB CD ......
Any ideas?
Thx.
Samo.
|
|
|
|
|
What's happening is that, by default, the character is being written out in UTF-8. If you want to just write out the character as if it were a ushort, either cast it to a ushort, or change the encoding for the binary writer.
By the way, writing out the ushort 0xABCD to a file will produce 0xCD 0xAB in that order.
Cheers, Julian
Program Manager, C#
This posting is provided "AS IS" with no warranties, and confers no rights.
|
|
|
|
|
Is it possible for calls to Socket.Send() to block?
If a socket "s" has s.Available > 0, and one calls s.Receive() with a read length of s.Available, can the call to s.Receive() block?
If blocking is possible in the situations described above, is there a way (without using asynchronous I/O) to determine in advance which calls will block, and/or avoid blocking?
Andrew
|
|
|
|
|
I want to match and replace a character sequence in the middle of a string, but the same sequence could appear at the begining or the end of the string as well and should be left alone. So for example:
Regex r = new Regex("a");
will match all occurences of "a" in a string, but:
Regex r = new Regex("^a");<br />
will only match "a" if it occurs at the begining of the string, and:<br />
<code>Regex r = new Regex("a$");<br />
will match it at the end. The trouble is I want to match "a" when it doesn't appear at the begining or the end of a string. There doesn't seem to be a way to say not begining and not end though? Does anybody know if such a thing is possible? I could use:<br />
<code>Regex r = new Regex(".a.");
but that will also match the character before and after the "a" which I don't want to replace.
Cheers
WJ
|
|
|
|
|
(?<=.)a(?=.)
The topic to look up in the docs is zero-width lookahead/behind assertion.
--
-Blake (com/bcdev/blake)
|
|
|
|
|
Works like a charm, thanks. That particular topic is really hard to find in MSDN (especially when you don't know what your looking for).
If anybody else is having trouble finding it, it's under "Grouping Constructs" on the "Regular Expressions Language Elements" page of my MSDN library (VS .NET 2003).
Regular expressions give me a headache.....
|
|
|
|
|
|
Hi,
I need to fire COM events from C# and the client to handle those events is in C++.
Following is the code snippet of the COM events and the dispinterface in C#.
[Guid("12854E47-AD44-4283-B503-1176CC827A49")]
public interface Foo1ComInterface
{
void FireRequest( string str );
}
[Guid("073D1766-7969-41fd-B794-8B65B0EADAF3")]
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface Foo1ComEvents
{
void FooEvent( string str );
}
[ Guid("22EFEC33-5B40-4417-AFF0-DE0C5B7C9E47")]
[ ClassInterface(ClassInterfaceType.None) ]
[ ComSourceInterfaces(typeof(Foo1ComEvents))]
public class BooHoo : Foo1ComInterface
{
.....
}
So far I have generated a tlb file using regasm and did a #import in the C++ code and am able to call the FireRequest function as defined above from C++. But how should I handle the event fired from the .NET side inside C++ Please help!!!
Thanks,
Abhi
|
|
|
|
|
[mode="frustrated"]
ARGH !
[/mode]
Please, please, if you can help with this,
*please* do so: I'm about to loose my mind on it
Here's the problem:
I'm developing a simple WinForm application.
Among other things, I'd like to set a private boolean flag,
called "shiftPressed" to true when the user is pressing
the Shift key.
This flag is checked when doing other things (such as
clicking on the form) to modify the behavior of the application
as needed.
So, I figured the logical thing to do was to
intercept the KeyDown and the KeyUp events.
In the Key down event, I would set the flag to true
if the Shift key is pressed;
in the KeyUp event I would unset the flag as needed.
However, it seems that if I catch the KeyDown, the KeyUp event is not fired,
and/or vice-versa (and let's not even talk about the KeyPressed event !).
In short, I have
<br />
private void myApp_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)<br />
{<br />
MessageBox.Show("KeyDown");<br />
e.Handled=false;<br />
}<br />
<br />
<br />
private void myApp_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)<br />
{<br />
MessageBox.Show("KeyUp");<br />
}<br />
and I see only "KeyDown" message boxes.
Note that the line
e.handled=false;
can be there or not, but the behavior seems to be always the same.
What can I do?
Do I have to dive into
<br />
public class TestMessageFilter: IMessageFilter<br />
{...}<br />
and
<br />
public bool HandleKeys(Keys keyCode)<br />
{<br />
bool ret = true;<br />
<br />
switch(keyCode) {<br />
case Keys.Shift: ...do stuff...<br />
default: ret = false; break;<br />
}<br />
return ret;<br />
}<br />
???
Thanks in advance,
F.O.R.
|
|
|
|
|
Go it !
Phew* !
I was seeing only KeyDown message boxes because of timing
issues; before that, I was doing a mistake in the code of the KeyUp
handler and the shiftPressed was being set to true when I was de-pressing the
key.
For anyone else who needs this, this seems to work:
<br />
private void myApp_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)<br />
{<br />
if(e.Shift) shiftPressed=true;<br />
e.Handled=false;<br />
}<br />
<br />
<br />
private void myApp_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)<br />
{<br />
shiftPressed=e.Shift;<br />
}<br />
We now return you to the universe next door.
F.O.R.
|
|
|
|
|
I was talking to a VB programmer a few days ago, and got to talking about switch/select statements, and how in VB you can do things like
Case >10
but you can't in C#. Has anyone found a way around this at all? or do you have to fall back on multiple if statements?? or even worse, itemise every possible option that could come through the switch?
Also, am I looking at this the wrong way - if so, what is the proper way to handle these kinds of situations?
|
|
|
|
|
No, I'm afraid you can't do that with C#. The expressions in the case labels must be constant since they're evaluated at compile-time (for speed at run-time).
To do what you want to do, you'd use a structure like
if (firstCondition) {
}
else if (secondCondition) {
}
else {
}
Cheers, Julian
Program Manager, C#
This posting is provided "AS IS" with no warranties, and confers no rights.
|
|
|
|
|
That works if you only have 3 or so conditions, but what happens if you have 30 conditions? How can you allow for so many responses without using a series of if-elseif statements?
This is hypothetical really, but there are some situations where either through bad design, poor experience or even bad luck that you end up needing something like this
|
|
|
|
|
Then you have two choices, I suppose: either write out the 30 or so if-elseif lines, or, you take a step back and consider how to refactor the code into something cleaner. The switch statement won't help you, I'm afraid.
Cheers, Julian
Program Manager, C#
This posting is provided "AS IS" with no warranties, and confers no rights.
|
|
|
|
|
The point is if you're using case >10 <30, case >30, default...then your code won't need many cases and if/else works fine. If you have constants, e.g. some sort of parser then const cases make sense.
|
|
|
|
|
Does anyone know how I create an application to burn CDs in C#?
Thanks
|
|
|
|
|
static main()
{
Process.Start("nero.exe");
}
leppie::AllocCPArticle("Zee blog"); Seen on my Campus BBS: Linux is free...coz no-one wants to pay for it.
|
|
|
|
|
Sorry, but I don't want to start an application that burns CDs. I want to create an application to do this.
|
|
|
|
|
|
Simple way to do this (only on OS>=WinXp) is to use ICDBurn.
(application can copy files to Burn folder and open winxp burning wizard)
i'm only pointer to myself
|
|
|
|
|
With VS 2002 we could send a GET request to a web service and it would work. After upgrading to VS 2003 it doesn't work and doesn't seem to be available. Anyone know what happened?
ed
Regulation is the substitution of error for chance.
|
|
|
|
|
Hi, working with DataGrid on a Windows Form right now. Three questions:
Q1: It seems that Windows Forms DataGrid doesn't support paging as they do on WebForms.
Q2: How can I disable editing on cell(s)/rows belonging to a particular column?
Q3: Any good tutorial on how to embed controls in Windows Form DataGrid? Controls like buttons and other stuff...etc. With WebForms' DataGrid, it's done by <ItemTemplate>. How can we do the same here on Windows Form? With "Checkbox", just feed in a column of type "bool", simple. But with other types? Buttons, links...
Thanks a bunch.
norm
|
|
|
|