|
[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
|
|
|
|
|
Q2: How can I disable editing on cell(s)/rows belonging to a particular column?
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformsdatagridcolumnstyleclassreadonlytopic.asp
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 . 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...
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformsdatagridclasstopic.asp
|
|
|
|
|
Thanks for the tip. I got it working now (enabling/disabling in-place editing). It's very convenient - I still remember way back when I was working with MFC. I need to actually draw an editbox and override a whole bunch of events to get this simple functionality. Glad .NET finally arrives.
But I don't think the second reference on DataGrid provides much information on embedding controls within DataGrid.
norm
|
|
|
|
|
great, as you could fine answer to one of your questions.
i am not a c# expert, actually have just started reading c#, but just trying to find answer of the queries asked here, helps me also in improving my knowledge of c#.
as far as embedding controls within DataGrid, i couldn't find anyway to do it. if you find the answer, please post it here, i would love to know.
|
|
|
|
|
You can show controls in DataGrid, for e.g. showing a button control in a column by adding those controls to the grid.
// Create a control
Button myButton = new Button();
myButton.Visible = false;
// Add the button to the data grid
myDataGrid.Controls.Add(myButton);
// Now handle the Paint event of the grid
OnDataGridPaint(..)
{
if (myDataGrid.CurrentCell.ColumnNumber = <columnnumber>)
{
myButton.width = myDataGrid.GetCurrentCellBounds().Width;
}
}
// CurrentCellChange event
OnDataGridCurrentCellChangeEvent(..)
{
if (myDataGrid.CurrentCell.ColumnNumber = <columnnumber>)
{
myButton.Location = myDataGrid.GetCurrentCellBounds().Location;
myButton.Visible = true;
}
else
{
myButton.Visible = false;
}
}
// Handle Layout and Scroll events of DataGrids
OnDataGridLayout(..)
{
OnDataGridCurrentCellChangeEvent();
}
OnDataGridScrolled(..)
{
OnDataGridCurrentCellChangeEvent();
}
This is just psuedo code. You may have to do some more tweaking for this to work. But this is generally how it is done (or how I have done it!)
Hope this helps.
Suhas
|
|
|
|
|
Thanks Suhas, I think I understand what you're getting at.
norm
|
|
|
|
|
I added assemblies to the GAC. When I want to add a reference, I don't see my assemblies in the .NET tab. I can see them from the Microsoft .NET Framework 1.1 Configuration control panel
--------
"I say no to drugs, but they don't listen."
- Marilyn Manson
|
|
|
|
|
VS.NET doesn't use the GAC for pulling the list of assemblies you can reference. In fact none of the MS compilers allow you to reference an assembly in the GAC, instead the reference is made to files located in a regular directory. For the core assemblies of the CLR that location is %WINDIR%\Microsoft.NET\Framework\%version%\
VS.NET gets its list from some registry keys under
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\7.1\AssemblyFolders (replace 7.1 with 7.0 if running VS.NET 2002)
There is also a similar key under Software\Microsoft\.NETFramework, but I can't remember if VS.NET looks under this key or not.
James
"then when you go to bed...wait, you dont do that do you....ok....when you plug into the 'hive mind' to charge yourself, ill hack into your head"
Nnamdi Onyeyiri over MSN
|
|
|
|
|
I have an application (BizTalk Server 2004, running as Administrator) that accesses custom components, which are referenced in my project (a class library project).
What happens is that my custom class is correctly loaded by the application, which custom class access another assembly. This last assembly loads another assembly using the following code:
Assembly assembly = Assembly.Load(assemblyName);
IComponent result = (IComponent) assembly.CreateInstance(className);
The first line of code works , but the second one throws the exception. Here is the stack trace:
at System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode, IntPtr errorInfo)
at System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode)
at System.EnterpriseServices.Thunk.Proxy.CoCreateObject(Type serverType, Boolean bQuerySCInfo, Boolean& bIsAnotherProcess, String& uri)
at System.EnterpriseServices.ServicedComponentProxyAttribute.CreateInstance(Type serverType)
at System.Runtime.Remoting.Activation.ActivationServices.IsCurrentContextOK(Type serverType, Object[] props, Boolean bNewObj)
at System.RuntimeType.CreateInstanceImpl(Boolean publicOnly)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at System.Reflection.Assembly.CreateInstance(String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at System.Reflection.Assembly.CreateInstance(String typeName)
Tx
Michel
--------
"I say no to drugs, but they don't listen."
- Marilyn Manson
|
|
|
|
|
System.UnauthorizedAccessException is almost thrown, when you try to change a file which is allready in use.
for example:
1. Assembly.Load( test.dll)
2. ... // do something
3. File.Delete(test.dll),while application is still running
--> Exception --> so you need to unload the assembly.
for this you have to use an AppDomain.Unload(...)
but I have the same problem too. so I can't really help you at the moment. use everything like AppDomain.Create, .Load,... maybe you find a solution. I would also need it.
thx
Christian
|
|
|
|
|
I finally found why. The assembly was a ServicedComponent (COM+). I was trying to load an assembly that had the same print as in COM+. This is now fixed.
Still have a problem to fix (SerializationException) but I'm on my way for this one.
--------
"I say no to drugs, but they don't listen."
- Marilyn Manson
|
|
|
|
|
Hi, I need to implement my own MouseHover event for a library I'm working on.
What is the exact logic of the MouseHover event? I can't find this on MSDN...
It seems like the MouseHover is fired only after the first N milliseconds that the mouse is idle in a control, and perhaps only if the control has focus. I expect I'd set a Timer when the MouseMove event is fired, and then invalidate the Timer if the MouseMove event was fired before N milliseconds had elapsed.
|
|
|
|
|