|
Programm3r wrote: So, my question: how can I develop / alter the event(s) (which runs on a separate thread that the main) to not make use of the above technique, and still be able to send / set data to the GUI controls?
If you have to set values to controls that are created by a separate thread, you need techniques like SynchronozationContext , Invoke/BeginInvoke.
BTW, why do you want to do this?
|
|
|
|
|
Thanks for the response Navaneeth.
N a v a n e e t h wrote: BTW, why do you want to do this?
Because, I want to be able to give the user visual confirmation of the following:
New TCP/IP clients that has connectedNew TCP/IP data that has arrivedInform the user when a client has disconnectedUnless you have other suggestions on how this could be achieved?
Thanks again.
Kind regards,
The only programmers that are better C# programmers, are those who look like this -> |
Programm3r
My Blog: ^_^
|
|
|
|
|
hi,
need your help to solve this issue..
i have a custom pictureedit control in which i have many custom properties and events. i need to place an image OVER this in another ordinary picture edit and should be able to work on the events in the picture edit in the lower layer.
i'll make it clearer...
in my custom pictureedit i have added a feature to measure the distance between 2 points. now what i need to do is place another image over the main image and while comparing these images should be able to take the measurements from the lower image...
hope you guys understood my issue clearly...
tons of thanks in advance for any help
|
|
|
|
|
I'm not sure I understood correctly. You have 2 controls, one on top of the other, the covered one is a custom control (you wrote it?) and you want mouse events, I suppose, to pass through to the covered control?
If it's your custom control (you have its code) then you can add methods you can call from the top control mouse event handlers then you make those metods call OnMouse.. methods, raise the events or do what you want to do directly in them. If you don't have the code, I think you can send the appropriate message(s) to the covered control using SendMessage[^].
Eslam Afifi
|
|
|
|
|
Thanks eslam...
i tried using the sendmessage function.. but till now i've not been able to implement it successfully..
so can you help me in this...
actually i make the measurement by dragging through the custom pictureedit(i dont have the source code) which is below the covering control
i tried sending the WM_MOUSEMOVE alone & WM_LBUTTONDOWN & MOUSEMOVE together but nothing much happened...
[DllImport("user32.dll")]
static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern int SendMessage(IntPtr hWnd, int wMsg, IntPtr wParam, IntPtr lParam);
private const int WM_MOUSEMOVE = 0x200;
private const int WM_LBUTTONDOWN = 0x201;
private void button2_Click(object sender, EventArgs e)
{
SendMessage(axe.Handle, WM_LBUTTONDOWN, IntPtr.Zero, IntPtr.Zero);
SendMessage(axe.Handle, WM_MOUSEMOVE, IntPtr.Zero, IntPtr.Zero);
}
once again thanks for showing the light..
hope you woulld be able to lead me further
thanks
|
|
|
|
|
What you need is to send a mouse button down message when the mouse is down, mouse move when the mouse is moving and mouse up when the mouse is up. You can experiment to be sure of the message sequence when dragging happens by creating a dummy custom control (or form) with some code similar to the following and figure out the proper message sequence that is generated when you do dragging with it.
protected override void WndProc(ref Message m)
{
Debug.WriteLine(m.ToString());
base.WndProc(ref m);
}
Use this list[^] to facilate analyzing the messages.
Then you can send the appropriate message(s) in the proper event.
By the way, don't send messages with lParam and wParam as IntPtr.Zero since they are supposed to hold modifier keys and mouse coordinates, which you need to make the covered control calculate the distance, otherzise it would calculate zero or some other wrong value since you're notifying it that is the mouse is currently at position (0, 0). See the msdn documentation of WM_LBUTTONDown... to know what to pass to lParam and wParam.
Eslam Afifi
|
|
|
|
|
once again thanks eslam.
i'm still fighting with this.
pls see the log that i got ...
msg=0x201 (WM_LBUTTONDOWN) hwnd=0xb046e wparam=0x0 lparam=0x4b0266 result=0x0
msg=0x7 (WM_SETFOCUS) hwnd=0xb046e wparam=0xd04a4 lparam=0x0 result=0x0
msg=0x8 (WM_KILLFOCUS) hwnd=0xb046e wparam=0x7a045c lparam=0x0 result=0x0
msg=0x111 (WM_COMMAND) hwnd=0xb046e wparam=0x100045c lparam=0x7a045c result=0x0
msg=0xc206 hwnd=0xb046e wparam=0x0 lparam=0x0 result=0x0
msg=0x200 (WM_MOUSEMOVE) hwnd=0xb046e wparam=0x1 lparam=0xffffffffff5d0230 result=0x0
msg=0x2a1 (WM_MOUSEHOVER) hwnd=0xb046e wparam=0x1 lparam=0xffffffffff5d0230 result=0x0
msg=0x202 (WM_LBUTTONUP) hwnd=0xb046e wparam=0x0 lparam=0xffffffffff5d0230 result=0x0
msg=0x215 (WM_CAPTURECHANGED) hwnd=0xb046e wparam=0x0 lparam=0x0 result=0x0
msg=0x2a3 (WM_MOUSELEAVE) hwnd=0xb046e wparam=0x0 lparam=0x0 result=0x0
msg=0x111 (WM_COMMAND) hwnd=0xb046e wparam=0x200045c lparam=0x7a045c result=0x0
but nothing special happened...
no event in the message receiving control was fired..
am I missing anything ?
pls help me on this
thanks
|
|
|
|
|
jamesjk wrote: but nothing special happened...
no event in the message receiving control was fired..
am I missing anything ?
The code was not to fire the events. It was to help you find the right message sequence and the lParam and wParam values to pass (read msdn documentation of those messages to find out the correct values to pass). You send the messages using SendMessage.
So I guess the sequence would be sending,
WM_LBUTTONDOWN in mousedown event
WM_MOUSEMOVE in mousemove
WM_MOUSEHOVER in mousehover (just in case the covered control uses it for something, i don't know. the same applies to WM_MOUSELEAVE)
WM_LBUTTONUP in mouseup
I don't know anything about WM_COMMAND nor 0xc206 (I couldn't find anything about it, maybe it's an undocumented message, i don't know). I think you shouldn't use WM_SETFOCUS and WM_KILLFOCUS. WM_CAPTURECHANGED, i don't know, maybe you should send it right after WM_MOUSEUP in mouseup event.
P.S. I've never tried to simulate something like dragging before but I did try sending simple messages before. I don't know much so you should experiment more. And study sequences generated from cases like mousedown, move, leave the control, re-enter the control, move, mouse up... (cases like that) to ensure you get the desired result in both normal cases and extreme cases. And you're welcome.
Eslam Afifi
|
|
|
|
|
Perhaps you could explain again in an other way. It is not clear if you are using 2 controls (one top of other) or are you using 2 images?
|
|
|
|
|
thanks for the reply..
i'll put the problem in another way
i have 2 controls 1. a customized pictureedit 2. a custom picturebox which is transparent
in the customized pictureedit i can measure the distance between 2 points by dragging the mouse from one point to another.
in my form i place the second control exactly over the first one
i load an image in the first control(in which i can take the measurements) that is underneath
then i load different images in the upper transparent picturebox so that i can see both the images overlapping each other..
so far it works fine...
now comes the tricky stuff
i should be able to drag through the upper transparent control and take the difference in measurements between the 2 images. i can't keep the measurable pictureedit on the top as per the requirements.
so what i need to do is drag on the upper transparent picturebox but get measurements as if i dragged on the lower pictureedit.
i hope i have made it clearer this time
once again thanks for the help
|
|
|
|
|
thanks for the reply..
i'll put the problem in another way
i have 2 controls 1. a customized pictureedit 2. a custom picturebox which is transparent
in the customized pictureedit i can measure the distance between 2 points by dragging the mouse from one point to another.
in my form i place the second control exactly over the first one
i load an image in the first control(in which i can take the measurements) that is underneath
then i load different images in the upper transparent picturebox so that i can see both the images overlapping each other..
so far it works fine...
now comes the tricky stuff
i should be able to drag through the upper transparent control and take the difference in measurements between the 2 images. i can't keep the measurable pictureedit on the top as per the requirements.
so what i need to do is drag on the upper transparent picturebox but get measurements as if i dragged on the lower pictureedit.
i hope i have made it clearer this time
once again thanks for the help
|
|
|
|
|
I m trying to add reference of pcrsrv32.dll in c#.NET project(adding reference) but it results error that is
" pcrsrv32.dll can not be added to project make sure its valid assembly or com component"
Plzz help
|
|
|
|
|
I guess pcrsrv32.dll is a native dll. You can add reference to managed assemblies (.net assemblies) but not unmanaged ones. Use DllImport[^] to call unmanaged code.
Eslam Afifi
|
|
|
|
|
Hi all !
i have opened the notepad using the the code as bellow:
System.Diagnostics.ProcessStartInfo obj = new System.Diagnostics.ProcessStartInfo();
obj.FileName = "C:\\Test.txt"
System.Diagnostics.Process objprocess = new System.Diagnostics.Process();
objprocess.StartInfo = obj;
objprocess.Start();
Is it possible to identify whether the notepad(process) is opened through the above code or manually by the user.
I am using WMI(Win32_ProcessStopTrace of Win32ProcessStartTrace)
Pls can some one help me.
thanks in advance
Regards
.....Jack
|
|
|
|
|
I guess you could get the process ID from objprocess? If you loop through all processes running, the one with the ID equal to that of objprocess is the one created by code.
[EDIT]mmm, sorry didn't see the WMI bit, I'm not sure if you can do it then unless you store the info from code somewhere and let WMI look for it there.[/EDIT]
|
|
|
|
|
Thanks for the suggestion.
Now i am storing the information already as you said.But i feel that is not correct. That's fine when u come across any technique then let me know it.
thanks
Regards
.....Jack
|
|
|
|
|
Hi,
I want to save the last entered data for the fields like file name and location,output directory path in C# windows application.when the application exits it should save the last entered values, and load them again on the next application load.
Please do the needful.Thanks in advance
With Regards
Mahesh
|
|
|
|
|
You need handle the form closing event and save the required information. What problem are you facing in this?
|
|
|
|
|
Hi,
Where to save the required information ? Is it a file ?
And how to retrieve back when the application reload or Application start.
I'm not clear about your answer please provide some example
With Regards
Mahesh
|
|
|
|
|
his answer in a nutshell is, 'this is really trival, here's how it's done, why do you need to ask about this, where are you stuck'
In other words, he's asking you to show that you've done SOMETHING apart from asking us to do your job for you.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Hi,
I have save the reqiered information into text file.
Ex:1.Input file name and Path
2.Output folder path
this two information from the browse button.For first time application runs
this information are added through browse button and i have save same imformation into text file.
When the application start from next time i am reading from the file putting the currect information into respective browse button using user defined function and calling that function in the constuctor.
But the problem is i'm not able to load the application itself.
please help me.
With regards
Mahesh
|
|
|
|
|
This article [^]may help!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hi!
Are you looking for the "official" C# way of saving program settings?
I know that it's different under .NET and with C# than the stupid method that Microsoft suggested before with Visual Studio 6 (before .NET) - put *EVERYTHING* in the registry!
I'm using the method below to store my program settings in my C# programs.
Windows Forms User Settings in C#[^]
From the books that I read, the above is the suggested method.
There are good/bad points with that method. *I* like storing a ".dat" file in the program directory. But, as I understand, with ***** Vista, and maybe with Windows 7, a user may not always be able to store a file in the programs directory (even if it's on the hard drive and a single user system). So, that's why the users application data area is used.
I use the above method to store the COM port number, program settings, user preferences, and so on. It may not be the best or fastest way. But, it works. And, it conforms to the accepted and suggested C#/.NET methods for storing/retrieving program data. So, if/when someone else looks at my code, it's not something unique or different than what's commonly done.
Good Luck!
________
Joe
|
|
|
|
|
2 ways to solution the problem
first one:
1)in your 'solution explore',choose 'properties'->'settings.settings' and double click to open it.
2)in the form of 'settings.settings', u can create parameters whitch you used to save data.
ps:for example: create a parameter named "filename" typed String.
3)using that parameter such as this code
Properties.Settings.Default.filename = &"c:\a.avi"
second one:
create a config file in local disk and save data to the config file.Then u can load the data for application from the config file when your application load.
good luck!
wjp_auhtm
|
|
|
|
|
Thank you very much.
I will go for second option. That's the exact requirement for me.
Even i'm new to .net application.And i have not done config file creation and how to use. I will try that if any problem comes i required your help
Once again thanks your answer.It's help me thank.
With Regard
Mahesh
|
|
|
|