|
Create an object of the form and set the name of the object as MainPage
Form newForm = new Form();
newForm.Name = "frmMainPage";
newForm.Size = new Size(200, 200);
newForm.Location = new Point(10, 10);
newForm.Show();
Oops I read your question wrong . You must be using what Colin said
Last modified: 11mins after originally posted --
|
|
|
|
|
IMHO this is not OP asks.
Perhaps he wants to dynamically create an instance of a class whose type is given by the "frmMainPage" string. Do you agree?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
CPallini wrote: Perhaps he wants to dynamically create an instance of a class whose type is given by the "frmMainPage" string. Do you agree?
Yeah, realized I read his question wrong
|
|
|
|
|
A form is just a class. You can use reflection to instantiate an object of a class if you know the name of the class.
See the MSDN documentation in the System.Reflection namespace.
|
|
|
|
|
OK --first post...;P
I have a windows app (simulation tool) that does a bunch of background number crunching. This is my first full C# project.
I want to stream some progress messages back to the user since the full simulation takes some time to run. (a la the messages that scroll by in a box during some software installation) The messagebox doesn't really do the trick.
Right now I am using a readonly textbox on the form and adding each message to the .Text property of the box, but this does not seem like the most efficient way. It usually doesn't actually display anything until it has all the messages --you just see the scroll bar changing in an empty box and then all the text appears, and when it's all said and done, there will be alot of messages and this seems like a lot of redrawing mostly the same thing...)
Basically, I want the equivalent of Console window Writeline messaging but delivered to a windows app something. It seems like there should be such a thing, but I can’t find it.
Thanks in advance.
-- modified at 12:49 Thursday 19th April, 2007
OK --so it turns out the property I was looking for was AppendText. I just didn't find that in any convenient documentation sources. It sounds like the Application.DoEvents() has some real memory use problems
|
|
|
|
|
The problem is that you're running your calculations on the UI thread. That will stop the update to the UI when you update the TextBox pretty quick.
The best solution is to move your long-running code to a background thread. A quick'n'dirty workaround is to call Application.DoEvents() every time you update that TextBox. But, there are pitfalls with using it if you don't manage the usable state of the controls your users can click on properly.
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
In addition to the above, I suggest you use a ListBox rather than a TextBox
for displaying a growing collection of text strings; it is much more efficient
since it has no need for all the strings to be concatenated.
|
|
|
|
|
Hello All Gurus,
I have one client server application where I am sending files from client to server ,like file upload functionality , File could be any file eg .exe , .jpeg .
I am sending data in byte array through network stream /sockets.
File is tranfering correctly but when I am trying to open any .pdf or .jpeg file after transfer it is giving me error.cannot open file not in correct format.
Only txt file working correctly..
Please advise.
Regards ,
nishu
|
|
|
|
|
The file your saving on the server is, obviously, being corrupted. Either your client isn't sending the file byte-for-byte, or the server isn't receiving it properly, or it's not writing it byte-for-byte to disk. Without seeing anyn of your client and server code, it's impossible to tell you what's going wrong.
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
It probably means the bytes are corrupted -- either you didn't get all the bytes or you didn't get them all in the right order. Do a file compare between original and transferred version to see if they're the same.
|
|
|
|
|
I'm wondering if the server is writing out a text file or a binary file? If the server is writing out a text file, that would explain this behaviour...
Phil
|
|
|
|
|
Yes it would. He's probably using TextReader/Writer, or some other text-only stream, probably even with an Encoding he specified, for reading/writing binary files. That'll corrupt 'em pretty quick.
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
Thanks for your reply...
I am not using TextReader/Writer ,I am using Filestream to write in the file....my code is as below,
stream = client.GetStream();
writer = new System.IO.StreamWriter(stream);
freader = new System.IO.FileStream(@"d:\AJAX_process.jpg", System.IO.FileMode.Open);
long length = freader.Length;
writer.WriteLine(length.ToString());
writer.Flush();
byte[] buffer = new byte[length];
freader.Read(buffer, 0,(Int32)length);
freader.Flush();
freader.Close();
//write buffer to network stream//
stream.Write(buffer, 0,(Int32)length);
stream.Flush();
stream.Close();
writer.Close();
One more question....
Do I need tto sent byte after byte....??
Regards ,
nishu
|
|
|
|
|
sorry I forgot to write but The above is sending data ....
stream=client.GetStream();
reader = new System.IO.StreamReader(stream);
filename = reader.ReadLine();
length = long.Parse(reader.ReadLine());
byte [] buffer = new byte[length];
stream.Read(buffer, 0,(int) length);
fwriter = new System.IO.FileStream(@"d:\new.jpg", System.IO.FileMode.CreateNew);
fwriter.Write(buffer, 0,(int) length);
MessageBox.Show("write to file done");
Regards ,
nishu
|
|
|
|
|
I want to enable a user to export a single MS Access Data Table from a multitable database into a separate database. More, I want the user to be able to create the separate database file at the same time he/she exports the datatable to that separate database file. I could simply use File.Copy to copy the entire database to the separate database file, but the users won't need the entire database, just the one table to allow them to archive certain information. Is this possible?
|
|
|
|
|
who can teach me to hacker ID games??
|
|
|
|
|
Noone around here will ever help you steal someone's software. Think about it. You just asked a bunch of developers, who making their living writing and selling software, how to steal the very software they're writing!
Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic 2006, 2007
|
|
|
|
|
If I told you I'd be cutting my own throat!
|
|
|
|
|
I was wondering if anyone knows how to access a control (like a textbox control) that is attached to a MS Word document that has already been created. I need to do it using C#. Any example would be a big help.
|
|
|
|
|
|
I opened up a new Word Doc. Started recording the macro. Created a Text Box and started typing some text in it. Stopped recording of the macro and did an Edit of the Macro to see the code and this is all i got out of it:
ActiveDocument.ToggleFormsDesign
Selection.InlineShapes.AddOLEControl ClassType:="Forms.TextBox.1"
ActiveDocument.ToggleFormsDesign
ActiveDocument.ToggleFormsDesign
ActiveDocument.ViewPropertyBrowser
ActiveDocument.ViewPropertyBrowser
It still does not tell me how to access the Text Box.
I can create on for the Word doc with
aDoc.InlineShapes.AddOLEControl(ref TextBoxName,ref Range);
put i need to get one that is already in the word doc
any ideas?
|
|
|
|
|
So save that document with the textbox in it. press return a few times. Start a macro click on the textbox, stop the macro. I would guess the macro code would have something that what you have above. So I would guess that you need to know which text box it is. It looks like they are numbered. YOu added one so the id is forms.textbox.1. So if you put the correct number in there you should be able to select the text box.
Ben
|
|
|
|
|
Hi All
I would like to implement the "CANCEL" operation while I'm copying a large file because it can takes too much time. I would like to do it in wondeful C# language.
Do you think that creating a separate Thread for the copy operation (implemented using File.Copy method) that could be killed when I call the CANCEL button put in a different Thread?
Regards
ManuStone
|
|
|
|
|
|
Hello
I have a computer which has a share folder with username and password.
I want to copy a file from this folder without having to map the folder into a drive just by a simple copy. What copy command accepts also username and password for file copying purpose ?
Thanks,
Clint
|
|
|
|