|
Hi,
I want to use Keypress event in my windows form. When user press enter that time i want to catch that event. and how to use the keypress event because in visual c# i never seen ASCII keys. Tell me how to catch keypress event and use ASCII values for trap the key which is press by the user.
Thank You for Help,
(Hemant Uttam Mane)
|
|
|
|
|
Web or Win Form?
There are some events and properties in WinForm to see keyboard: KeyPreview, KeyPress, KeyDown etc. See EventArgs and KeyData, KeyChar, KeyCode properties.
Hi,
AW
|
|
|
|
|
There's many ways of doing this. If you want to catch these in your derivative class, override OnKeyDown . External to your class, handle the KeyDown event. This is to catch and potentially "handle" the key without it being passed to the target window. If you don't care about stopping it from being dispatched, you can handle either KeyPress or KeyUp .
In there, you actually use the KeyEventArgs - not the EventArgs like the other response mentioned - to get the Keys enumeration member for pressed keys, or just the ASCII character value itself. See the documentation for the KeyEventArgs members for more details.
If you want to catch keys throughout your application (say, for configurable hot keys), implement the IMessageFilter class and add your implementing using Application.AddMessageFilter . You get a Message structure that contains the message (such as WM_KEYDOWN ) and you can get the data from the WParam and LParam properties. You can also return true to signal that you've handled it and the message should not be dispatched.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
i am using visual studio to make some histogram graphs and pie graphs of standered divation but the programme does not recognize the graphics.h header file. how should i make the graphs and please tell what should i do to this heard file (graphics)
help me in graphics
|
|
|
|
|
This is C# forum not C forum. Post this in VC++ forum.
Mazy
"One who dives deep gets the pearls,the burning desire for realization brings the goal nearer." - Babuji
|
|
|
|
|
C# doesn't use header files. You'll have to rewrite the C++ constants, structures, function headers, whatever your trying to use in the header file, into C# code.
RageInTheMachine9532
|
|
|
|
|
I want to use a variable (or constant) in following class property:
[EventTrackingEnabled(true),ObjectPooling(true,1,50)]
public class Aktualizacje : ServicedComponent
{...
instead of number 50 in many classes in many projects of one solution. Is it possible? Thx in adv
Hi,
AW
|
|
|
|
|
You can declare constants and use those in your attributes, but not variables. Since attributes are metadata, the values must be defined at compile-time, not at runtime.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Just overload the constructor, very handy with attributes. Remember attributes are readonly because they are stored in metadata, and hence, can be changed at runtime.
|
|
|
|
|
|
Hi friends
I have a problem. I have a login form in visual C# in which user must enter username amd password and then click login. If username or password is blank then one messegebox display that "Please enter username and password". After that i want to exit that sub. In Visual besic .Net there is command "EXIT SUB". In visual C# there is a static method call Application.exit but it is for close the whole application but i want only to exit the event and application should not be close.
Please reply me as early as possible
Thank you.
(Hemant Uttam Mane) 
|
|
|
|
|
Application.Exit() static method. See help
Hi,
AW
|
|
|
|
|
He said he didn't want to call that and exit the whole application.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
|
normally you can exit a sub (in C# it's called method) with return....like this:
public void Login()
{
return;
}
|
|
|
|
|
Hi,
I have a structure declared with bit fields in one of the C++ dll I am calling in my c# application. How can I change it to C# type struct?
typedef unsigned int UINT32;
typedef struct DEV_TYPE
{
UINT32 ReadCdR :1;
UINT32 ReadCdRw :1;
UINT32 ReadDvdRom :1;
UINT32 ReadDvdRam :1;
UINT32 ReadDvdMinusR :1;
UINT32 ReadDvdMinusRw :1;
UINT32 ReadDvdPlusR :1;
UINT32 ReadDvdPlusRw :1;
UINT32 WriteCdR :1;
UINT32 WriteCdRw :1;
UINT32 Reserved0 :1;
UINT32 WriteDvdRam :1;
UINT32 WriteDvdMinusR :1;
UINT32 WriteDvdMinusRw:1;
UINT32 WriteDvdPlusR :1;
UINT32 WriteDvdPlusRw :1;
UINT32 TapeDrive :1;
UINT32 Reserved :15;
} DEV_TYPE;
I have read in MSDN that C# does not support bit fields. Is there any method to implement this structure in C#? Pls help..
Thanks
Vini
|
|
|
|
|
Use BitArray(sealed) or BitVector32 or try to create new class using uint and next define set/get properties:
private uint a=0;
public uint A
{
set { A=value; }
get { return a; }
}
public uint A0
{
set { a &= 0xFEU; if(value>0) a+=0x1U; }
get { return a & 0x01U; }
}
...
Hi,
AW
|
|
|
|
|
I got it with BitVector32 BitVector32.CreateSection Method and get/set methods.
Thanks
Vini
|
|
|
|
|
Hi Vini,
I am also having the same problem using bit fields in C#. Is it possible for you to post ur sample code?
Thanks,
- Prerna
|
|
|
|
|
Your C# code could just pass/receive a uint from the .dll. Just use the bitwise operators in C# to set up or read the various bits.
You'd have to define your bits differently and wouldn't really use a 'bit field' but you'd get the same effect of storing several bools in a single 32 bit variable.
i.e.
C++:
const UINT32 ReadCdR = 0x00000001;
const UINT32 ReadCdRw = 0x00000002;
const UINT32 ReadDvdRom = 0x00000004;
...
const UINT32 TapeDrive = 0x0000FFFF;
bool DoSomething(UINT32 devType)
{
if (devType & ReadCdR)
...
}
C#:
private static uint ReadCdR = 0x00000001;
private static uint ReadCdRw = 0x00000002;
private static uint ReadDvdRom = 0x00000004;
...
private static uint TapeDrive = 0x0000FFFF;
public static CallSomethingInDll()
{
uint val = ReadCdR | ReadCdRw | TapeDrive;
bool ret = CPPWrapperOrManagedClass.DoSomething(val);
}
|
|
|
|
|
C# has constants too
Hi,
AW
|
|
|
|
|
O lord, another programmer trying to be clever without knowing how to use bit masks (not you). This is what it should look like both sides...
[Flags]
enum DEV_TYPE
{
ReadCdR =1 << 0,
ReadCdRw =1 << 1,
ReadDvdRom =1 << 2,
ReadDvdRam =1 << 3,
ReadDvdMinusR =1 << 4,
ReadDvdMinusRw =1 << 5,
ReadDvdPlusR =1 << 6,
ReadDvdPlusRw =1 << 7,
WriteCdR =1 << 8,
WriteCdRw =1 << 9,
WriteDvdRam =1 << 11,
WriteDvdMinusR =1 << 12,
WriteDvdMinusRw=1 << 13,
WriteDvdPlusR =1 << 14,
WriteDvdPlusRw =1 << 15,
TapeDrive =1 << 16,
}
|
|
|
|
|
Has anyone experimented with using structs or classes in C# to carry data rather than strongly typed Datasets in a Webservice environment?
VS.NET makes it as difficult as possible to pass classes and strongly-typed ArrayLists of classes in and out of Webservices and as easy as possible to use Datasets with Webservices and with MSSQL.
Nevertheless, profiling a recent project that used strongly typed Datasets showed that there is a massive run-time cost to using them (lot of meta data around and many Events being fired) which led us on to thinking about using good old structs.
We have successfully passed 'property only' classes in and out of Webservices (including classes that include other classes and arrays and ArrayLists of classes) and bound strongly typed ArrayLists to DataGrids and we can use a property by property approach together with stored procedures to get data in and out of an MSSQL database. The code we have produced could be 'templated' (generics will be wonderful) meaning that, in theory, we could stop using strongly-typed datasets.
On the other hand - who wants to reinvent the wheel if MS have done all the work for us in creating Datasets?
Has anyone else agonised over this decision and, if so, what conclusion did you come to?
Thanks
Bernard Yardley
|
|
|
|
|
It's not VS.NET that's causing the problem, it's your implementation of how it defines the WSDL for the Web Service. Even generic DataSet will produce a generic declaration in WSDL. And there is not such thing as a typed ArrayList - it works only with object s, unless you've extended it and declared typed parameters.
Structs, classes, DataSet s, whatever work well so long as they can be serialized correctly / the way you want. By default, Web Services use XML Serialization attributes or simply uses the public properties (not fields, and this is documented) and their names. See XML and SOAP Serialization[^] in the .NET Framework SDK for more information.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Sorry - my reference to a strongly-typed ArrayList was 'lazy' English. What we actually did was create a class named MyClassList that implemented IList (to give bindability to a DataGrid) and had a private ArrayList member. It then implemented all the Methods of IList by passing them on to the ArrayList except that this[]{get()} and Add() were both typed rather than returning/accepting object s.
Our problem with WebServices was that the proxy class that VS.NET builds contained its own declarations of the data classes, so you ended up with MyNamespace.MyClass and localhost.Webservice.MyClass so Method signatures didn't match and the code wouldn't compile. The solution seemed to be simply to go into the file that VS.NET built and delete the lines that declared MyClass - then everything compiled and ran fine. Are you saying that a tweak to the way VS.NET calls WSDL would solve this problem?
My real interest, though, is whether anybody else is attempting this or just sticking to using strongly-typed Datasets to do everything?
Thanks
Bernard
|
|
|
|