|
If one instantiates a form by: myform = new asssetinq(), what 'variable' holds "myform"? In other words, if I have a string variable "formname" defined, and I wish to set this to the form name, how would the command "formname = ????" be written so that formname has the value "myform"? Tons of searching has not yielded a result, so any specific help would be most appreciated!
|
|
|
|
|
The strict answer is string formname="myform"; but that is not what you were hoping.
Variables are defined when you generate the source code, and seldom used afterwards (it would take reflection to get access to some of them).
Abyway, if you have:
Form form1=new Form();
Form form2=form1;
Form form3=form2;
which variable is "holding" the one form?
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
Point taken, although in playing with this, if you use "this" in various syntaxes, I'm getting the title bar verbiage. So things seem to know what form I'm working with. (This code is intended within the keydown event logic of a listview on a form, so even though a few forms may be in the works, the keydown event would be associated with a specific form. I'm just hoping there's a way to retrieve what the form name was. Long story short, I create the forms with a SCO unix process ID value, so these are variable. Short of setting a public string variable to my form name when I create the form, I was hoping there was something identifying that form name.)
|
|
|
|
|
When you create a form, you normally store its reference in a variable, as in MyForm myForm=new MyForm(); so you can always use myForm to act on that one Form.
Furthermore, event handlers associated to myForm get two parameters, the first one (object sender) can be cast to its owner's type to return the real sender, so MyForm me=(MyForm)sender; could be useful, although at the Form level, this most often is all that is required.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
I instantiate the form in a proprietary language, using a "bridge" to the .net world. So this is not a 'normal' way of doing things. I will: "F_1098 = New ERUtil.assetinq();" to create the form in our application software (which is NOT C#), and this bridge makes it happen. "assetinq" is a 'normal' form created in Visual Studio, and so when I'm adding C# code to events associated with controls on this form, I'm finding the need to know what the form name is I've given it (F_1098 in this example), keeping in mind that the form was not instantiated in the C# code, so I don't know in the C# code what the form name is. So in the example below, of code supporting the keydown event of a control "list" on this form:
private void list_KeyDown(object source, KeyEventArgs e)
{
MessageBox.Show(this.ToString());
}
Shows me: "ERUtil.assetinq, Text: Asset Inquiry". Forgive my inability to comprehend your response Luc, as I'm getting my feet wet with C#, and am still far more used to procedural coding than object-oriented code, and C# as a whole. In my example, is there anyway I get "F_1098" into a string in this method, and if so, what specific commands would give me this? (I will assume this is not possible, and thank you for your responses anyway).
|
|
|
|
|
I still don't get the global picture.
It might help telling what you want to do with F_1098 later on.
Here are some facts, maybe they can help:
1.
genisyssoftware wrote: I'm finding the need to know what the form name is I've given it (F_1098 in this example)
F_1098 is NOT the name of the Form, at best it is the name of a variable somehow representing a Form.
The following do exist In System.Windows.Forms:
- Name: a string mainly used by Visual Designer to indicate the name of the variable that was used to create and hold a Control
- Text: the Form's title
- Tag: a free object, you can assign and use any way you like
2.
The name of a variable is pretty useless at run-time, unless your app needs to think about itself, and uses reflection, which is part of .NET
3.
Once the Form is created (with new) you can store its reference in as many Form variables as you like (I have shown that before).
4.
ToString() returns a string; by default it is the type string of the type it belongs to. You can override ToString() to return something else.
5.
Application.OpenForms returns a list of all open windows belonging to your app.
6.
you can store associations (i.e. key-value pairs) in a Dictionary.
Hope some of this may help.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
Lots of helpful notes in your last reply Luc, so thank you. The tag value is giving me what I want. So I'm now setting the tag value to the name that I instantiated the form with, so I can retrieve this form "name" on the C# side. What I need to do in C# is send back to the server formatted commands that resemble what this gui "bridge" does. If I define a form name as F_938, I need to send back "3Click,F_938.SelectButton", for example, to the server. I started out a couple of years ago just creating forms in visual studio, and using this bridge (www.truegui.com) to give our character-based application a gui front-end. While this bridge allowed us to have a more appealing look to our application, there's a lot of I/O between the client and the server. I'm now adding more and more business logic on the C# side (the client side), which means less I/O communication needed between the client and the server (where our old legacy application is running). This is yielding an increase performance in our application, as we continue to migrate from a character-based application to a gui one. If you double-click a line in a listview, for example, the client sends "3DoubleClick,F_828.ListName" to the server, where I then have to ask for the index with "F_828.ListName.LastSelectedIndex?", and will get back the index value, and then I need to retrieve contents of that index with "F_828.ListName.Items[(index value)].Text?", and will get back "2Bob Johnson" for example." So in this simple example, there are 5 I/O elements. I can cut this down to 1 now by having the logic to retrieve the selected contents within the form. My initial question here was a result of me needing to know what "F_828" would be in some cases, so it can be used on the C# side, when the form was instantiated on the server side, through the bridge. I'm sure in this process, this forum will hear from me again Thanks again Luc.
|
|
|
|
|
You're welcome.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
Luc - making progress here, but I'm a bit baffled by what is wrong here in this code:
public static void CloseAllForms()
{
MessageBox.Show("Number of open forms: " + Application.OpenForms.Count);
string tag;
int i=0;
foreach (Form frm in Application.OpenForms)
{
// frm.Dispose();
i = i + 1;
tag = frm.Tag.ToString();
MessageBox.Show("in loop, i="+i+" tag = "+tag);
}
}
What I'm trying to do is go through all the open forms that have a tag value populated, as those would be forms that I opened (The intial count that I display here seems to show more forms than I have opened, but I'll get to the bottom of this once I can figure out the simple things). In this code above, I'd sure think I'd be able to set the tag value to a string, and then display that in this loop. This code compiles, but when I execute it, I only get the initial count displaying, and I get one blank dialog box displaying. If I remove the "tag = frm...." line, the loop displays 4 or 5 times). So there's something I don't yet understand about how to access form names, or forms themselves. I think there's some issues with trying to set the "tag" variable above if the .Tag property has not yet been set on a form, and maybe that's my problem. But if you were to replace my code above with trying to loop through and display the .Tag property of forms, how would you do this? (Keeping in mind that not all open forms may have a tag value set).
|
|
|
|
|
genisyssoftware wrote: Keeping in mind that not all open forms may have a tag value set
You really should take your own advice here. What is in a Tag that hasn't been set by you?
And what happens when you execute null.ToString() ?
Suggestions:
- tell your IDE to always show line numbers in editor windows (for Visual Studio see here[^])
- put one big try-catch around the thing you are experimenting with, and within the catch show the entire Excecption.ToString()
- use the error messages and their line numbers to your advantage to pinpoint to location and cause of the problems you have.
genisyssoftware wrote: // frm.Dispose();
you shouldn't dispose of objects that still are referenced by some collection, unless the very next thing you do is killing the collection too. And you can't kill Application.OpenForms, it isn't even your collection.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
Local announcement (Antwerp region): Lange Wapper? 59.24% waren verstandig genoeg om NEEN te stemmen; bye bye viaduct.
|
|
|
|
|
I implemented your try/catch suggestion (had to investigate the syntax here, as I'm a newbie), and this yielded the problem I had: you cannot set the .Tag property to a string if it is null. So I check for a null first, and things seem to be ok now. I'm still living in the "null is the same as a blank" logic which holds true in everything BUT C# in my experience But there are form names "AutogenForm" and "FrmMain" that are showing up in my "for" loop that I didn't instantiate, so that's why I need to only dispose of the "tagged" forms. (This may be a result of that 'bridge' I use, where maybe embedded - and hidden to me - is the instantiation of these forms, for whatever purpose they are for.). Your other suggestions here are worth noting, so thanks again Luc.
|
|
|
|
|
in many languages obj.method() or obj->method() is the way to apply a method to an object using a reference, sometimes simply called a pointer. You can dereference (i.e. use) a valid pointer, you can't dereference a null-pointer. Not in C/C++/Java/C# anyway.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
Local announcement (Antwerp region): Lange Wapper? 59.24% waren verstandig genoeg om NEEN te stemmen; bye bye viaduct.
|
|
|
|
|
hey guys
I have this code:
axMedia.URL = Application.StartupPath + "\\playlist.asx";
it loads a playlist file and runs it in Media Player Addon.
PlayList file has nodes(tags) of links of websites
<Entry>
<ref href="www.blah.com/well.mp3" />
</Entry>
Am asking how can i check if there is a connection at all or not.
because there is no taste to load a file and computer has no connection to the net.
so before using axMedia.URL="playlist.asx";
i need to ask if there is already connection or not.
thanks.
|
|
|
|
|
Hi,
you can use P/Invoke and some Win32 functions to get Internet connection info; this:
enum LP_InternetConnectionState : int {
Configured=0x40,
LAN=0x02,
Modem=0x01,
OffLine=0x20,
Proxy=0x04,
RAS_installed=0x10
}
public static bool Connected() {
LP_InternetConnectionState description=0;
return InternetGetConnectedState(ref description, 0);
}
public static string ConnectionName {
get {
LP_InternetConnectionState description=0;
StringBuilder sb=new StringBuilder(512);
InternetGetConnectedStateEx(ref description, sb, sb.Capacity, 0);
return sb.ToString()+" ("+description.ToString()+")";
}
}
[DllImport("wininet.dll")]
static extern bool InternetGetConnectedState(ref LP_InternetConnectionState lpdwFlags,
int dwReserved);
[DllImport("wininet.dll")]
static extern bool InternetGetConnectedStateEx(ref LP_InternetConnectionState lpdwFlags,
StringBuilder name, int nameLength, int dwReserved);
should get you started.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
Hi All,
I need to be able to connect to a database on a remote server without using an ODBC connection or anything of that kind. Does anyone know the parameters I would need to include in the connection string to achieve this?
Any help would be really appreciated.
Thanks
|
|
|
|
|
It is very hard to give a definitive answer to this without more detail, such as what type of database and so on but you could take a look on connectionstrings.com[^], which has details for most scenarios.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Hi Henry,
Thanks for your feedback.
Sorry about the lack of information. It's a SQL Anywhere 10 database that I'm trying to connect to and I'm writing in C# within the .NET framework.
Please let me know if there is any other information I can give you that would be helpful.
Thanks again,
MWRivera
|
|
|
|
|
Did you try the connectionstrings.com link I gave?
I have found for version 11[^], don't know if it will help for V 10 though as I'm not familiar with SQL Anywhere.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Henry,
Thanks I was able to connect after visiting the site you referred.
I had to play around with a combination of connects but got there in the end
The connection string is:
ENG=serverName;DBN=databaseName;Uid=username;Pwd=password;Links=tcpip(Host=server);
Do you know if the connection is using anything in particular to connect ADO.net or anything like that? Or is this a straight connection to the server (if that's at all possible).
Thanks again
|
|
|
|
|
MWRivera wrote: Do you know if the connection is using anything in particular to connect ADO.net or anything like that? Or is this a straight connection to the server (if that's at all possible).
That depends as much on the code that you have that uses the connection string. However it looks very much like ADO.Net.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Hello i have to create an application that read an existing drawing file .DWG and then aorder a robot to cut the shape drawin in a tissue
any help , which tools i should use , i am thinking about microsoft robotics and c#?
|
|
|
|
|
That's an ambitious task - this is for school ? Have you worked with Autocad in C# before ?
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Hi
I have a void method which has an interface passing parameters in and parameters going out. This method is in one Visual Studio Project. However, when I open up my other Visual Studio Project which has a service reference to the other Visual Studio Project, and call the method, I can only see my in parameters and not out parameters. If I change the method to a function I can see both, but I don't want a function!
Can someone please explain why this is the case? Am I missing something?
Please help!
|
|
|
|
|
Hi,
in C# all callable code units are called methods, whether they return something or not (as opposed to Fortran or Basic subroutines and functions). And the behavior of parameters is independent of the return type.
So I suggest to check your facts again; if need be, show us the one that works well and the one that fails.
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
Since you are speaking about a Service Reference, I assume you are using WCF.
Apparently, WCF supports out parameters in operations (I didn't think it did), but can have some tricky behaviors with them (look this discussion, for instance).
I strongly suggest you to refactor it by changing the out parameter to return value, since your method don't already has one. Really, that will be effectively the same.
|
|
|
|
|