|
Um, perhaps in your form OnLoad :
MyControl.Site = (ISite)this;
"The greatest danger to humanity is humanity without an open mind." - Ian Mariano
http://www.ian-space.com/
|
|
|
|
|
Surely you havent got to wire this stuff up yourself? I may as well write my own Parent property if that were the case...
Anyone?
Pete
Pete
Insert Sig. Here!
|
|
|
|
|
Prepare a constructor with a IContainer param. This will be used to pass the parent. In System.Windows.Forms.Timer :
public Timer() : base() {
this.interval = 100;
}
public Timer(IContainer container) {
this = new Timer();
container.Add(this);
}
As you can see, this code doesn't store the reference to the parent anywhere, but that's up to you to do so.
Back to real work : D-28.
|
|
|
|
|
Nice... Thanks a lot. I'll have a got with this later this morning.
Cheers.
Pete
Insert Sig. Here!
|
|
|
|
|
Hi again.
Yeah, that works. The form code generator automatically adds the code to pass the components object to the constrctor and everything.
Unfortuantly, I have not idea of how to navigate from that Component object to the actual Form object, which is what I am interested in. Any ideas?
Surely the framework includes this? Or Maybe a Component based object is not what I want here?
Basically, what I'm after is the same as the Parent property on a Control. Except I'm not building a visible control, just a component that adds some event handlers to the forms events and does some processing based on them.
BTW, the Timer was just an example, I'm not actually using a timer...
Thanks
Guys.
Pete
Insert Sig. Here!
|
|
|
|
|
Pete Bassett wrote:
just a component that adds some event handlers to the forms events and does some processing based on them.
This is a different topic now.
To get it done, you need to declare a delegate, an event object, an eventarg object, and a handler. Adding this to a Form-derived class, along with appropriate [design-time] attributes will make the event handlers show in the Form designer.
Whenever the event handler is actually subscribed for, you have internal code executed where you can process the event using another component (non-visible if you like) of yours.
All you need is a good sample to start with. There are articles about new event creation on CP (C# programming section), MSDN, ...
Back to real work : D-27.
|
|
|
|
|
No, sorry for the confusion.
I understand all about event handlers etc etc etc. I just need a reference to the Form-derived object inside my Component. Thats all.
You told me to write the Constructor with one IContainer param and this works correctly, but I need a reference to the actual Form, not its internal Container.
Once I have the reference to the Form it will all work because all the rest of the code is written...
Have I explained the problem correctly now? Thanks again.
Pete
Insert Sig. Here!
|
|
|
|
|
I think I know what you mean...I had something similar where I wanted to get the HWND of the MainAppwindow wher I would "drop" the component, although there was no interaction with the window, it still needed to know this...
I wonder how this can be done? All my attempts were failures
"There are no stupid question's, just stupid people."
|
|
|
|
|
This one[^] might help, in conjunction with the IContainer.Add(this) mentioned above.
Back to real work : D-27.
|
|
|
|
|
Hi again.
I've had a look at the code but I don't think its the way.
I'm starting to think this isn't possible at all.
Well, thank you (all) again. I'll investigate some more and post back.
Pete
Pete
Insert Sig. Here!
|
|
|
|
|
Add form reference property in your component, and assign it when you initialize your component:
public class MyComponent : System.ComponentModel.Component
{
private Form m_oMyParent;
public Form Parent
{
get { return m_oMyParent; }
set { m_oMyParent = value; }
}
}
m_oMyComponent.Parent = this;
|
|
|
|
|
Hi.
Yes, I did this right at the start when I couldn't figure out how to do it automatically. This whole thread is just me trying to fine a more elegant way of doing this. i.e. without the client having to write any code.
Thanks again.
Pete
Pete
Insert Sig. Here!
|
|
|
|
|
How do i tell if the context menu has disappeared?
1001111111011101111100111100101011110011110100101110010011010010 Sonork | 100.21142 | TheEclypse
|
|
|
|
|
A context menu triggers commands. So once commands are triggered, the context menu has disappeared. This is a simple enough application logic!
Internally, the System.Windows.Forms.ContextMenu class is just a tiny wrapper on top of the WIN32 TrackPopupMenuEx API call. And as you'll see in the doc, one of the param passed in order to create and show a popup menu is the owning window. Which means this window gets notified of everything.
Back to real work : D-28.
|
|
|
|
|
Thankyou. You answered the question just how i like it, a nudge in the right direction, rather than a spoon fed answer
1001111111011101111100111100101011110011110100101110010011010010 Sonork | 100.21142 | TheEclypse
|
|
|
|
|
Hello!
I'm writing a personal account management program that relies on a sql server database. I have the following problem: I would like to ensure, that the sql server db can only be modified by my program (and the server administrator of course, i.e. me ). I considered creating a db user account with read/write access and accessing the server through this account. But even then I have to store the name and password somewhere in my application - which could easily be extracted, esp. with .net apps (Anakrino, ILDASM).
Is there any way to encrypt the password, without exposing the encryption mechanism and encryption keys (Anakrino, ILDASM)
I'm a bit lost
any help appreciated
Martin
"Situation normal - all fu***d up"
Illuminatus!
|
|
|
|
|
Martin Häsemeyer wrote:
Is there any way to encrypt the password, without exposing the encryption mechanism and encryption keys (Anakrino, ILDASM)
I know you are not working with ASP.NET , but have a look at FormsAuthentication.HashPasswordForStoringInConfigFile() method, it could be handy
"There are no stupid question's, just stupid people."
|
|
|
|
|
Hi!
Thanks for the answer but as I understand hash algorythms it is not possible to reconstruct the password from the hash. Therefore this can only be used to compare an entered password with the stored one (I use this technique for the passwords stored in my db with the System.Cryptography namespace). But what I need is a way to store the password so that I can send it to the sql serve and that the server can *understand* it, but my users can't. This means I must be able to decrypt the password without revealing the mechanism to the users...
Cheers
Martin
"Situation normal - all fu***d up"
Illuminatus!
|
|
|
|
|
Martin Häsemeyer wrote:
But what I need is a way to store the password so that I can send it to the sql serve and that the server can *understand* it, but my users can't. This means I must be able to decrypt the password without revealing the mechanism to the users...
Pretty clever users I understand your problem better now, but cant think of way you can "hide" password...
"There are no stupid question's, just stupid people."
|
|
|
|
|
leppie wrote:
Pretty clever users
Yeah I know - but as it is almost sure that no one except myself will use the application it isn't that important anyway - but I'm a little perfectionistic (can you say that in english?) in this way.
Thanks for your thoughts.
Have a nice weekend
Martin
"Situation normal - all fu***d up"
Illuminatus!
|
|
|
|
|
I would create two db user accounts. One with the most basic permissions needed to operate as a normal user. Then create another account that is more privledged.
Store the username/pwd for the first in the program/config file. For the second store just the username and an encrypted version of the password. Base the encryption of the db password on a password you must supply when logging into the program for admin operations. [You need to make sure that when you change the password used to login you re-encrypt the admin db password as well].
A quick look through the Cryptography namespace tells me that the DES algorithm could be used to do what I outline above. There are probably other algorithm's available but that was the first one I found.
James
Sig code stolen from David Wulff
|
|
|
|
|
The String object is immutable. It cannot be changed. Those methods are not void (meaning they don't return anything) however, they do return a string . So what you need to do is:
string lowerStr = col.ColumnName[0].ToString();
lowerStr = lowerStr.ToLower();
string variableStr = lowerStr + col.ColumnName.Substring(1);
And, it would be even better if you did this:
string lowerStr = col.ColumnName[0].ToString().ToLower();
string variableStr = lowerStr + col.ColumnName.Substring(1);
Hope that helps...
You will now find yourself in a wonderous, magical place, filled with talking gnomes, mythical squirrels, and, almost as an afterthought, your bookmarks
-Shog9 teaching Mel Feik how to bookmark
I don't know whether it's just the light but I swear the database server gives me dirty looks everytime I wander past.
-Chris Maunder
|
|
|
|
|
This is a question displaying my incompetence.
I cannot figure out how to pass an event to the parent form.
Here is an example. I have a form and a button on it. If the mouse enters the form and event is fired, when the mouse moves over the button, the I want to call the event handler of the parent. I want to generalize this (as if I use a custom button).
|
|
|
|
|
I think you would have probably figured it out by now if you were thinking in reverse. Instead of asking how you can pass the event to the parent, ask how the parent can susbcribe to the child's event. It's not much different, but it helps to think about it that way.
The functionality you are looking for will be coded the exact same way you code a handler for a button click.
To continue the explanation, you would need something like this (in the parent form):
this.YourButton.MouseEnter += new EventHandler(this.MouseEnteredChild);
Of course, you'd have to have a function in the parent form of the type
private void MouseEnteredChild(object sender, EventArgs args){}
John
|
|
|
|
|