|
Nazila I thought I might give you a different twist on your question. I write classes that overloaded the toString()'s (if I am being lazy I make them methods) so that I can always get my variables back with the correctly. Example
public class AccessDb
{ //in my data object
public int pInt(int intIn) // This is the lazy way
{// this is only an example I would use inherited base classes and
// overloading the toString it is so much cleaner.
return "'" + intIn.toString() + "'"
}
}
// then later in your Business object code
AccessDB db = new AccessDb();
db.Update("update table set field=" + db.pInt(intvariable)+ "where otherfield=yes");
I started doing this so I don't get caught recoding everytime the database gets switched from Access to MySql or something else happens. I really like insulating the data objects from the business objects and this is a big help in making generic interfaces. My applications can switch database backends by setting preferences which makes my life much better. It is very important to read up on your database access in .Net and get your design down solid first you will need this when you are setting up the data classes. There are a couple of really cool articles on how to implement this.
Let me know what you think of the idea.
Kevin
|
|
|
|
|
Hi,
I'm working with Arrays of strings for which I don't know the Length beforehand. Because I have a boatload of code that needs to index these arrays, I don't want to embed every single line in a try{} block or have an if() statement on every line without looking at other approaches that would save me some syntax. Basically, I want my program to return zero instead of throwing IndexOutOfRangeException. Can anybody point me in the right direction for this?
Thanks,
John
|
|
|
|
|
The only way to do this AFAIK is to create a wrapper class for the array that gives you the behaviour you want. If it's an array of strings, why/how can you return 0, or do you mean an empty string ?
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
Yes, I meant to write empty string. Which leads to my next question, is there some way I can use the Convert.ToInt32, Convert.ToDouble, etc, and have them return 0 if the string is unrecognized?
I spent a minute writing a class that derives from Array but got an error "cannot inheret from special class System.Array." But I'll research that route more thoroughly now.
|
|
|
|
|
Same answer - you can't inherit, you need to contain, your class HAS an array, you can't write a class that IS A array.
So you need a class with static methods that call Convert.ToWhatever, and handle failure the way you want them to.
I'm not suggesting this is a good idea.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
Okay, that makes sense. I'll try that. Thanks.
|
|
|
|
|
Perl has made me very soft.
c# is sharpening me up again.
Rgds,
Ian
|
|
|
|
|
Hi everybody
I an all the examples that I have studied so far with regards to remoting there is a server and many clients that communicate with it using either TCP/IP or HTTP. What kind of communication protocol can we use for the case of windows forms that communicate with other windows forms and need to pass data to them. So instead of having a pool of sockets to connect, we have the server (window form father) to create and then send data to the new window form (window form child) and then wait until the child window returns some results. If we use TCP/IP and config files all child processes will use the same port. From my small exeprience I believe that this is at least incorrect. So my question is: does anyone know am effective way to perform that type of communication?
Thank you very much for your time.
Spiros Prantalos
Miami the place to be!!
|
|
|
|
|
The whole application runs on Window Terminal Server
Spiros Prantalos
Miami the place to be!!
|
|
|
|
|
Using a TcpChannel is typical for remoting between app domains on the same machine. There is far less overhead than with HTTP (a protocol over TCP/IP). Using a .config file for remoting configuration (by calling RemotingConfiguration.Configure ) does offer benefits over manual configuration, but you can still specify ports. Each application will have it's own configuration file (named yourappname.exe.config) so you can configure clients to use the same or different ports. Of course, applications that need to communicate with each other via remoting must use the same port. Also note that with remoting, you don't have to use the typical client-server setup. Clients can talk to each other as well as can servers; in essence, each application acts as a client and server (sending requests and getting responses back for both applications).
You should pick up the book ".NET Remoting" from MSPress. It's a good introduction to remoting and covers lots of intermediate and some advanced techniques and topics.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Thank you for your help.
After some research I found the following:
--
Let's assume you have two Windows Forms applications, running on a single machine and you want the two applications to be able to communicate with each other. Or suppose you have a Windows service which should exchange data with your GUI application. Which protocol can you use? Remoting!
This is one of the cases where the TCPChannel is extremely helpful as it allows you to specify rejectRemoteRequests="true" upon its construction which limits all incoming connections to the ones originating from your own machine. No need to take too many precautions about security in this case.
However: If you use fixed port numbers for WinForms to WinForms communication, you might run into troubles when running on Windows Terminal Services with two or more users trying to use your application at the same time
--
Unfortunately this is my case.
Spiros Prantalos
Miami the place to be!!
|
|
|
|
|
Okay, sorry, didn't understand quite what you were asking in the first post.
You could have a remoting object that merely keeps track of which ports are currently being used by a pair of applications, and perhaps even hands out ports to use. Of course, you'd have to configure the remote objects yourself, but this isn't a difficult thing (just more difficult to change since you have to recompile for some things).
If security is an issue, you could assign each user a key (if you have ActiveDirectory with Certificate Services installed and setup, just use the user's key) to communicate between application domains. If you configure the apps to use the same port, of course only the first user would be able to run it.
Finally, if you use a client-server type setup, you could use single call well-known objects so that multiple users don't interact with each other's sessions.
Just a couple of thoughts.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Hi i am inetrested in finding out if the caplock button is active or not ... Thats when the form loads... or if there is a way to like toggle the button to disable when it loads ...
Thanks
DaIn
|
|
|
|
|
P/Invoke the native function GetKeyState :
[DllImport("user32.dll")]
private static extern short GetKeyState(int virtKey); You would then pass 20 (VK_CAPITAL ) to get the CAPS LOCK key state. Fortunately (for good reason), the System.Windows.Forms.Keys enumeration members match up with the virtual key constants defined in winuser.h, so you can use (int)Keys.CapsLock instead for more readable code:
short value = GetKeyState((int)Keys.CapsLock);
bool on = (value & 0x0001) != 0;
myButton.Enabled = !on; It's important to mask out the high-order bit so you can check the status of the low-order bit. This is documented in the Platform SDK documentation for the GetKeyState , see so that for more information.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Before I go re-inventing the wheel, can anyone tell me if they have an SSL Stream Socket class? I already use TCP based cleartext socket communications to a server and want to enable SSL support for the same protocol going through an SSL proxy.
|
|
|
|
|
Mentalis.org (http://www.mentalis.org/soft/projects/seclib/) has a SSL Socket Class Library. It implements a SSL version of the Socket, NetworkStream, TcpClient, and TcpListener classes.
|
|
|
|
|
How do you add the bitmaps (without pulling teeth) to the menus?
Larry J. Siddens
|
|
|
|
|
Dr. GUI on MSDN had an article some time back that presented a pretty easy way of doing it: http://msdn.microsoft.com/library/en-us/dnaskdr/html/askgui11062001.asp[^].
You should also check out the articles here on CodeProject by searching the site. There has been several articles discussing other ways or even providing libraries if you don't want to write your own.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
So, there is no easy way to enable the XP styles for the menus like you can for the controls? Fooie!
Larry J. Siddens
|
|
|
|
|
XP visual styles have nothing to do with bitmaps on menu items. They are entirely independent of each other. You asked about menu item bitmaps - not XP visual styles.
I have written an article on XP visual styles here: http://www.codeproject.com/csharp/dotnetvisualstyles.asp[^]
If you are using .NET 1.1 or higher, you can also call Application.EnableVisualStyles() before you call Application.Run in your entry point method (Main ). That's also mentioned in the article forum for the article link I gave you above.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
You could use the Magic Library. It has Windox XP style menu components. You can get it on the code project site.
|
|
|
|
|
The user is going to be able to move listbox items up and down in the listbox. I want to use two buttons with upp-and-down arrows. Like the characters < and > but rotate them så they point up or down instead
Rickard Andersson
Here is my card, contact me later!
UIN: 50302279
Sonork: 37318
|
|
|
|
|
So what's the problem? You want to know how to do it?
Either make a couple of images and use them on a couple of Button objects, or set the Font for the Button objects to Wingdings or something and choose the appropriate character for an up or down button (there are several). Use the Character Map application in Windows to help find which one is appropriate (Start->Programs->Accessories->System Tools->Character Map).
Using images as embedded resources in the dialogs you see with up/down arrows is what the .NET BCL uses, but either way works. Using a font to do it will also allow the arrows to match the system's current ControlText color.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Heath Stewart wrote:
Either make a couple of images and use them on a couple of Button objects, or set the Font for the Button objects to Wingdings or something and choose the appropriate character for an up or down button (there are several). Use the Character Map application in Windows to help find which one is appropriate (Start->Programs->Accessories->System Tools->Character Map).
doh...
Thanks, I didn't think that far.
Rickard Andersson
Here is my card, contact me later!
UIN: 50302279
Sonork: 37318
|
|
|
|
|
In my app I want to create some tool windows, which can be auto-hide and docking like that tool windows of VS.net, with VC++.net. But I looked the MSDN and some samples, the tool window is like only to be created as addin to be used by other app. Please tell me how to do, thank you very much.
If you have some samples , could you send to me?
|
|
|
|