|
.NET offers this event[^]. If that isn't available on CF, your best bet might be to provide an AddControl() method which does whatever you want it to do; the disadvantages would be: Controls.Add() remains available, and Visual Designer would not call your method.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
I am using two list boxes and some buttons...
i am trying to shift the items from list 1 to list 2, vice - versa.
while i try to attempt to move names from from one list to another it should accept the same names(i.e, duplicate names should not be accepted)
can any one please help me...
|
|
|
|
|
You just need to check whether the name you are trying to move exists in the ListBox you are trying to move it to. I would keep 2 List<item> 's in memory and bind these to the ListBoxes and Add or Remove from the List<item> and rebind as necessary.
...and I have extensive experience writing computer code, including OIC, BTW, BRB, IMHO, LMAO, ROFL, TTYL.....
|
|
|
|
|
if (!list2.Contains(list1.selectedName))
{
list2.Add(selectedName);
}
- Regards - J O N
A good thing is a bad thing if it keeps you from the best thing. - Dr. Adrian Rogers
|
|
|
|
|
|
The previous solution can be slow if the lists are long. Inserting the names into a hash table will eliminate duplicates and run much faster if there are many names.
|
|
|
|
|
|
I have been trying to write the clipboard content to an external windows application (currently running process) from a C#(WPF) application using SendMessage API and WM_PASTE . Can't get it work. Here is the sample code
public const int WM_PASTE = 0x0302;
[DllImport("User32.dll")]
public static extern Int32 FindWindow(String lpClassName,String lpWindowName);
[DllImport("user32.dll", CharSet=CharSet.Auto)]
public static extern int SendMessage(int hWnd, int msg, int wParam, IntPtr lParam);
private void btn_Click(object sender, System.EventArgs e)
{
int hwnd=0;
hwnd = FindWindow(null, "Untitled - Notepad");
if (hwnd != 0)
{
Clipboard.SetText("sample text from clipboard");
hwnd = FindWindow(null, "Untitled - Notepad");
SendMessage(hwnd, WM_PASTE, 0, IntPtr.Zero);
}
}
Note: have to Notepad app opened to test the code
tried some other possible combinations
SendMessage, WM_PASTE<br />
SendMessage, WM_CHAR<br />
PostMessage, WM_PASTE<br />
PostMessage, WM_CHAR
An alternate way to send keystrokes to an extern app using SendMessage and PostMessage
SendMessage, (WM_KEYDOWN, WM_KEYUP) For CTRL+V<br />
PostMessage, (WM_KEYDOWN, WM_KEYUP) For CTRL+V
Windows.System.Forms.SendKeys.SendWait("^V") -> works but not always
any idea?
- Regards - J O N
A good thing is a bad thing if it keeps you from the best thing. - Dr. Adrian Rogers
modified on Wednesday, April 20, 2011 6:17 AM
|
|
|
|
|
alright, getting the child window of the notepad application works which is the edit control.
we can do a PASTE only in the edit panel of the notepad application. modified code below...
GetWindow_Cmd.GW_CHILD = 5
int hwnd=0;
int hwndChild=0;
hwnd = FindWindow(null, "Untitled - Notepad");
if (hwnd != 0)
{
Clipboard.SetText("sample text from clipboard");
hwnd = FindWindow(null, "Untitled - Notepad");
hwndChild = GetWindow(hwnd, GetWindow_Cmd.GW_CHILD);
SendMessage(hwndChild , WM_PASTE, 0, IntPtr.Zero);
}
now, how do i find the window handle of the static edit control of "winword" and "mspaint" application
same approach doesn't work...
any idea?
- Regards - J O N
A good thing is a bad thing if it keeps you from the best thing. - Dr. Adrian Rogers
|
|
|
|
|
-
ok, i think, using WM_PASTE to paste the contents into word or paint is somewhat complex.
not able to find a way to get the handle of the edit panel.
a simple solution is adopted and it works
Win32.SendMessage(hWnd, Win32.WM_SYSCOMMAND, (IntPtr)Win32.SC_RESTORE, IntPtr.Zero);
Win32.SetForegroundWindow(hWnd);
System.Threading.Thread.Sleep(100);
System.Windows.Forms.SendKeys.SendWait("^v");
- Regards - J O N
A good thing is a bad thing if it keeps you from the best thing. - Dr. Adrian Rogers
|
|
|
|
|
I'm a student and I'm doing my thesis. I'm using ACOS3 1.07.18, according to it's manual book, the 18 is mean that the card can contain 24KB of data. I want to ask you how to use all of that 24KB?
I have formatted it, first I'm trying to format it using 94 files, but I got a problem in record number 31 (record number starts from 0), the card return code that the address could not be found. I read the manual once more, I found that in the personalizetion stage I only can make 31 files.
I formatted the card using 31 files (record number 0 - 30) with 254 Bytes record length in each. That's mean I only can use 31 x 254 Bytes = 7.874 Bytes.
Please help me what should I do to use that 24 KB?
Thanks before.
modified on Wednesday, April 20, 2011 3:22 AM
|
|
|
|
|
Firstly: Never post your email address in any forum, unless you really like spam! If anyone replies to you, you will receive an email to let you know. Edit your message and remove it.
Secondly: What does this have to do with C#? AFAIK, neither .NET nor Mono run on smart cards...
Contact the manufacturers - their technical support should be able to help you!
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Manfred R. Bihy: "Looks as if OP is learning resistant."
|
|
|
|
|
OK, I'm sorry for that mistake and thanks to OriginalGriff for replying my post. I mean, my programming language is C#, and I have to write some data to the smart card. But I have a problem with the smart card as I wrote before. I hope someone who have ever used a smart card could help me.
|
|
|
|
|
It's cool!
I would strongly suggest that the manufacturers will have a better idea than anyone here: it may be a feature specific to that smart card, and no other.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Manfred R. Bihy: "Looks as if OP is learning resistant."
|
|
|
|
|
Yes I hope so, they haven't reply my message yet. I'm confuse, so I try to post here, who knows someone in here can help me.
Thanks for your suggestion...
|
|
|
|
|
I have a class:
public class SomeClass<t> : ISomeInterfaceBase
{
.
.
public delegate void MessageHandler(object sender, T message);
public event MessageHandler Handler
{
}
.
.
}
so its a generic class and has a delegate that uses the T type as a param. I thought that was a good idea so users don't have to cast to their T type.
But an issue arose:
MainWindow -> subscribes to the event
MainWindow pops up Window1
Window1 -> subscribes to the event too
Window1 closes (and doesn't unsubscribe)
Now when the event triggers, it still calls the one in Window1 too.
So I figured I'd use weak references.
public event MessageHandler Handler
{
add
{
lock (_lstHandlers)
{
foreach (WeakReference weakRef in _lstHandlers)
{
if ((MessageHandler)(weakRef.Target) == value)
return;
}
_lstHandlers.Add(new WeakReference(value));
}
}
when the event needs to be triggered, I loop through _lstHandlers and check if isAlive = true and then send it, otherwise, I remove that event.
Problem is, isAlive never goes false when I close window1.
I looked into WeakEventManager, but that doesn't seem like it will jive with a generic delegate. Seems like you need to have a WeakEventManager for every generic type thats created?
|
|
|
|
|
You can't rely on the Garbage Collector to play along like that - it could decide to collect those delegates at any point in time since they were not referred to anymore, possibly infinitely long into the future.
Window1 should unsubscribe before closing (in the OnClosing event, for example?)
|
|
|
|
|
Yeah, Window1 *should* unsub... but sometimes people don't. Sure they are being lazy and its really a "bug", but the intention is to protect against that.
|
|
|
|
|
Ooh so it's out of your control, well that changes matters..
I don't see any solutions then, except a couple of really really dirty things.
You can, with reflection, extract the Target Object from a delegate object. You can then check whether it is a Window1 and whether it has closed yet.
You could also try to subscribe to the OnClosing of Window1 (through that Target Object) and when it's triggered delete all delegates which have Window1 as Target Object.
|
|
|
|
|
SledgeHammer01 wrote: I looked into WeakEventManager, but that doesn't seem like it will jive with a
generic delegate. Seems like you need to have a WeakEventManager for every
generic type thats created?
Sounds like you need to roll your own generic weak event manager class - could be an interesting and useful excercise!
|
|
|
|
|
Before I waste time going down this road, is that going to solve the original issue (of Window1 closing and still having a listener)? It would seem that wrapping a delegate in a WeakReference should theoretically have the same effect, no?
I'm not really liking WeakEventManager to be honest with you. Seems like everybody has to implement the IWeakEventListener interface.
I'm just really curious why my previous idea didn't work... of storing the WeakReferences myself???
|
|
|
|
|
I'm not sure to be honest whether it will solve your problem. Every weak reference solution seems to have pros and cons. The event model employed by .NET is flawed in this regard and relies on consumers unsubscribing correctly.
Another option maybe to forget about events in the normal way and go back to generating old fashioned windows messages or something similar so interested parties can override WndProc and catch the event there - no direct subscription... Maybe not practical or possible in your situation, certainly not as elegant as events, but worth a thought?
|
|
|
|
|
Hmm...
I found a lightweight solution (a WeakDelegate<t> class and a WeakEvent<t> class that work together). Seems like it will work how I want.
They store a weak ref to the owner class and use dynamic invoke to execute the method. So they can tell when the owner class is dead.
The dynamic invoke is probably a bit slow though... I might look into switching that to something faster.
http://tomlev2.wordpress.com/2010/05/17/c-a-simple-implementation-of-the-weakevent-pattern/[^]
|
|
|
|
|
You may still execute the event in the time between the closing of the window and the GC destroying it though
|
|
|
|
|
For an item of hardware I have written a Shared library to make it easy to use the API for this hardware. The library sets up data structures and handles, buffers etc for simple program use.
For example to arrange data to be transmitted I call routings like:-
UINT16 TransmitData( UINT unit, UINT addr, TXBUFFER * tx_buffer );
However in VS2008 I used C++ in a MFC dialog application, which all worked well.
Having moved to VS2010, I now see that the intellisence does not work with this product.
So my thoughts were to use C# for the Windows forms and link in the Shared Library.
I have built the Shared Library in VS2010 so I need to understand how to access these function in a C# program. Is this using ‘Wrappers’ and how does the libraries API001.LIB and API001.h files link in?
For a C++ MFC program I included the headers and LIB files with the PATH set up for the DLL’s.
The libray is built using C.
Many thanks,
Andy
|
|
|
|
|