|
I have a thread running that needs to read the Windows Clipboard but my Clipboard.GetDataObject() always returns null. I've read that Clipboard.GetDataObject() doesn't work in a thread (even though it's supposed to be thread safe), so I tried setting the apartment state by doing Thread.SetApartmentState(ApartmentState.STA) and still no luck. Anyone have any ideas I can try? The Main() function is declared with [STAThread] and I've even tried using [STAThread] to declare the function that tries to read the clipboard.
Here's the background on the thread:
The thread imports data from various formats (Excel, CSV, DBF, MDB, and I"m trying to get Word working) into a database. The best way I've seen to read Word Docs is to open the doc by creating a Word Application class, opening the doc in question, having word select severything and copy it to the clipboard.
I'm running WinXP pro and Word 2007 (wasn't having much luck in the previous version of Word either)
Here's the code that I use to call the thread:
m_ProcessThread = new Thread(new ParameterizedThreadStart(this.RunJob));<br />
m_ProcessThread.SetApartmentState(ApartmentState.STA);<br />
m_ProcessThread.Start(NextUp);<br />
m_JobList.Sort();<br />
m_JobList.ResetNextUp();<br />
UpdateJobListView();
And here's my clipboard reader (straight from MSDN)
IDataObject iData = Clipboard.GetDataObject();
Thanks!
|
|
|
|
|
I'm not really sure what you've read, but the only thing that could make sense is that it only works in a UI thread ("doesn't work in a thread" - every piece of code that's being executed is run in a thread...).
If everything else fails and you're still convinced the threading is the culprit you could try marshalling all calls to Clipboard.GetDataObject() to the UI thread... (using Invoke() or BeginInvoke() ).
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
You know, I really really should've thought of calling from the UI thread myself...
I'll give it a shot, I'm sure it'll work.
Thank you very much!
|
|
|
|
|
Can C# create dynamic hashes and arrays in a similar fashion to perl (i.e. in perl you can statically define almost any structure your mind can imagine)?
For example an array of variable length arrays (pseudo code):
<br />
arrays = <br />
{<br />
{1},<br />
{1, 2},<br />
{3, 2, 1},<br />
undef,<br />
{5, 6, 7, 8, 9},<br />
}<br />
Todd Smith
|
|
|
|
|
|
edboe wrote: Have you tried it?
Nice!
led mike
|
|
|
|
|
Your code in C#
object[] arrays =
new object[]
{
new object[] {1},
new object[] {1,2},
new object[] {3,2,1},
null,
new object[] {5,6,7,8}
};
|
|
|
|
|
Even though I have a feeling that I'm doing someone's homework, I think it would be more like this:
Nullable<int>[][] arrays = new Nullable<int>[][]
{
new Nullable<int>[] {100},
new Nullable<int>[] {1,2},
new Nullable<int>[] {3,2,1},
null,
new Nullable<int>[] {5,6,7,8}
};
|
|
|
|
|
I'm trying to find a good HTML editor control for my Windows Forms application. The control must not use the IE COM and ActiveX components, and should have source available, ideally in C#.
|
|
|
|
|
SyncFusion have an editor control (I think), it's either a viewer or editor/viewer can't remember which. And I think it has source code available.
Sorry if it doesn't do the job but I just remember coming across it a while ago.
|
|
|
|
|
My colleague downloaded their EssentialEdit and EssentialHTMLUI, and I will be looking at them when he gets it, but I've found that the problem with most html controls is that they wrap MSHTML or one of the other IE browser interfaces, eliminating the Mac as a target platform.
So far I'm starting to think about using an HTML rendering control (like EssentialHTMLUI) and extending it by providing my own editing functions.
|
|
|
|
|
I don't think you'll find many that aren't based on MSHTML or Gecko because it's a hell of a lot of code to write to support various pages, e.g. those which don't conform etc. You might be able to find one which only supports XHTML for example since at least that should be standards compliant.
|
|
|
|
|
I have started looking at using the Mozilla tools on both platforms, but I think that will be some work.
|
|
|
|
|
How extensive do you need the editor to be, i.e. support all forms or is it just going to be using a subset of HTML?
|
|
|
|
|
No, it only has to support enough HTML to allow the user to create documents, i.e. all normal formatting including table editing etc. and maybe some styles.
|
|
|
|
|
There's a RichTextBox control here (on CP) which supports some of this but will save it's output to HTML. Very basic but allows pictures, tables etc and I think supported some styles.
If I come across it again I'll let you know.
|
|
|
|
|
Hi,
I am working an application window program using .Net Framework SDK 2.0 but I having a problem that after I compile with the SDK 2.0, as I run the program, there are 2 windows appears together which are the blank console window and my desired application window.
Problem is when closing the console window, the application closes. But I still want the application window.
How to code it? Help Me...
|
|
|
|
|
I think you should change the way you comple ur code using csc.exe
you will be compiling ur code using
csc /target:exe yourfile.cs
You need to change ur command line option like,
csc /target:winexe yourfile.cs
|
|
|
|
|
|
Hello,
I have a problem, I have an application which is about 900x700 size by default, and it looks fine on a 1024x768 desktop resolution, but on computers where there is a 800x600 resolution set its huge, it event doesnt fit the screen.
So my question.. is there anyway to scale the mainform so that all its content will be scalled down or up too ?
|
|
|
|
|
nevermind Scale() does the trick
|
|
|
|
|
My program has different "modes". Each mode has its own control which inherits a base control. The base control has the base code which each control uses. The mode controls have different functionnality.
What i want to be able to do is change the mode, which means changing the control but without loosing the data/view which the control is using.
E.g: If your in Edit mode, you can switch to View mode but not have to re-create the data.
Im abit stuck on how i'd do this, as once you dispose of the control, you loose the data.
Any ideas are appreciated.
Regards,
Gareth.
|
|
|
|
|
Why disposing it? simply make it hidden. it will keep the data.
~~~ From Milano to The Hague, easy as it goes ~~~
|
|
|
|
|
Hello,
Hope I understand everything write.
You have a base Control (I name it ControlA) and two Controls (I name them ControlA1 and ControlA2) which inherit from ControlA.
You have for example a ControlA1 (I name it myControlA1) in your program(on your form) and at runtime it has to be changed to a ControlA2.
I think what you have to do in, this very special case, is to make a new instance of your ControlA2.
ControlA2 newControl = new ControlA2();
Then you have to, lets say downgrade, your ControlA1 to a ControlA Control.
ControlA oldControl = myControlA1 as ControlA;
Now you should copy (clone) the property values from oldControl to newControl.
Therefore the namespace "System.ComponentModel" is required.
PropertyDescriptorCollection pdcoldControl = TypeDescriptor.GetProperties(oldControl);<br />
PropertyDescriptorCollection pdcnewControl = TypeDescriptor.GetProperties(newControl);<br />
<br />
foreach(PropertyDescriptor pdoldControl in pdcoldControl)<br />
{
if((pdoldControl.Attributes.Contains(CategoryAttribute.Appearance) && pdoldControl.IsBrowsable)<br />
|| (pdoldControl.Attributes.Contains(CategoryAttribute.Behavior) && pdoldControl.IsBrowsable && pdoldControl.IsReadOnly==false))<br />
{<br />
PropertyDescriptor pdnewControl = pdcnewControl[pdoldControl.Name];<br />
pdnewControl.SetValue(newControl,pdoldControl.GetValue(oldControl));<br />
}<br />
}<br />
TypeDescriptor.Refresh(oldControl);<br />
TypeDescriptor.Refresh(newControl);<br />
<br />
newControl.Size = oldControl.Size;<br />
newControl.Text = oldControl.Text;
This code would of course look nicer in a method.
Now you can place the newControl, and remove and dispose the myControlA1.
This only works (if it works ) as long as your Form or parent control is in memory.
Hope that helped you.
All the best,
Martin
-- modified at 16:43 Friday 17th November, 2006
|
|
|
|
|
Martin, your code example doesnt work. It creates the control but doesnt show it. I've tried adding it to the Controls class, as well as Docking and BringToFront.
|
|
|
|