|
Yes, it is absolutely counter intuitive in today's strongly typed world, but sometime you need to address some irrational requirement.
Fakher Halim
|
|
|
|
|
Your method does NOT simulate default properties. It creates a new object and resets the handle, which could be disastrous from both a performance and stability standpoint. It's interesting nonetheless.
I agree with both Heath Stewart and Daniel Turini: the syntax is awful from an object-oriented perspective anyway, which is why they didn't build it in. This should be one of the times you just say "no", and you have the excellent support of not actually being able to provide the functionality!
Regards,
Jeff Varszegi
|
|
|
|
|
I agree.
It is just to illustrate how to create a new class instance out of a string. Of course it doesn't have code to add string into an existing instance, nor it has similarity to a VB6 control for that matter.
Sure it is a weird syntax -- shocking to any OO person, and that is exactly why I posted this so called VB6 compatibility possibility -- knowing the controversy.
Fakher Halim
|
|
|
|
|
I feel your pain, believe me. I have to admit that it is a fun little problem, one of those ones that always seems just out of grasp. I can't find any way to do it without some modification of the runtime.
Regards,
Jeff Varszegi
|
|
|
|
|
Hi,
I have a datagrid with 2 icon columns, I found when the screen needs to repaint, the 2 icon columns slow down the painting, it seems that loading icons is taking time, any idea about how to make loading of icons faster?
Thanks
|
|
|
|
|
For starters, if you're creating a Graphics instance yourself (probably not, but anyway...), make sure you dispose of it when finished or memory consumption will increase (call Graphics.Dispose() when finished). The same goes for the Icon . If you don't, it will take longer and longer because your memory consumption increases. Eventually you may exhaust the working memory alloc'd to your process.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi !
I will use similary method like Redim in c#
How can i do ???
dim toto(3) as string
redim preserve toto(4)
Thanks
|
|
|
|
|
C# has no redim aka VB. Take a look at the ArrayList class though.
|
|
|
|
|
Ok thanks a lot
|
|
|
|
|
Andrew's message is entirely correct: there is no Redim, and the ArrayList class addresses the problem by rendering things like Redim unnecessary. Here's how you can "redim preserve" an array in C#, if you choose not to use ArrayList or something like it:
<br />
string[] toto = new string[3];<br />
<br />
string[] newToto = new string[4];<br />
Array.Copy(toto, 0, newToto, 0, toto.Length);
toto = newToto;<br />
newToto = null;
ArrayList is nothing magic, just a wrapper around an array. The major differences between the above code snippet and the use of ArrayList is that ArrayList takes care of the array copying seamlessly for you, that ArrayList keeps track of how many items have been added to it (you have to keep this in an extra variable otherwise), and that every index access incurs the overhead of a method call. This method call overhead can significantly slow down code that heavily uses an ArrayList, which is why when I'm writing code for speed (which I do much, but not all, of the time) I prefer to just manage my own arrays.
A tip: if you know in advance roughly the number of items you might see, you can save yourself some ArrayList-internal array copying by setting the initial capacity in the constructor.
Regards,
Jeff Varszegi
|
|
|
|
|
Hi:
I want to Enable/disable the mouse and keyboard .
But I do not know which function that I can use.
Could you give me some addvices.
Thank you.
|
|
|
|
|
Are you talking about disabling the keyboard and mouse system wide or just in your app?
System wide, you could write a low level keyboard and mouse hooks or use Application.AddMessageFilter in your app. You'll be receiving every mouse and keyboard message before it is dispatched to its destination. When you get the keyboard or mouse message, it is up to you to either pass that message on to its destination or not do anything with it at all. Doing nothing will result in the message being dropped and essentially disabling the keyboard and/or mouse.
WARNING: Improperly writing code or writing poor performing code for these methods can result in serious performance degradation issues system wide.
What trigger do you plan to use to re-enable the keyboard and mouse?
RageInTheMachine9532
|
|
|
|
|
Or just unplug them!
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Why not just provide a delegate and event that can be registered when the second form is created, and hook in an event handler on the first form before you show the second form.
[EDIT] What happened to my thread, the forum must not have liked my response! [/EDIT]
- Nick Parker My Blog | My Articles
|
|
|
|
|
|
Heath Stewart wrote:
You could do that, but it seems like an aweful lot to do for something as simple as passing a reference to your ListView or just getting the database from the second form to put into your first, kind of like an InputBox of yesteryear.
Figures you wouldn't totally agree with something I said!
- Nick Parker My Blog | My Articles
|
|
|
|
|
That's not it at all.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
|
I'm trying what you said, but i don't know how to pass a reference to another form. Is there an article i can read, or can you give me quick example of how to do it. Sorry, i'm still a beginner with programming.
thxs for the advice you gave.
|
|
|
|
|
Why I personally perfer having the second form just return the data as a property or something, passing a reference to the first form isn't hard at all. Here's an example:
public class FirstForm : Form
{
private void btnSecondForm_Click(object sender, EventArgs e)
{
using (SecondForm form = new SecondForm(this))
{
form.ShowDialog(this);
}
}
internal ListView TheListView
{
get { return theListView; }
}
}
internal class SecondForm : Form
{
private FirstForm parent;
public SecondForm(FirstForm parent)
{
this.parent = parent;
}
private void btnOK_Click(object sender, EventArgs e)
{
ListView view = parent.TheListView;
if (view != null)
{
this.DialogResult = DialogResult.OK;
}
}
} As you can see, though, not SecondForm is tightly coupled with FirstForm , which is why simply having the SecondForm define a property which returns the input data would be better, because then you could use it anywhere when you need to query for such data.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi,
Can someone pls tell me, if its possible to change the permissions of a registrykey using C#.
Searching the web, all I found is to read/create/write... keys and values, but the often asked question to give a userthe right to read/execute is never answerd.
(to be more specific: I used aspnet_setreg.exe to create registrykeys. In my Web.config I use the identity-tag. The only way to give the ASPNET Machine Account the right to read the keys I found is using regedit / Context-Menü and add the account manually)
thx for replies
Sebastian
|
|
|
|
|
Yes, it is possible, but you must P/Invoke a lot of native APIs in order to do so. It's definitely not an easy task. If this isn't something you need to do often or automate, don't bother.
If you need to, see the RegSetKeySecurity API in the Platform SDK on MSDN[^]. There's also examples available that use this and related APIs. You'll need to P/Invoke all these methods, as well as declare all the structs and consts necessary to set security on registry keys.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thank you for the reply. I feared a solution like this, but now I know which way to go.
Sebastian
|
|
|
|
|
Hello,
I have a simple xml-file and i show it in a datagrid like this:
ds.ReadXml(@"c:\nodes.xml");
But one of the colums is true/false. So i would like a column with checkboxes in my datagrid. I found something about the DataGridBoolColumn but i can't make it work. Is it possible or is their another way?
thx in advance.
|
|
|
|
|
Why can't you make it work? Please be specific.
All you need to do is add it to your DataGrid<code> and bind it to your column by setting the <codE>MappingName as you would with a DataGridTextBoxColumn .
Microsoft MVP, Visual C#
My Articles
|
|
|
|