|
I guess you have to provide username and password of your database in youur connection string so it won't ask for it.
Mazy
"One who dives deep gets the pearls,the burning desire for realization brings the goal nearer." - Babuji
|
|
|
|
|
How can I create contols on a form with the data from a loaded object (I load it from a file)? Where do I put the code that creates this controls in order for them to be visible as long as the form is visible? I suppose I cannot instantiate them in a method of the form's class because in this case they will be treated as locals. Is there a way to make them global in the form's class, if I don't know how many controls do I have to instantiate (this depends on the data that the loaded object gives me)?
I dont't know if I've been clear enough but I hope you can help me or give me an advice.
Thanks!
Best regards,
Cristina
|
|
|
|
|
Hi Cristina!
After creating your controls you have to add them to the controls collection of your form to be visible. Therefor you can use either Controls.Add or Controls.AddRange depending on how many controls you want to add.
Take a look at the "Windows Form Designer generated code" region to see how your form gets created to get an idea on how to use this.
Hope this helps 
|
|
|
|
|
As far as reading controls from a file, that is entirely up to you. You could use a runtime serialization format (better for saving state), or an XML format (as many do), or make up some crazy format of your own. As you read this file in, you use reflection to create the types (like using Type.GetType to get the type and Activator.CreateInstance to create an instance of that type) and then setting properties, etc.
There are already many projects out there. I recommend MyXaml[^] from CP's own Marc Clifton, which even has the attention of Microsofties. It already provides a pretty complete framework for doing this. There's already projects out there that do this - many of which are free to use. It's not as easy to do as you might think.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
(new to c#)
I'm trying to use the Find method to search text in a richtextbox...
eg.
myTextBox.Find("Text",0,RichTextBoxFinds.WholeWord);
The problem is I want to combine RichTextBoxFinds options
- WholeWord (value = 2)
- MatchCase (value = 4)
- Reverse (value = 16)
The microsoft web site says:
"You can combine one or more values from this enumeration to specify more than one search option when calling the Find method."
Can anyone show me (in code) how I'd use the values? Do you add them together, or list them?
Thanks,
Ron
|
|
|
|
|
hi Ron,
You can specify multiple enumerations by using "|" character between the enums... like :
myTextBox.Find("Text",0,RichTextBoxFinds.WholeWord | RichTextBoxFinds.MatchCase);
regards,
Aryadip.
Cheers !! and have a Funky day !!
|
|
|
|
|
Cool, works like a charm... thanks Aryadip!
So what's up with the values though, can you use them instead of the text?
Ron
|
|
|
|
|
Hey,
Anybody know how to generate a LM and NT hashes? This is for generating samba passwords.
Sample C# code would be greatly appreciated. Im writing a windows forms application. I need to be able to get text from a text box hash it to LM and NT then write it to my ldap server.
Cheers,
Rhys
|
|
|
|
|
First of all, it's "NTLM" not "LM and NT". It stands for "Windows NT LAN Manager". The older "LM" just refers to LAN Manager (before NT, but still supported in part).
Second of all, it's not just a simple hash like MD5 or SHA1. The server creates a 16-byte random number (the challenge). The client hashes the password and encrypts the challenge with it. This is the response. If it's the client hash you're talking about, this is described in the Samba ENCRYPTION[^] documentation.
Why are you communicating with the LDAP server directly, though? If possible, you should use the negotiate security package, or Windows Integrated security. Since the hash of the password will always be the same, sending across the wire would be subject to replay attacks. A cracker wouldn't need the plain-text password - the hash would suffice, which is why the server sends a challenge to the client with either authentication request to be encrypted (the response).
You should go through the proper "channels" to authenticate the user, not do it yourself. One such easy way is to call the LogonUser API. This negotiates the security package and authenticates the user. If youre LDAP server is part of the Active Directory domain, there should be no problems doing it this way.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Aight, cool thanks for that, that clears things up for me a bit.
I'll give a little more background... My clients/users will be authenicating with with samba. My openldap Server is being used for a samba backend. I am writing a windows app to manage the directory backend, that is adding users and so on. The directory seems to store the the password in two seperate attributes: sambaLMpassword and sambaNTpassword.
Currently I have to two ways of adding users: (1)using the smbpasswd samba tool wich generates the passwords it self and (2)also the idealx smbldap-tools, wich use a little linux util called mkntpwd wich when you feed it a string it spits out two hases a LM and a NT. Both of these are command line tools, I'd like to try my hand a creating a small and usable windows GUI.
Kind Regards,
Rhys
|
|
|
|
|
My suggestion would be, then, to find the source for those two utilities. Being open-source software, it's around somewhere. You might check the Samba web site[^]. They probably have CVS instructions somewhere - typically - to download the source. You could see how they do it, then.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I have the following code but i don't know c++ language.
How to write in C# language ?
http://www.codeguru.com/Cpp/controls/treeview/misc-advanced/article.php/c679/
Anybody can ?
|
|
|
|
|
We LEARN by doing!
At least make an attempt at it, then we can help you with any problems. If you read the code and then look up keywords in the Visual Studio Help for C++, you can read what it does and translate into C#. C# and C++ are different languages, but not as much as you might think.
RageInTheMachine9532
|
|
|
|
|
Just wondering how this can be accomplished? I've played with fraps so I know it can be done. Just wondering how difficult ^^
|
|
|
|
|
Hi. I'm new to C# and I'm trying to create
C# implementations of Controls I did in
Delphi in the past. In Delphi there is
a flag 'csDesigning' that will be set in
'ComponentState' if you're in design mode.
Using that I can do stuff like create a
Guid String to get a unique program ID
and the control can do stuff like File
Mapping or whatever to share data between
instances of the same app etc..
In C# I see something called 'DesignMode'
but it seems like it's always false!
Is there an easy way to set properties
when a UserControl is dropped on a form
that will be the same for all instances
of the application?
IOW, if I create a Guid String just using
a constructor I'll get a different string
for each app instance when I want the
property values to be the same for all
app instances, but be unique in each
app where the control is used.
This one has me baffled!
TIA
|
|
|
|
|
hi,
Well at design time youi can set a default value to whatever property you are defining in your custom control. Here is the way to do that
// Attribute applied to a property.
[DefaultValue(false)]
public new bool TabStop {...
}
and also you can use
System.Windows.Forms.Design.ControlDesigner
class to give the design time support to your control. Here you need to override the Initialize method to do all your custom setting of properties.
Hope this helps you...
regards,
Aryadip.
Cheers !! and have a Funky day !!
|
|
|
|
|
Wow! That's like, way too much work.
All I'm trying to do is create a convenience
where a component is dropped on a form and
a unique string is generated to ID the app
as a property of the component.
I'm coding a simple instance component where
the programmer can set the number of concurrent
instances allowed to run on the same machine.
In the Delphi version (s)he just has to drop
it on the form and call one method on app startup.
Looks like in C# I'll have to settle for a string
property with a suggestive name( "GuidString" )
to hint that the programmer should use a Guid
Generator utility to paste a unique string in
this property. It works just as well but it's just cooler if it would fill in without the programmer's intervention. Unfortunately
with C# if you use any contructor you get
a different Guid every time the form is
created, which is no good for my purpose.
Oh well.. can't have everything I guess!
Thanks for the info. I would have looked
around for days only to find there ain't
no easy way to do it!
|
|
|
|
|
Just FYI after playing around for
about 6 hours I hacked my way into
a component that will initialize
the way I want when dropped on
a form.
Maybe I'll work up a short article
showing how 'cause it's definitely
a feature that's very convenient.
When my C# programming book arrives
in the mail I'll consult that first
of course.
|
|
|
|
|
I am trying to customize PrintPreviewDialog for changing functionality of existing buttoms and add a few new buttons using C#, please tell me which dll need to be imported and what are the various methods available or need to be overriden for the same.
Sample code will help a lot.
regards
|
|
|
|
|
Did you read the documentation for the PrintPreviewDialog ? It states right at the bottom: the System.Windows.Forms.dll assembly. Read the documentation to learn what you can override. You will need to use Reflection to change existing behavior for buttons and other controls, however. The PrintPreviewDialog extends Form and just hosts a PrintPreviewControl with some buttons and combo boxes. You might consider a similar approach which would be easier depending on how much you want to change.
Just extend the Form class and host an instance of the PrintPreviewControl . Add your own controls and behavior to the form.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks for your valuable suggestion. I am using PrintPreviewControl to make customized dialog, but the problem is that, how to integrate vertical scroll bar with next/previous page in co-ordination with the present zoom status. please do suggest
regards
|
|
|
|
|
I suggest you look at how the PrintPreviewDialog works. Download something like .NET Reflector[^] and find the PrintPreviewDialog in the System.Windows.Forms assembly. Use the decompiler to see how it works.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I can't find the equivalent to PostMessage in Windows Forms. I'm currently using BeginInvoke, as it's much like it, but then I get memory leaks, since I ignore the AsyncResults. What should I do with them? Store them in a queue which I walk through later to see if the Completedflag is set and can then safelly call endinvoke?
Thanks in advance
|
|
|
|
|
You won't get memory leaks if you ignore AsyncResult s. .NET is GC'd. More than likely you're not using Control.InvokeRequired and Control.Invoke to call methods and get/set properties on controls created in a different thread. This is a common problem. When you comunicate with a control that was created on a different thread (the UI thread), you must use the ISynchronizeInvoke impementation that every control inherits from Control . This makes sure that communciate with the control happens in the UI thread.
If you want PostMessage , why not just P/Invoke it? If you read the forms, we're continually telling people to P/Invoke SendMessage to send the message immediately, but P/Invoking PostMessage is really no different. It would just look like this:
[DllImport("user32.dll")]
private static extern bool PostMessage(
IntPtr hWnd,
[MarshalAs(UnmanagedType.U4)] int msg,
IntPtr wParam,
IntPtr lParam); If you need to pass a struct or reference to a struct or something, instead of marshaling the struct yourself and passing it as an IntPtr , you could overload PostMessage like so:
[DllImport("user32.dll")]
private static extern bool PostMessage(
IntPtr hWnd,
[MarshalAs(UnmanagedType.U4)] int msg,
int wParam,
ref LVITEM lvItem); Of course, you'd need to declare a managed LVITEM struct (can be named whatever you like, though) that would marshal correctly.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thank you very much for your answer. Although I don't agree on your discussion, I'll use the code you gave me.
I tested calling BeginInvoke(Nada) a hundred thousand times and then GC.Collect(); The memory footprint after the collection was over a hundred megs. ??? And the reason I ask is that I do use BeginInvoke, but am not satisfied with it. And Invoke is no option since it causes deadlocks in my case. (The UI is updated from a background process.)
|
|
|
|