|
You can always pass the reference to the parent object and call methods of it. The reference is just like pointers in c++.
Live Life King Size
Alomgir Miah
|
|
|
|
|
You could just pass the form to the class during instantiation using 'this' keyword. For example, assume your form is called MyForm and has a function called MyFormFunction that you want to call from MyClass:
during instantiation in MyForm:
MyClass newClass = new MyClass(this);
in MyClass:
private MyForm _externalForm; //declare as class level private variable
//ctor
public MyClass(MyForm passedFormReference)
{
_externalForm = passedFormReference;
}
public MyFormFunction()
{
_externalForm.MyFormFunction();
}
Hope this helps,
Regards,
-----
Josh Lindenmuth
jlindenmuth at paycepayroll dot com
Payce Payroll - Smart for Business
|
|
|
|
|
I am designing a function that requires an asynchronous call to be made to a remote device and the reception of some data from that device. Once the data is acquired the function can return its result.
Currently the function initiates the call and terminates, waiting for a communications event to signal that the data has been received.
How do I make the function wait until the event returns the value (or times out at which time I return an error) before it terminates and returns its value?
Thanks
Chris
|
|
|
|
|
if i understood you correctly you want the caller of the function wait untile its recive the signal or timeout
if this is correct So
The IAsyncResult interface returned from BeginInvoke ( ) has the AsyncWaitHandle property which have some overloaded WaitOne method
One of the take Timespan parameter you can use it to pass
Timeout value
IAsyncResult asyncResult = yourDelegate.BeginInvoke(param1,param2,null,null);
asyncResult.AsyncWaitHandle.WaitOne(timeoutValue,false);
int result;
result = yourDelegate.EndInvoke(asyncResult);
WaitHandle.WaitOne Method[^]
MCAD
-- modified at 19:36 Monday 29th August, 2005
|
|
|
|
|
Thanks for your response....Just so that you understand this fully:
My function has a method that just opens the comms port and dials out the number of the remote device. At that point exeution of the method terminates. At the same time in the function's class constructor I subscribe to the OnComm event (which fires whenever communications events happen, such as when receiving data). When I receive data, I parse it in the event handler of the OnComm event and if valid I fire an event with the data as its argument.
What I am looking to do is have the original method initiating the call wait until this valid data event is fired, or a timeout occurs. Once either of these happens I would like the function to return the data or an error code accordingly.
Thanks
Chris
|
|
|
|
|
Just adding to the previous response
//Client Code
AsyncCallback callback = new AsyncCallback(MyCallback);
MyBeginMethod(param1, param2,..., callback, null);
private void MyCallback(IAsyncResult result)
{
MyRetType obj = EndMyMethod(result);
//Some stuff
}
//Server Code
public MyRetType MyMethod(string param1, string param2, ... )
{
//your logic
}
public IAsyncResult BeginMyMethod(string param1, string param2, ..., AsyncCallback ac, Object state)
{
MyDelegate d = new MyDelegateMyMethod);
IAsyncResult result = d.BeginInvoke(string param1, string param2, ..., ac, null);
return result;
}
public static MyRetType EndMyMethod(IAsyncResult result)
{
MyDelegate d = (MyDelegate)((AsyncResult)result).AsyncDelegate;
return d.EndInvoke(result);
}
Live Life King Size
Alomgir Miah
|
|
|
|
|
I am working on the extraction of the frames from the AVI Movie.As i want to grab each and every frame from the AVI movie and perform some processing on them.I have done it in Visual C++ using AVI Library there.But i can't find the same library there.So i want to know how it can be done.Moreover the library(if any) in C# which will be used to handle AVI can be used to handle MP3 format.
|
|
|
|
|
|
Hello
You can try to interop Video for Windows for this task. Look at my "Motion detection algorithms" for sample. Or you can try to work with DirectShow (which is able to play MP3s too). A small sample for the second approach you can find in that article too or other article here on CP.
With best regards,
Andrew
|
|
|
|
|
I am currently working on a number plate recognition project.My sotware is finding the plates from the images.Now in next task i want to grab the number plate and increase its size if its width and height is less then the certain threshold for better pixel information.In Visual C++ there is a function StretchBlt which serves the purpose but in CSharp i cannot find the way to Stretch(Increase Size)image.I have resized the image and displayed it on the screen.But i want to save to resize it and store it into Bitmap object at the backend.
|
|
|
|
|
<br />
using System.Drawing;<br />
using System.Drawing.Imaging;<br />
using System.Drawing.Drawing2D;<br />
<br />
<br />
void ResizeBitmap(Bitmap org, string filename, int width, int height)<br />
{<br />
Bitmap newBmp = new Bitmap(width, height);<br />
using (Graphics g = Graphics.FromImage(newBmp))<br />
{<br />
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.DrawImage(org, 0, 0, width, height);<br />
}<br />
<br />
newBmp.Save(filename, ImageFormat.Bmp);<br />
newBmp.Dispose();<br />
<br />
}<br />
|
|
|
|
|
Hello,
I have a situation that I have not been able to solve, maybe one of you can point me in a direction to pursue.
I have a Windows Form application that utilizies a RichTextBox to view the contents of a file. Some of the file have very lnog lines in them that initially need to be displayed for various reasons. For example, the first line may be 9,000 characters before its crlf is encountered.
The behavoir I'm getting in the RichTextBox is that it chops this line up on the display, so maybe at character 3,00o it wraps the line, then again at 2,800, then finally displays the remaining chunck of characters. So, I get the line displayed on 3 lines, although the line count is 1. If I open the file up in say Visual Studio or TextPad, it displays the contents all in 1 line, like I need it to.
I have set WordWrap to false.
Any ideas would be appreciated.
Thanks in advance.
|
|
|
|
|
Using the code from the DirectX.Capture project, I would like to read the mouse clicks and movements in the video preview panel. However, since the panel in the main form is overlayed with a new panel whenever Preview is active, the mouse movements on the original panel are unavailable. Is there a way to fetch the mouse movements in the "new" panel?
Thanks.
|
|
|
|
|
I would like to know how
to creat CDX index file for DBF Table.
thx
|
|
|
|
|
I have two forms (login and main). And as suggested on this forum, I load the login from my main form. So I have a modal login form infront of my main form. That is the way I want it but another problem emerged with the use of loginForm.ShowDialog(). If user clicks 'ok' and something is not right, I call a messageBox with an appropriate messsage; however, when I click 'ok' (on the message box) instead of bringing me back to the login form so I can retry loging in, application exits. It dosn't occure when I call loginForm.Show(), but this is not what I need. Please let me know where I'm going wrong.
Thank you
-- modified at 13:02 Monday 29th August, 2005
|
|
|
|
|
Build a loop (e.g. do-while-loop) that calls loginForm.ShowDialog and evaluates the DialogResult. If user clicks 'ok' and something is not right, show the message box and ensure that the loop is executed one more time (e.g. with a bool variable).
www.troschuetz.de
|
|
|
|
|
I was wondering why does the closing of the message box trigger the closing of the actual login form?
Thanx
|
|
|
|
|
Hmm, I guess I misunderstood your first posting a bit. Thought you check whether something is not right and call a messageBox after the ShowDialog method returned. Am I right that you do this inside of an event handler of the OK button?
Anyway, I think your login form automatically closes cause you set the DialogResult property of your OK button. If the value of this property is set to anything other than DialogResult.None , and if the form was displayed through the ShowDialog method, clicking the button closes the form without your having to hook up any events.
www.troschuetz.de
|
|
|
|
|
The code I'm working with was initially witten by someone else that is why I wasn't aware that DialogResult of the OK button was set to something. Your suggestion hit the spot. Thanks a lot.
|
|
|
|
|
|
hi all,
I have developed a application using C# and generate exe.(test.exe).But the problem is when I used a decompiller ,I can easily obtain the code again.Even though I convert this exe to class Library, It is also can decompile to get source code.
So How am I avoid this situation.How can I stop decompilling the .NET Application exe?
any answers greatly appreciated.
thanks in advance.
|
|
|
|
|
.Net languages 'compile' into an intermediate language (IL), and are only converted into machine code at runtime. There are obfuscation tools available that will scramble your IL in a manner that will make it difficult to reverse enginerr.
|
|
|
|
|
...finally available Goliath.NET - the last secure obfuscator for .NET Platform - the new plan all Italian who tries to stop the decompilation & reverse-engineering of the .NET assembly
thanks for your attention & best regards,
Marcello Cantelmo
www.cantelmosoftware.com
Nothing is Impossible if Not Tests the Absurdity !
|
|
|
|
|
Well I've gone through numerous examples and code samples here on the Code project as well as other places on the net and I just can't seem to get them to work properly. All I am trying to do is capture a screen shot of the entire desktop...INCLUDING all windows, programs & applications open on the desktop. The problem I am having is that whenever I take a screen shot, not all applications are captured. Currently I have an application that opens up several forms internally...as well as several IE Browsers. When I capture the screen the application is captured, but all of the forms and IE browsers that are overlaying the application are NOT captured. Almost as if they were all 'hidden' the screen shot was captured, then they were displayed again. Could someone please please help?? I'm just thoroughly confussed. Whenever I use the 'Print Screen' button the entire screen(s) contents are all captured perfectly, what am I doing wrong? Any and all help would be greatly appreciated, thanks so much. The code I am using is as follows...
public static Bitmap GetDesktopWindowCaptureAsBitmap()<br />
{<br />
Rectangle rcScreen = Rectangle.Empty;<br />
Screen[] screens = Screen.AllScreens;<br />
<br />
foreach(Screen screen in screens)<br />
rcScreen = Rectangle.Union(rcScreen, screen.Bounds);<br />
<br />
Bitmap finalBitmap = new Bitmap(rcScreen.Width, rcScreen.Height);<br />
<br />
Graphics g = Graphics.FromImage(finalBitmap);<br />
g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;<br />
g.FillRectangle(<br />
SystemBrushes.Desktop,<br />
0,<br />
0, <br />
rcScreen.Width - rcScreen.X, <br />
rcScreen.Height - rcScreen.Y);<br />
<br />
IntPtr hdcDestination = g.GetHdc();<br />
<br />
foreach(Screen screen in screens)<br />
{<br />
IntPtr hdcSource = Win32.CreateDC(<br />
IntPtr.Zero,<br />
screen.DeviceName,<br />
IntPtr.Zero,<br />
IntPtr.Zero);<br />
<br />
int xDest = screen.Bounds.X - rcScreen.X;<br />
int yDest = screen.Bounds.Y - rcScreen.Y;<br />
<br />
bool success = Win32.StretchBlt(<br />
hdcDestination,<br />
xDest,<br />
yDest, <br />
screen.Bounds.Width, <br />
screen.Bounds.Height, <br />
hdcSource, <br />
0, <br />
0, <br />
screen.Bounds.Width, <br />
screen.Bounds.Height, <br />
(int)Win32.TernaryRasterOperations.SRCCOPY);<br />
<br />
if (!success)<br />
{<br />
System.ComponentModel.Win32Exception win32Exception =<br />
new System.ComponentModel.Win32Exception(); <br />
System.Diagnostics.Trace.WriteLine(win32Exception);<br />
}<br />
<br />
Win32.DeleteDC(hdcSource); <br />
}<br />
<br />
g.ReleaseHdc(hdcDestination);<br />
g.Dispose();<br />
<br />
return finalBitmap;<br />
}
|
|
|
|
|
Are you capturing right after you create the windows? You have to give it several message loop iterations before it actually displays the windows.
Try putting the capture in a timer, set to say 100 msec or so. Be sure to turn it off right as the timer fires so that it only fires once, and be sure to use System.Windows.Forms.Timer (the one in the toolbox) so that you don't have threading issues.
|
|
|
|