|
Hi Code Gurus,
(in a C# Windows Form application) How can I detect that the Enter key was pressed in a single line TextBox control in .NET? I want to enable the user to type in some text in the TextBox (a command) then by pressing Enter an action is taken (like the address bar in IE). This can be done very easily in VB and VC++. But in .NET, the only way I discovered so far is to use a multi-line textbox control and detect when the user presses Enter (using either KeyDown or KeyPress events) then remove the new line characters from the text, this is other than deleting any multine text pasted in the control except the first line. I believe there must be a better and more elegant way to do this but I just don't know it!
Regards,
Waleed
(a.k.a. Wal2k) www.wal2k.com
|
|
|
|
|
If you're going to ask this in one forum, please don't ask it in another. Cross posting is really frowned upon here. Just FYI before someone else who's in a really bad mood decides to jump down your throat...
Norm Almond: I seen some GUI's in my life but WTF is this mess
Leppie: I made an app for my sister and she wouldnt use it till it was colorful enough
Norm:good point leppie, from that statement I can only deduce that this GUI must be aimed at children
Leppie:My sister is 25
-Norm on the MailMagic GUI
|
|
|
|
|
Hi Code Gurus,
(in a C# Windows Form application) How can I access a public member of the form that defines the static Main() member function from another form? I have two forms, frmMain (defind in frmamin.cs) and frmDialog (defined in frmDialog.cs), I want to access a member of frmMain (a property or a function or whatever member) from within frmDialog. When the application runs, the frmMain form is displayed as the application's main window, if the user chooses Connect... from the application's menu, the other form frmDialog is displayed as a dialog using ShowDialog(), now what I want is to access some member fields of frmMain from within frmDialog while frmDialog is displayed as a dialog box (that was extremely easy in VB).
Well, to be more specific, what I want to do exactly is to enable the user to connect to a database, when the user selects Connect... from the menu, a dialog box is displayed to allow the user to enter the database connection information. There is an OleDBConnection object (public member), defined in frmMain, that I want to use in frmDialog (there is a button in frmDialog whose caption is "Connect"). In the event handler of that button I want to use the public member of frmMain (System.Data.OleDB.OleDBConnection m_OleDBConn). For example like this:
myfrmMain.m_OleDBConn.ConnectionString = ... etc
Regards,
Waleed
(a.k.a. Wal2k) www.wal2k.com
|
|
|
|
|
This is an extremely common question for people migrating from "classic" VB to .NET, as a result of the confusion caused by the way VB doesn't differentiate between the form class and an instance of the form.
The simple answer is that you have to provide a reference to the instance of your frmMain to the instance of frmDialog:
class frmMain : System.Windows.Forms.Form
{
public System.Data.OleDb.OleDbConnection m_OleDBConn;
...
private void Connect()
{
frmDialog D = new frmDialog();
D.Parent = this;
D.Show();
}
}
...
class frmDialog : System.Windows.Forms.Form
{
...
public frmMain Parent;
public void OK_Click(object sender, EventArgs e)
{
Parent.m_OleDbConn.ConnectionString = ... etc;
}
}
A better approach would be to show frmDialog as a dialog, and use public properties on frmDialog to retrieve the information in frmMain. For example:
class frmMain : System.Windows.Forms.Form
{
private System.Data.OleDb.OleDbConnection m_OleDBConn;
...
private void Connect()
{
frmDialog D = new frmDialog();
if (D.ShowDialog() == DialogResult.OK)
{
this.m_OleDBConn.ConnectionString = D.ConnectionString;
}
}
}
...
class frmDialog : System.Windows.Forms.Form
{
...
public string ConnectionString
{
get
{
return this.txtConnection.Text;
}
}
}
|
|
|
|
|
Hello,
I need some refernce points on accessing Assembly resources.
what I need is to add an xml file to a project, compile it into the exe and later access it without loading a file.
any help would be great.
Noam
Noam Ben Haim
Web Developer
Intel
noam.ben.chaim@intel.com
|
|
|
|
|
Are there any good ASP.NET applications/books/sites out there that show good 'best practices'.
I am currently working on an ASP.NET application and I have created lots of web controls and functionality. However the one thing I can't get my head round is how to actually structure all the pages to create a good Web Application.
What I currently have is functional but it is not pretty.
Thanks for your input.
Stupidity dies.
The end of future offspring.
Evolution wins.
- A Darwin Awards Haiku
|
|
|
|
|
|
I haven't finished looking through the documents yet but the IBuySpy.com site has ASP.NET best practices sample apps for a store front and portal site. Examples are available in both VB.NET and C#. So far it looks good although i'm no expert.
|
|
|
|
|
Yeah I did look at those myself but I can't make up my mind as to the suitability
Stupidity dies.
The end of future offspring.
Evolution wins.
- A Darwin Awards Haiku
|
|
|
|
|
For a psuedo-serialization method I'm doing to persist a tree view (the reason it's psuedo is because I don't want the TreeNodeCollection serialized as an element), I have two method signatures like so:
public void LoadNodes(XmlNode xmlRoot, ref TreeNode treeRoot);
public void SaveNodes(TreeNode treeRoot, ref XmlNode xmlRoot);
What I'd like to do, since this could be a fairly lengthy operation and needs to be done on 4 separate trees, is provide our framework application with Begin* and End* functions for asynchronous processing.
I've worked with threading a lot and have used asynchronous methods many times in the past, but I'm having problems imlementing it myself. I've written basic asynchronous methods were the state object is enough to pass custom values. I've read about all I can on it, and all the examples reference methods of the MulticastDelegate class that don't exist (I'm guessing these were .NET pre-release articles). I've also considered just returning Control.BeginInvoke and getting the object from Control.EndInvoke, but neither of my methods above return anything (hence, void - and there's a good reason for it).
Has anyone written any asynchronous methods that could help me? TIA
"Well, I wouldn't say I've been missing it, Bob." - Peter Gibbons
|
|
|
|
|
Okay, after reading an article in the docs one last time, I caught something I obviously missed last time. If you use the correct method signature, the compiler will generate BeginInvoke and EndInvoke automatically. It wasn't showing up in the Intellisense menu - nor the class documentation - so I never noticed it before.
"Well, I wouldn't say I've been missing it, Bob." - Peter Gibbons
|
|
|
|
|
Heath Stewart wrote:
If you use the correct method signature, the compiler will generate BeginInvoke and EndInvoke automatically.
Wow, didnt know that! Can u paste what the method?
Cheers
Give them a chance! Do it for the kittens, dear God, the kittens!
|
|
|
|
|
Hi all,
I am trying to write some small app that automates Word Application (mainly MailMerge, and sending word documents to the printer), and I have come to a problem.
Using the Missing.Value as a missing parameter (which is a good thing to do in every other method of the word app) will not work as most of the methods need a ref object as a parameter.
does anyone have a clue?
thanks
Noam
I attach a small piece of code for example.
this code does not compile, for the above reason.
<br />
Word._Application word = new Word.ApplicationClass();<br />
Word.Document doc = (Word.Document)word.Documents.Open(ref m_confirmationFile,<br />
Missing.Value, Missing.Value, Missing.Value, Missing.Value, <br />
Missing.Value, Missing.Value, Missing.Value, Missing.Value, <br />
Missing.Value, Missing.Value, Missing.Value, Missing.Value, <br />
Missing.Value, Missing.Value);<br />
Word.MailMerge mailMerge = (Word.MailMerge)doc.MailMerge;<br />
mailMerge.CreateDataSource("Data.doc", Missing.Value, Missing.Value, <br />
"CandidateID, FirstName, LastName, Address",<br />
Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);<br />
Word.Document dataDoc = (Word.Document)word.Documents.Open("Data.doc", <br />
Missing.Value, Missing.Value, Missing.Value, Missing.Value, <br />
Missing.Value, Missing.Value, Missing.Value, Missing.Value, <br />
Missing.Value, Missing.Value, Missing.Value, Missing.Value, <br />
Missing.Value, Missing.Value);<br />
Word.Table tbl = (Word.Table)((Word.Tables)dataDoc.Tables).Item(1);<br />
tbl.Cell(2, 1).Range.InsertAfter(candidateId);<br />
tbl.Cell(2, 2).Range.InsertAfter(firstName);<br />
tbl.Cell(2, 3).Range.InsertAfter(lastName);<br />
tbl.Cell(2, 4).Range.InsertAfter(address);<br />
dataDoc.Save();<br />
dataDoc.Close(Missing.Value, Missing.Value, Missing.Value);<br />
mailMerge.Destination = Word.WdMailMergeDestination.wdSendToPrinter;<br />
mailMerge.Execute(Missing.Value);<br />
doc.Close(Missing.Value, Missing.Value, Missing.Value);<br />
Noam Ben Haim
Web Developer
Intel
noam.ben.chaim@intel.com
|
|
|
|
|
Try null ?
Might not work but it's a clue.
Paul
|
|
|
|
|
string s = @"c:\mydoc.doc";
object so = (object) s;
object o = null;
Word.Document doc = word.Documents.Open(ref so,ref o,ref o,ref o,ref o,ref o,ref o,ref o,ref o,ref o);
(the ref stuff is because the tlbimporter is stupid, and prefers to assume nothing, even when the type-library brings everything top-to-bottom and left-to-right).
Have fun!!
MS quote (http://www.microsoft.com/ddk) : As of September 30, 2002, the Microsoft® Windows® 2000 DDK, the Microsoft Windows 98 DDK, and the Microsoft Windows NT® 4.0 DDK will no longer be available for purchase or download on this site.
|
|
|
|
|
object isVisible = false;
object missing = System.Reflection.Missing.Value;
Word.ApplicationClass WordApp = new Word.ApplicationClass();
WordApp.Visible = false;
WordApp.ScreenUpdating = false;
WordApp.DisplayAlerts = Word.WdAlertLevel.wdAlertsNone;
Word.Document aDoc = WordApp.Documents.Add(ref fileName, ref missing, ref missing, ref isVisible);
aDoc.Activate();
WordApp.ActivePrinter = _DeviceName;
// Office 2000 format
WordApp.ActiveDocument.PrintOut(ref bool_true, ref bool_false, ref missing, ref newFileName,
ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
ref bool_true, ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing);
|
|
|
|
|
Hi.
If I want to connect a printer to a computer port, how do I accomplish that in .NET? Is there something corresponding to the functionality of WNetAdd/CancelConnection?
Still not friends with the .NET documentation
Any help will be most appreciated!
/EnkelIk
|
|
|
|
|
Has anyone had any experience or seen any articles about using AppDomains and the CodeDOM classes in the .NET framework in a similar way to ASP.NET? I would like to be able to compile extension code for my app that provides user specific customisation. Hopefully the extension code will have full access to the object model of my app including instances of objects hosted inside the main AppDomain.
I guess it's the efficiency of marshalling calls between AppDomains that i want to understand so i can make best use of them.
Thanks
Matt
|
|
|
|
|
I am trying to set tags for individual Combobox items. In looking through the Combobox doc, I cannot find the equivalent of SetItemData/GetItemData. The tag property is set at the Combobox level, and not at the item level. Can someone point me to an example, or how to set the tags for invidual combobox items. I would like to store database record ids as tags in the combobox.
Gaulles
Gaulles Technologies, Inc
http://www.gaulles.com
|
|
|
|
|
Unfortunately there isn't. However, if you considered switching to a ListView instead of a ListBox, then you would be able to use the ListItem.Tag property. And, it functions almost like a listbox...kind of.
Norm Almond: I seen some GUI's in my life but WTF is this mess
Leppie: I made an app for my sister and she wouldnt use it till it was colorful enough
Norm:good point leppie, from that statement I can only deduce that this GUI must be aimed at children
Leppie:My sister is 25
-Norm on the MailMagic GUI
|
|
|
|
|
|
Aloha everyone...I have a question:
How can I implement auto-updating to my app? I have created a simple TCP/IP application and I would like the client to be able to get the newest version from the server and overwrite itself with the new version.
Obviously this will create problems with trying to overwrite a file in use, so how do you do it?
- Does .NET provide built in "shadow copying"? (I know ASP.NET does)
- Does Windows provide a service to auto-copy a file once an application closes?
- Is there some black-book trick I am unaware of???
Any help would be really appreciated!
|
|
|
|
|
.NET has several capabilities that you could possibly try. My companies application is Internet-distributed and actually launched from the web and downloaded automatically into the Temporary Assembly Cache (TAC, kept safe from other applications). Based on the .config file on the server that the application uses, we can easily update a DLL, modify the <runtime> section of the .config file and change the binding to the new version, for which the application will automatically grab the new one and download it, inserting it into the AppDomain.
As far as automatically updating files that are in use, you don't really want to overwrite files. This is not necessary and not recommend in .NET. You could install the assemblies in the GAC, for which each one gets a separate directory (for which you don't see) and you can have several versions of assemblies in there. Then, using the application's configuration file, you can use a <bindingredirect> to tell the application (which is bound to a previous version of an assembly) to now use the new one. See the <bindingredirect> element in the .NET Framework docs for more information.
I hope that gives you some insight for ways to keep your application up-to-date on client machines.
"Well, I wouldn't say I've been missing it, Bob." - Peter Gibbons
|
|
|
|
|
I'm sure I read an article on gotdotnet.com about tricklefeeding a .NET app.
Try this.
"Update applications and distribute their pieces automatically using application domains and assemblies."
Quite a few hits on Google too.
Cheers,
Simon
"Sign up for a chance to be among the first to experience the wrath of the gods.", Microsoft's home page (24/06/2002)
|
|
|
|
|
|