|
This would be an option if it was only one cd; but the program that I'm building is for cataloging several cd's and it is not so practical to hold down the shift key for several seconds every time i want to add a cd. Keep in mind also that not all of my users will be aware of this option so i prefere to "temporary" disable the autorun function while using the program
|
|
|
|
|
As the Microsoft Powertoy TweakUI allows you to disable the Autorun function of drives, I think this can be done by manipulating the registry.
Don't know a concrete key for this, but maybe you could get this info in some forum which deals with Windows and stuff like that
www.troschuetz.de
|
|
|
|
|
Thank you very much.
The problem is that if I do this with windows registry
I have to restart my computer and I would want to do
this without restarting the computer.
Have you other idea?
|
|
|
|
|
Uuh, you're right. Didn't considered that.
Maybe you can somehow simulate the holding of the Shift-Key, which Colin proposed, programmatically. It isn't quite elegant, but maybe it works.
www.troschuetz.de
|
|
|
|
|
|
There is a programmatic way, and many installers (including the Windows Installer runtime) will do this when prompting for CDs.
In order to do this, you must P/Invoke the RegisterWindowsMessage API to register a windows message that should be handled in your Forms override to the WndProc method. I would recommend defining a property to easily enable or disable autorun:
public class MyForm : Form
{
internal static uint QueryCancelAutoPlayMsg;
private bool enableAutoPlay = true;
public bool EnableAutoPlay
{
get { return enableAutoPlay ; }
set { enableAutoPlay = value; }
}
[DllImport("user32.dll", CharSet=CharSet.Auto)]
private static extern uint RegisterWindowMessage(string msg);
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
if (QueryCancelAutoPlayMsg == 0)
QueryCancelAutoPlayMsg = RegisterWindows=Message("QueryCancelAutoPlay");
if (m.Msg == QueryCancelAutoPlayMsg)
m.Result = new IntPtr((int)enableAutoPlay);
}
} Please note that this is only a sample. I recommend you read more about canceling autoplay on MSDN in Enabling and Disabling AutoPlay[^].
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thank you very much!!!! ))
You are super! You have always
a answer for a difficult question!
Thank you very much once again! ))
|
|
|
|
|
I am a moderately-skilled VB.NET guy who has (very) recently moved to C#. Where I seem to be having trouble is whenever I expect the same sort of forgiveness that VB seemed to give.
It seems that enums in C# are not as flexible as they were in VB. I am not sure if this true, but I am struggling where I did not expect to.
I have an enum that has int values. Basically, it is like this:
public enum Things<br />
{thing0 = 0, thing1 = 1, thing2 = 2}
... and so forth. What I can't do is this:
int numericThing = 1;<br />
Things aThing;<br />
aThing = numericThing;
This throws a CS0029 error about how it cannot implicitly convert type int to type Things.
What am I missing? I mean, if it doesn't work this way? What's the point?
I do not want to curl into the fetal position and crawl back to VB...
|
|
|
|
|
You need to cast it to Things:
Things aThing = (Things)numericThing;
|
|
|
|
|
Wingnut74 wrote:
What am I missing? I mean, if it doesn't work this way? What's the point?
I do not want to curl into the fetal position and crawl back to VB...
As mentioned, you need to cast it to int.
And, IMO, this is one of the C# strenghts over VB. Notice, VB allows you to do things that may cause hard to find runtime bugs, while C# will stop them at the moment you're compiling. This is called a "strongly-typed language".
notice this code:
int numericThing = 1;
Things aThing;
aThing = (Things)numericThing;
Now, it compiles, but does it work? Not always. What if numericThing has a value that is an invalid Thing? You should validate it before assigning.
And that's why the C# compiler stopped you.
Yes, even I am blogging now!
|
|
|
|
|
Daniel Turini wrote:
Now, it compiles, but does it work? Not always. What if numericThing has a value that is an invalid Thing? You should validate it before assigning.
And that's why the C# compiler stopped you.
Thanks to both of you. I figured it was something I was missing and was related to the way I have become used to VB's mommy-coddling.
I am still a bit out of my comfort zone, but I see the truth of what you are saying. I just have some re-learning ahead of me.
Thanks again.
|
|
|
|
|
My question is why are you even trying to assign an integer to an enum?
Whatever it is be aware of the very useful Enum.Parse For instance, in the case of persisting to fule it might be better to use the enum's name incase the enum's underlyng value was ever changed.
|
|
|
|
|
I need to create an object that takes its values from a database. The value of the enum is stored as an int, and I need to convert it back to the enum as I build the object.
|
|
|
|
|
Daniel Turini wrote:
What if numericThing has a value that is an invalid Thing? You should validate it before assigning.
Or let it be an undefined value
top secret xacc-ide 0.0.1
|
|
|
|
|
hi,
i got error when compile the code that implement generic in C#
like this : public class Stack<T>
i read msdn that C# support generic
but why i get compile error
how to solve this?
Thanks
|
|
|
|
|
C# doesn't support Generic, at least not yet. This feature will be included in the upoming C# 2.0 standard.
Take a look at this article from MSDN magazine for some more information about C# 2.0.
www.troschuetz.de
|
|
|
|
|
just realize it is for C# 2.0
thanks Stefan
|
|
|
|
|
Hi
I have a question, that how i can convert value of textbox(string) to integer in C# ?
i will be happy if you help me!
|
|
|
|
|
|
Convert.ToInt32(this.textBox1.Text);
i would explain a bit more but my wrist is broken.
/\ |_ E X E GG
|
|
|
|
|
Hi
It's better you learn the 'Parse' way:
int Number = Int32.Parse(textbox1.text)
Why? You can use to various types. e.g:
double Number = double.Parse(textbox1.text)
DateTime ADate = DateTime.Parse(textbox1.text)
Regards
|
|
|
|
|
I need same thing in Windows Forms programming as with ASP.NET Label (on Web it is much easier because Text property is just droped into html source). So is there something similar already around or should I think my own way to do this... ?
Any suggestions are also welcome...
|
|
|
|
|
And the string value for the Label.Text property in Windows Forms is dropped into the source code as well. Expand the "Windows Form Designer generated code" region and you'll see it. And if something doesn't appear in source code (like images in an ImageList or for any BackgroundImage properties, etc.), then it's most likely serialized to a ResX file. There's actually no hidden code like there was when designing forms in Visual Basic 6 and older.
But what does this have to do with "multi-styled lable" as you mentioned in your subject?
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
You didn't understood my question ...
ASP.NET Label.Text = "[b]Boldpart[/b]la[i]italic[/i]" gives (of course I know that it is < instead of [):
Boldpartlaitalic
Same manipulation can be done with fore color with is basicly what I need.
Now I was just wondering if there is a way to do that with "Windows Forms Label"... for example, \n will gives new line \t tab... is there something like that for color and bold/italic or should I go with developing my own Label that will have this?
|
|
|
|
|
pekica wrote:
You didn't understood my question
Actually, you really didn't explained what you want (which I mentioned in my first reply).
No, there is no style formatting specificiers and the Label wouldn't support them even if there was. It's a simple Static common control. Even extending it won't do much good because of that fact (it's limited to what the Static common control can do). You could always owner-draw your Label derivative, but that could be difficult.
Instead, you might consider just using a read-only, borderless RichTextBox . While RTF formatting isn't quite as simple as HTML formatting elements, it's not very hard and - if you wanted - you could always extend it to accept HTML format elements and transform them to RTF. Use the RichTextBox.Rtf property, though, not RichTextBox.Text .
Microsoft MVP, Visual C#
My Articles
|
|
|
|