|
To time something, grab DateTime.Now before and after the operation
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Hi there .
There is an another way to do it .
Try to use Thread in Threading namespace . Something like following code :
<br />
private void StartThread()<br />
{<br />
Thread thd1 = new Thread(new ThreadStart(Your_Function());<br />
thd1.Start();<br />
<br />
}<br />
<br />
<br />
private void Your_Function()<br />
{<br />
}<br />
Important : If your function get any parameter Use ParameterizedThreadStart delegate instead of ThreadStart
DMASTER
|
|
|
|
|
where is the timing information ?
Developer611 wrote: your function will be execute on per second
what is the meaning of this ?
the new thread will start immediately and execute the method once...
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
how to start a form maximized ?
-- modified at 23:58 Tuesday 7th August, 2007
|
|
|
|
|
Set it's WindowState property accordingly, either in code, or the designer.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
what should i do if i have an error in ISynchronizeInvoke casting.
Actually i am doing a c# console application that use ISynchronizeInvoke
the code is like this:
ISynchronizeInvoke i = (ISynchronizeInvoke)this;
The Error:
Unable to cast object of type 'ArtIntelTania.Program' to type 'System.ComponentModel.ISynchronizeInvoke'.
hope somebody can help me
Thanks in advance
Regard,
jac
|
|
|
|
|
Consoles don't implement ISynchronizeInvoke . You'll need a Form or Control for that.
Can you describe in more detail what you're trying to acheive?
|
|
|
|
|
oic...
Actually the idea is like this:
- i want to display all the record(s) inside the database
- the connection is always there, so that i can retrieve the records. For an example, if i insert a new data the data will be displayed instantly (no need to refresh or debug once again).
thanks,
Jac
|
|
|
|
|
jacklynn_mei wrote: - i want to display all the record(s) inside the database
- the connection is always there, so that i can retrieve the records. For an example, if i insert a new data the data will be displayed instantly (no need to refresh or debug once again).
I don't know much about using databases. I'm guessing you'd probably have to hook into some event that is raiesed when the database changes and then display the update in your UI. A Form based application would probably be better for this than a Console application.
|
|
|
|
|
I want to control the Office Word's behavior using C#.
i.e. Create a new word document in local PC with specified path.
And if I open a remote word document I could control that when user close the document,Word should not quest a saving path but save the change into the remote region path(if the user selected save the change).
Becides these,I also want to know whcich behaviors that the Office Word have and I can retrieve these messages?
Thanks.
GOOD LUCK.
|
|
|
|
|
Hi,
Do you wish to open the Word doc from another process? Do you wish to populate it? Would you like to automate the creation of documents, either before Word opens or by helping the user after it has opened?
Basically to open Word with a new document you need to do the following:
First create a new Windows Forms project. Add a button to the default form.
Next add a reference to the Microsoft Office 12.0 Object Library & Microsoft Word 12.0 Object Library (for Office 2007) so you have access to the word objects. The Office 12.0 Object library is not strictly necessary, but you may find you need it to complete other operations further down the track.
Next use the following as the code behind for Form1:
using System.Windows.Forms;<br />
using Word = Microsoft.Office.Interop.Word;<br />
<br />
namespace WordSample<br />
{<br />
public partial class Form1 : Form<br />
{<br />
private object m_Missing = Type.Missing;<br />
<br />
public Form1()<br />
{<br />
InitializeComponent();<br />
}<br />
<br />
private void button1_Click(object sender, EventArgs e)<br />
{<br />
Word.Application word = new Word.Application();<br />
<br />
Word.Document wordDoc = new Word.Document();<br />
<br />
word.Visible = true;<br />
<br />
wordDoc.Application.DocumentBeforeSave += new Microsoft.Office.Interop.Word.ApplicationEvents4_DocumentBeforeSaveEventHandler(Application_DocumentBeforeSave);<br />
wordDoc = word.Documents.Add(ref m_Missing, ref m_Missing, ref m_Missing, ref m_Missing);<br />
<br />
}<br />
<br />
void Application_DocumentBeforeSave(Microsoft.Office.Interop.Word.Document Doc, ref bool SaveAsUI, ref bool Cancel)<br />
{<br />
}<br />
<br />
}<br />
}<br />
<br />
That will create a new instance of word. To modify the closing behaviour there are a number of events available to you including the Application.DocumentBeforeSave or Application.DocumentBeforeClose events. I have included a dummy ApplicationBeforeSave event for you. There is extensive documentation on MSDN regarding the Word ObjectModel that lists all events (http://msdn2.microsoft.com/en-us/library/kw65a0we(vs.80).aspx[^]; http://msdn2.microsoft.com/en-us/library/aa192495(office.11).aspx[^] should get you started, there is also plenty about Office 12/2007 you'll find from there).
If you have any further questions please feel free to ask away. You also have a lot more options for automating word via VSTO with Document or Application level customisations that you may wish to consider.
Hope that helps, good luck and have fun
Toby Russell
Software Engineer
|
|
|
|
|
Thanks.
Although I am a beginer of C#,but I will glad to have a try.
Best wishes.
|
|
|
|
|
Hi kcynic,
The code I gave you will work straight out to open word from a windows form. Changing the path can easily be done in the event that is created for the document when you open it from the form, have a play with it and you should find it easy enough. If you have more questions please feel free to ask whatever. Mark was right; Office is incredibly easily and powerfully automated and can be customised to do many things for the user. If you are really serious about Office Automation look into VSTO. It gives a fantastic, totally managed code, interface for Office development.
Regards,
Toby
Toby Russell
|
|
|
|
|
All the words are good guide for me.But there also some problems puzzled me.
For example,I offen find some compling error like some .dll files are used somewhere so VS can not copy the created file to the local device.
Why?
|
|
|
|
|
There are a myriad of reasons why you might get some messages. My advice is to make sure you don't have any instances of your code running anywhere as that will cause errors such as the one you mentioned and to google the errors as they arise.
Toby
|
|
|
|
|
|
I will glad to read it carefully.
Thank you very much.
|
|
|
|
|
Hey all. I am having a bit of trouble with ReflectionPermissions. I have some code that uses reflection to access properties of classes in a different assembly (also mine). The issue is it only gets the private fields from the top-most object, it does not see the private fields from any of the base objects.
I have been trying different things with ReflectionPermissionAttribute s with no luck. I think I don't understand how to use it correctly.
Anyone got any ideas? Do I have to have the calling code set something or the objects with the private fields? Or the assembly in which they live?
On the calling class I have tried things like
[ReflectionPermission(SecurityAction.Assert, Flags = ReflectionPermissionFlag.AllFlags, MemberAccess = true, Unrestricted = true)]
with no luck.
Any help on this would be great. Thank you in advance.
Luke
|
|
|
|
|
Hello,
I'd like to make a (read only) console component.
Almost a multiline TextBox in read only with a fixed number of lines.
As a DOS console which use a fixed buffer, the old lines should be discarded.
To limit the line number, I tryed to limit the character number (which is ok in my case) like so :
int maxNumCharacter = 10000;
public void AppendText(String text)
{
textBox.AppendText(text);
if (textBox.Text.Length > MaxNumCharacter)
textBox.Text = textBox.Text.Remove(0, textBox.Text.Length - maxNumCharacter);
}
But setting the Text property is not that good because :
- It replaces all the textBox characters. It's slow.
- It also has the effect to move the scrollbar to the top and I need it allways at the bottom if the user doesn't move it.
Is there any way to do such a component ?
Thanks.
|
|
|
|
|
Hi,
if your Control is to be line-oriented then I would go for a ListBox or a ListBox derivative.
The advantages are:
- its Items collection holds items of arbitrary type, could be simply strings.
- lines never get concatenated, they are kept in the Items collection; fast and easy
- you can limit the number of items you keep, i.e. you could append to the bottom,
and, if required, remove lines from the top
- it offers scroll bars, so you can easily do a scrolling DOS window, holding much more
lines than your screen could show at once.
The disadvantages are:
- selection, if required, is by lines, not an arbitrary from-to selection
- maybe some more, nothing comes to mind
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Thanks for your answer.
I thought about using a listbox but the input text should not allways be formated line by line. As you pointed the selection cannot be arbitraty in this case.
Also, I think its quite heavy to use a listbox for this simple stuff (actually its nothing more than a fixed text buffer). I need it to be really fast and light.
I use it as an output log for a little game editor. This component can be filled 60 times per second if a log is made in the update loop.
|
|
|
|
|
ListBox is ideal for logging; there is simply nothing else I would consider for logging.
I would never consider a TextBox for big, live pieces of text (anything larger than
3 lines of text, and/or adding/replacing 3 lines per second).
I have ListBoxes that consume 100 lines per second and more.
And I forgot at least one more advantage:
you can make the ListBox OwnerDraw, meaning you draw the lines yourself.
I do this for highlighting (painting some lines red or bold).
If handled correctly, there should be no speed penalty involved.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
I agree. Listbox can be really good in many cases. But I guess it a question of taste.
For example in visual studio you can use both, the Output and/or the Tasklist.
I prefer to use the Output.
In my case the output text is formated by the user (a developper).
I cannot assume any formating, he is free. He should be able to write anything he wants and then select on one or multiple line (columns selection would be great too, as a CMD window)
As you said, with listbox you can use color, draw the lines yourself, etc..
It has a cost. Drawing a simple character buffer and updating only what needs to be updated is a lot faster than the insertion of listbox items, the selection of their colors (according a keyword in the line for example, etc...)
I may use a listbox component later for this purpose. Right now I need something different.
Thanks.
|
|
|
|
|
I have an nterview where I was asked What is useful to use interface or abstract classes.
When We use interface and when we should use abstract classes?
Thanks in advance
seema
|
|
|
|
|