|
There are 2 ways I would go about this:
The graceful way would be to use remoting. In your code that checks for a single instance you would set up remoting to communicate with the running instance of your program and call a method in that instance to bring itself to the foreground. Remoting is ideal for communicating locally across application and process boundaries. The only drawback is that you need a network card to avoid problems.
In the case that you can't guarantee your client's will have a NIC you can use Windows API. You need to call the Activate Window API.
Here's a quick intro into that API.
http://www.devhood.com/tutorials/tutorial_details.aspx?tutorial_id=711
|
|
|
|
|
I need to have a timer that halts my program for 2 seconds (2000 milli secs). I have a GUI program calling a class which is firing my custum events. I need to stop the program for 2 seconds after each event..and resume soon after the 2 seconds. does any one have a clue
Thanks...
GaMBiT---> aND ReVeNGe WiLL Be
|
|
|
|
|
Create a timer in your class. You'll to subscribe to the timer's Elapsed event and have code to start and stop the timer.
<br />
class MyClass<br />
{<br />
<br />
System.Timers.Timer _timer;<br />
private void SetupTimer()<br />
{<br />
_timer = new System.Timers.Timer(2000);<br />
_timer.Elapsed += new System.Timers.ElapsedEventHandler(_timer_Elapsed);<br />
}<br />
<br />
private void PauseApp()<br />
{<br />
_timer.Enabled = true;<br />
}<br />
<br />
private void _timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)<br />
{<br />
_timer.Enabled = false;<br />
}<br />
<br />
}<br />
|
|
|
|
|
Guys this code is great for what I'm trying to do - basicly I have a for loop, and I need a timed pause in execution inside the loop - I'm trying to implement this code, but I don't know how to subscribe to the elapsed event, or start/stop the timer.
I appreciate anything you can add!
Thanks in advance,
Joe
|
|
|
|
|
u can be ease use the threads in this thing
using System.Threading;<br />
and in timer Elabsed event or tick event just place this line Thread.Sleep(int milli second);<br />
Thread.sleep(2000);
ByMindOnlyYouCanDoIt
|
|
|
|
|
You shold not do that. It's a bad idea. If you call Thread.sleep(...) you'll lock up the main thread (probably your UI thred) for 2 seconds. You should NEVER break a user's access to your main thread for long running processes, especially in this case where it happens often as in your post. If you do, your app will seem to lock up to the user. Instead, if you use the timer with threading you will prevent the main thread from being locked, and you have the ability to enable and disable specific items (buttons etc...) accordingly. You always want to allow user interaction, even if you have to lock down controls and there's nothing enabled to interact with.
|
|
|
|
|
Doesn't the System.Threading timer start on a new thread itself?
/\ |_ E X E GG
|
|
|
|
|
Yes, when you create a new thread. That's not true when you call Thread.Sleep(...). That takes action on the thread from which the code is executed.
|
|
|
|
|
First and foremost, thanks for helping out.
The System.Threading in my case is a little out of question, since the user will be observing the UI for information from a (particularly compute intensive) class. Halting the main thread for 2 seconds would make it even more slower. Timers make more sense. However how much I tried before, I couldn't even make them work....Now its OK..thanks to you guys
Thanks!!
GaMBiT---> aND ReVeNGe WiLL Be
|
|
|
|
|
Hello everyone,
I wrote a little application designed to lay some crucial data on Top of all other Windows. Basically, I am using a window with FrameBorderLayout.None and a single Label which is updated regularly. Frame and Label have a White background and the TransparencyKey is set to White.
For me, this is perfect - I lose only very little space on my Desktop, no additional entry in my Taskbar and still I get all the info necessary.
There only is ONE drawback: Some mechanism is applying anti-aliasing to my label's text, which is quite disturbing.
Is there any way to disable anti-aliasing (I tried turning it off in the display properties, which did not solve my problem) or another approach to get "Text only"?
Cheers
Sid
|
|
|
|
|
You can draw the text on the Label yourself. Handle the Paint event of the Label - or, better yet, extend the Label class and override OnPaint for even more control. Set the Graphics.SmoeethingMode to SmoothingMode.None and draw the text yourself:
public class TextLabel : Label
{
public TextLabel()
{
SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.DoubleBuffer |
ControlStyles.UserPaint, true);
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Graphics g = e.Graphics;
g.SmoothingMode = SmoothingMode.None;
g.DrawString(Text, Font, new SolidBrush(ForeColor), new PointF(0f, 0f));
}
}
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hi all
I was wondering if there's any limit to the windows controls? I recieve the following error "Error creating window handle." while trying to databind a treeview to textbox.
Thanks ppl
|
|
|
|
|
Yes there is a limit to the number of handles in Windows and Windows NT, the former being much lower but still impractical to ever reach. This is most likely not your problem.
The problem is, most likely, that a TextBox is not a container control. The use of "databind" is also not possible in this context, since neither represents data.
Please post relevent code so that we can help you diagnose the problem you're having, since the discription you've given doesn't have nearly enough information to form any decent diagnosis.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Ok here's the code where it happens
This works fine
"this.textBox_ClsId.DataBindings.Add(new Binding("Text", ((DataSource)this.treeView_WorkView.SelectedNode.Tag), "Datamember"));
this.textBox_ClsIdentifier.DataBindings.Add(new Binding("Text", ((DataSource)this.treeView_WorkView.SelectedNode.Tag), "Datamember"));
this.textBox_ClsDescription.DataBindings.Add(new Binding("Text", ((DataSource)this.treeView_WorkView.SelectedNode.Tag), "Datamember"));
this.textBox_ClsVersion.DataBindings.Add(new Binding("Text", ((DataSource)this.treeView_WorkView.SelectedNode.Tag), "Datamember"));"
This is the only line giving me the error "//this.textBox_ClsExtends.DataBindings.Add(new Binding("Text", ((DataSource)this.treeView_WorkView.SelectedNode.Tag), "Datamember"));"
This is also working fine
"this.checkBox_ClsAbstract.DataBindings.Add(new Binding("Checked", ((DataSource)this.treeView_WorkView.SelectedNode.Tag), "Datamember"));
this.checkBox_ClsNew.DataBindings.Add(new Binding("Checked", ((DataSource)this.treeView_WorkView.SelectedNode.Tag), "Datamember"));
this.checkBox_ClsSealed.DataBindings.Add(new Binding("Checked", ((DataSource)this.treeView_WorkView.SelectedNode.Tag), "Datamember"));"
thanks
|
|
|
|
|
What's a DataSource , and what's the "Datamember"? Please don't post pseudo-code since it typically doesn't show the error. If DataSource is actually a class you created then please explain it, otherwise please use the actual class. For "Datamember" it's not so much important, but specifying such information should not be any sort of breach. If someone wanted to see your code, they'd just have to disassemble or decompile it with a slew of tools already available, including ildasm.exe that ships with the .NET Framework SDK.
If DataSource is a class besides a DataSet , DataTable , DataView , or DataViewManager derivative, then you're using property bindings. What type is the property that is returned from whatever "Datamember" represents in that line? If it is a data or data-derived class from those listed above, what type of data does the column represented by "Datamember" in that line represent, and is it returning DBNull (or null , if a strongly typed DataSet )?
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
I apologize for not providing the correct information. The datasource is a class and the class name is "Class" and the datamember is "Extends". I found out that the datamember "Extends" was not assigned. Again I apologize but I'd like to say thank you for the help.
Thanks
|
|
|
|
|
Hi
there is a requirement to find some solution to make PDF secure that is if one opens in Acrobat,he can not 1)Print 2)Save and Copy(Ctrl+C) any part of document..
is there any solution in .NET?
-adnan
|
|
|
|
|
Such a solution would not be a .NET solution, but a solution using the PDFs themselves, since a PDF viewer is what is viewing the document. Adobe has had this capability for many years now and you should just buy Adobe Acrobat (the full version, not the reader - which does honor the DRM of the PDFs). See http://www.adobe.com/security/main.html[^] for more information.
I am not familiar with any .NET PDF writers that have the DRM capabilities, so you'll need to use Acrobat to do so. For that, read the documentation included with Acrobat since this is not a .NET solution.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
These are normal document properties of a .PDF file. When Acrobat creates the file, security properties can be written in to do exactly this. Now, if your using a 3rd party component to generate and write the .PDF file, you'll have to get with that components manufacturer to see what kind of support they offer to do this and how you can programmatically get to it.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I'm trying to use WIA for the scanning of an application yet i don't want the default UI it provides and would also like to be able to pre-set the properties for the scan.
I've been looking at the article on here about WIA:
http://www.codeproject.com/dotnet/wiascriptingdotnet.asp
I've been able to change the code so it cuts out the UI and just gets the scan, however i'm having trouble trying to set the properties for the scan, one comment on the article says that you can use 'GetPropById' to do this yet i've so far had no luck, has anyone got experience with using this or can see a way of being able to pre-set the properties?
|
|
|
|
|
*How to monitor a printer queue from C#
*Get a handle to the printer you want to monitor
====================================================================
HI Experts,
how are you .hope you all will be fine.. i have started that i have to work on C#.well sir my project in which my main motto is to pause,cancel, and delting a job.. i have done the RND of this topics and methods used in the project...
Well sir now i am in the way that i have to know about the event handlers,event watcher for the printjobs or printers.In other words that when the user give the command of printjob then this job is watched by the event watcher and the information of printer i.e printer handler is given to the the event handler like jobid and according to this watching information of job the users jobs should be pause,cancel or delete the job.I have to handle with event wathcer , not from the button of the form,,because the job should be captured as before the printer starts and the action i.e performed pause or delete or resume .Now i am on the phase that i have to start working on handlers ,needs yours help.Waiting for yours reply .
With Regards,
Ishtiaq Ahmed
|
|
|
|
|
i made dialog with datagrid, now how do i set DialogResult.OK when i doubleclick on datagrid,
it's easy with button, ..hmm ..can you help me please
|
|
|
|
|
Create a handler for the DoubleClick event of your Datagrid and assign the wanted member of DialogResult enumeration to the DialogResult property of your Form :
private void dataGrid1_DoubleClick(object sender, System.EventArgs e)
{
this.DialogResult = DialogResult.OK;
}
www.troschuetz.de
|
|
|
|
|
thx!
|
|
|
|
|
Hi there,
Could anyone point me in the right direction... I'm trying to create a simple application that uses reflection to inspect objects at runtime. I dont want to use the Property Grid because i want to save the results to a text file. I cant find any example code that shows how to do this.
Thanks
Rohan
|
|
|
|