|
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
|
|
|
|
|
|
I am wondering what is the best way to store data like email accounts and what not for a email program(checks if you ahve new mail).
Thanks!
|
|
|
|
|
it really depends on what exactly your doing with your data. if you are going to be doing a bunch of lookups, then consider a Hashtable, but remember for efficiency to implement your own HashProvider and Comparer.
see Hashtable in MSDN for more information
Soliant | email
"The 'B' in Visual Basic means Beginner" - R. Bischoff
|
|
|
|
|
I am posting this here in case anyone has an idea or can help...
Ok, I understand that the NetServerEnum API (netapi.dll) functions do not work on a Win9x machine. In VB6, I had code to enumerate Servers on a Windows9x machine, however, porting it to VB.NET seems impossible. I have it working...somewhat. However, it only enumerates the Top-Level Node everytime!
If someone could please shed some light on what I am doing wrong I would greatly appreciate it! This was all guess-work on my part even though I understand Marshalling a little bit.
Here's what I have so far:
'Declarations
'API Declarations
Private Declare Auto Function GlobalAlloc Lib "kernel32" (ByVal wFlags As Integer, ByVal dwBytes As Integer) As Integer
Private Declare Auto Function GlobalFree Lib "kernel32" (ByVal hMem As Integer) As Integer
'API Declarations for Win9x
Private Declare Ansi Function WNetOpenEnum Lib "mpr.dll" Alias "WNetOpenEnumA" (ByVal dwScope As Integer, ByVal dwType As Integer, ByVal dwUsage As Integer, ByRef lpNetResource As IntPtr, ByRef lphEnum As Integer) As Integer
Private Declare Ansi Function WNetEnumResource Lib "mpr.dll" Alias "WNetEnumResourceA" (ByVal hEnum As Integer, ByRef lpcCount As Integer, ByVal lpBuffer As Integer, ByRef lpBufferSize As Integer) As Integer
Private Declare Ansi Function WNetCloseEnum Lib "mpr.dll" (ByVal hEnum As Integer) As Integer
'Structures
<Runtime.InteropServices.StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi)> _
Private Structure NETRESOURCE
Dim Scope As Integer
Dim Type As Integer
Dim DisplayType As Integer
Dim Usage As Integer
Dim LocalName As IntPtr
Dim RemoteName As IntPtr
Dim Comment As IntPtr
Dim Provider As IntPtr
End Structure
'Constants for WNetEnum
Private Enum ResourceScopes
resConnected = &H1 'All currently connected resources (the dwUsage parameter is ignored)
resGlobalNet = &H2 'All resources on the network.
resRemembered = &H3 'All remembered (persistent) connections (dwUsage is ignored)
resRecent = &H4
resContext = &H5
End Enum
Private Enum ResourceTypes
resAny = &H0 'All resources (this value cannot be combined with RESOURCETYPE_DISK or RESOURCETYPE_PRINT).
resDisk = &H1 'All disk resources.
resPrinter = &H2 'All print resources.
resReserved = &H8
resUnknown = &HFFFF
End Enum
Private Enum ResourceUseages 'Ignored if the ResourceScope is not 'resGlobalNet'
resAll = ((&H1) Or (&H2))
resConnectable = &H1
resContainer = &H2
resNoLocalDevice = &H4
resSibling = &H8
resReserved = &H80000000
End Enum
Private Enum ResourceDisplayTypes 'Used to Determine the Resource Type of the NETRESOURCE Struct
resGeneric = &H0
resDomain = &H1
resServer = &H2
resShare = &H3
resFile = &H4
resGroup = &H5
resNetwork = &H6
resRoot = &H7
resShareAdmin = &H8
resDirectory = &H9
resTree = &HA
End Enum
'Enumerations
Public Enum ServerTypes
All = &HFFFFFFFF '/* handy for NetServerEnum2 */
Browsers = &H10000
Browser_Backup = &H20000
Browser_Master = &H40000
Domains = &H80000000
DomainController = &H8
DomainBackController = &H10
DomainMaster = &H80000
DomainMember = &H100
Novell = &H80
NTClusters = &H1000000 '/* NT Cluster */
Servers = &H2 ' All Servers
ServersDialIn = &H400
ServersLocal = &H40000000
ServersPrintQ = &H200
ServersNT = &H8000
ServersSQL = &H4 ' SQL Server
ServersXenix = &H800
ServersUnix = &H800
TimeServers = &H20
Workstations = &H1
WorkstationsNT = &H1000
WorkstationsWin9x = &H400000 '/* Windows95 and above */
End Enum
'Routine to Refresh Servers on a Win9x Machine (uses Recursion)
Private Sub RefreshServersWin9x(Optional ByVal Domain As String = Nothing)
Dim vResource As NETRESOURCE
Dim hResult, hEnum, hBuffer, hPointer, i As Integer
Dim nBufferSize As Integer = 16384, nCount As Integer = &HFFFFFFFF
Const GMEM_FIXED As Integer = &H0
Const GMEM_ZEROINIT As Integer = &H40
Const GPTR As Integer = (GMEM_FIXED Or GMEM_ZEROINIT)
'Initialize the Buffer Pointer
Dim ptrBuffer As IntPtr = IntPtr.Zero, ptrDomain As IntPtr = IntPtr.Zero
If (Not IsNothing(Domain)) AndAlso (Domain.Length > 0) Then
ptrDomain = Marshal.StringToBSTR(Domain)
ptrBuffer = Marshal.AllocCoTaskMem(Marshal.SizeOf(vResource))
vResource.RemoteName = ptrDomain
Call Marshal.StructureToPtr(vResource, ptrBuffer, True)
End If
Try
hResult = WNetOpenEnum(ResourceScopes.resGlobalNet, ResourceTypes.resAny, ResourceUseages.resContainer, ptrBuffer, hEnum)
If (hResult = 0) And (hEnum <> 0) Then 'Successful
'Enumerate the Resource
hBuffer = GlobalAlloc(GPTR, nBufferSize)
hResult = WNetEnumResource(hEnum, nCount, hBuffer, nBufferSize)
If (hResult = 0) Then 'Successful
hPointer = hBuffer
For i = 0 To nCount - 1
'Retrieve the Information for the Resource
vResource = CType(Marshal.PtrToStructure(New IntPtr(hPointer), GetType(NETRESOURCE)), NETRESOURCE)
'Recurse to Find the Servers if this is a Root or Domain Node
Select Case vResource.DisplayType
Case ResourceDisplayTypes.resDomain, ResourceDisplayTypes.resGroup, ResourceDisplayTypes.resNetwork, ResourceDisplayTypes.resRoot
Call Me.RefreshServersWin9x(Marshal.PtrToStringAnsi(vResource.RemoteName))
End Select
'Determine the Next Pointer
hPointer += Marshal.SizeOf(vResource)
Next i
End If
End If
bInitialized = True
Catch
'Call Globals.ErrorMessage("Refresh")
Finally
'Free Up Memory
Call Marshal.FreeCoTaskMem(ptrBuffer)
Call Marshal.FreeCoTaskMem(ptrDomain)
If (hEnum > 0) Then hResult = WNetCloseEnum(hEnum)
If (hBuffer > 0) Then hResult = GlobalFree(hBuffer)
End Try
End Sub
|
|
|
|
|
maybe try posting this in the VB.NET section
Soliant | email
"The 'B' in Visual Basic means Beginner" - R. Bischoff
|
|
|
|
|
Nevermind, I figured it out!
|
|
|
|