|
hom_rcp wrote: i need a file viewer can open images ,video ,audio ,pdf ... formats .
How can i find the source for it in C# or component only?
I'd recommend a site called Code Project. I hear that folks sometimes have examples on that site that you can download and look at the source. You should check there.
Definitely it isn't hard to view an image file - PictureBox will do that. Video and Audio can be viewed using the Quartz plugin or the MediaPlayer plugin. I suspect there is a PDF viewer too, though I haven't bothered looking for one.
Good Luck!
“You can't teach people to be lazy - either they have it, or they don't.”
-Dagwood Bumstead
|
|
|
|
|
I've written a Windows Form application and am trying to adapt it as a command line utility.
Target Behaviour:
1) When I run by double-clicking the exe it runs as a windows application.
2) When I open a command line and execute it without params it opens as a windows application.
3) When I open a command line and execute it with params it runs as a command line tool and outputs to the console.
What I'm seeing:
If I define the project as a Console Application then my form displays, but it also opens a console in the background. This is ugly.
If I define the project as a Windows Applicaiton then it accomplishes 1 and 2, but doesn't output to the console for 3.
Here's my entry point code:
static void Main(string[] args)
{
if (args.Length > 0)
{
CommandLine.Run(args);
}
else
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Main());
}
}
What am I missing here?
If I need to define the project as a Console Application how can I supress the console? (sounds hoaky, I know)
Thanks,
Shaun
|
|
|
|
|
I've done that. Start out as Console and use the FreeConsole API function when you want WinForms.
|
|
|
|
|
|
Thanks. I didn't see the link above, but you gave me a starting point.
I actually created it as a Windows Application cause I didn't like that console flashing before the form came up when running as a gui.
so I used
[DllImport("kernel32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool AttachConsole(int dwProcessId);
// then my entry code:
[STAThread]
static void Main(string[] args)
{
if (args.Length > 0)
{
// use -1 to attach to the parent
AttachConsole(-1);
CommandLine.Run(args);
}
else
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Main());
}
}
However. now my problem is that once my app executes the prompt does not show. It takes input and my app is not running in processes, but still, it's just ugly.
Oh, well. I appreciate the response and direction. Have a good one.
|
|
|
|
|
I am new to C# and I am looking at ways to write a IIS configuration dll.
Would like the dll to create a new website outside of the root. something that i can point the directory to a new location and then create virtual directories on the main level as well as creating them down in subfolders and then setting some features on the virtual directory along with settings to some of the folders say turning one into an application.
newsite - d:\mylocation - set basic auth - set permission to local logged in domain
folder1
folder2 - set as application
virtualdirectory1
virtualdirectory2
file2a
file2b - set security permisions to not anonymous
file2c
folder3
folder4
file - change error page 402 and permisions
I have all of these settings that I change when I setup this one site I know all the names and settings so they could be made hard coded except 6 things like the url, ip, port, root folder location for new site this will need to be passed into the program. Could someone point me in the right direction on this
|
|
|
|
|
use WMI - Windows Management Instrumentation
http://www.codeproject.com/csharp/wmi.asp
|
|
|
|
|
Hi there,
I have the following situation, which I've been handling through an event that returns a value. Apparently, this is bad coding practice!? If so, can someone tell me what I should be doing?
---
I have a class library. The user calls, say, GetMyPrivateInfo("password"). This private info may also be protected by a PIN. There are several other methods like GetMyPrivateInfo that may require a PIN for processing (but, they may not). It doesn't really make sense to ask for a PIN in the argument list of GetMyPrivateInfo and other such methods, especially since often a PIN might not be needed, if the user has decided not to protect certain data with a PIN (but instead just with a password).
Right now, I have a PinNeeded event handler, with return type int. If GetMyPrivateInfo determines that the info is in fact protected by a PIN, it will trigger PinNeeded and use the resulting integer PIN. If the PIN is not necessary, it won't trigger the event. And other methods in the class library can all use the PinNeeded event as well, when they need a PIN to get at certain data.
This works really well, because the user can log in to their account through my program, and the program doesn't know whether they have protected certain data with a PIN. So the program, which interfaces with the class library containing GetMyPrivateInfo, will subscribe to the library's PinNeeded event; the event handler will pop up a dialog box asking the user for his/her PIN, and if the user wants the program to remember the PIN for next time, then the event handler will in the future not pop up the dialog box but instead return the stored PIN. This is all in the program, not the class library. Now, the program calls GetMyPrivateInfo, because the user asked them to. The program still doesn't know if a PIN is needed, but the class library will find out, in the process of doing all the stuff in GetMyPrivateInfo. When GetMyPrivateInfo determines "I need a PIN to access this info," it calls the PinNeeded event handler, letting the program do its dialog-box/remembering thing, and uses the PIN to access the info and return it to the program.
Make sense? And it works really well.
---
But, I can see arguments that this actually isn't an "event," in some sense, but more of a request. But what's the correct coding paradigm for such a thing?
Thank you,
-Domenic Denicola- [CPUA 0x1337]
“I was born human. But this was an accident of fate—a condition merely of time and place. I believe it's something we have the power to change…”
|
|
|
|
|
An event handler should fire and pass values that are needed through the event, not as a return value. That's what event args are for. Or did I misunderstand ?
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Well, maybe. The event is made by the class library when it needs something from the end-user. So the process is:
class library (needs something)
<--accessed through--> program (can ask the user for something)
<-- interfaces with --> user (can supply something)
The question is, how do I handle that "something"? Right now I am making it a return value of the event. The event is part of the class library; the program has an event handler; and the event handler queries the user, and returns whatever the user inputted.
Are you saying that I should put the "return value" in the event args? So that the program's event handler gets the user's input, stuffs it in the event args, and then the class library reads out what the program put into the event args?
-Domenic Denicola- [CPUA 0x1337]
“I was born human. But this was an accident of fate—a condition merely of time and place. I believe it's something we have the power to change…”
|
|
|
|
|
Domenic wrote: Are you saying that I should put the "return value" in the event args? So that the program's event handler gets the user's input, stuffs it in the event args, and then the class library reads out what the program put into the event args?
Yes that it how it is normally done in events. Event should always have this signature: void Foo(object sender, YourEventArgs e); . A sample for your needed feedback ist for example the CancelEventArgs used in the framework. It has a Cancel property which can be set by receivers. If you don't want to stick to this pattern you should use a normal delegate instead.
Robert
|
|
|
|
|
Thank you! The CancelEventArgs example was very helpful; now I can feel that, although it seems natural to use a return value, in reality it's done another way, and I should stick to that.
-Domenic Denicola- [CPUA 0x1337]
“I was born human. But this was an accident of fate—a condition merely of time and place. I believe it's something we have the power to change…”
|
|
|
|
|
If you consider the return value natural, maybe you should consider changing the event to a single "settable" delegate. So instead of hooking up to the event you set a callback delegate. This way you can only have one hooked up - and hence a return value makes sense. I am not saying this is better than having a settable result property in the eventargs - just another way of doing it.
|
|
|
|
|
I'm not really sure how this effects the message pump, but I feel like getting user feedback within an event handler in general is a bad idea because it will (I think) halt message handling while you wait for the input. Why not process this on the actual thread that you are calling it from, with a public method called "GetPin()", which will check to see if the pin is already entered and return that if it exists, or return the new pin provided by the user through some UI.
Jeff
|
|
|
|
|
OK, but where should this method go? The class library is what actually needs to use the PIN; the program should be allowed to choose any mechanism for giving the library a PIN that it wants. Maybe the program generates random PINs ('cuz someone is using the library to be l33t hacker); maybe the program gets it from the user; maybe the program looks it up in a database. The class library doesn't care though, it just needs a PIN---how do I get the PIN from the program to the class library?
-Domenic Denicola- [CPUA 0x1337]
“I was born human. But this was an accident of fate—a condition merely of time and place. I believe it's something we have the power to change…”
|
|
|
|
|
Basically, you would implement an interface called IPinProvider, which the form would extend. Then, instead of having your mainform register to listen to the event from the Dll, have it send a reference to itself to the dll. Then the Dll can call the method directly. This will also increase security because a third-party application could not just register for the event from the Dll, and intercept the return value. If you wanted to, you could even check to make sure that the calling assembly is the Dll that you expect it to be from the MainForm class using the System.Reflection namespace.
public Interface IPinProvider {
int GetPin();
}
public class MainForm : Form, IPinProvider {
DllClass myDll = new DllClass();
...
public MainForm() {
myDll.ParentForm = this;
}
...
private int GetPin() {
...
}
}
public class DllClass {
private IPinProvider myPinProvider = null;
public IPinProvider ParentForm {
set { myPinProvider = value; }
}
private int GetPin() {
return (myPinProvider == null ? int.MinValue : myPinProvider.GetPin());
}
}
Hope this helps!
-Jeff
|
|
|
|
|
Hello all. Is it possible to have the property's getter public whereas the property's setter protected? Don't know, something like:
string Property
{
public get { return _property; }
protected set { _property = value; }
}
If possible, how can I do so?
Thanks in advance.
Hope is the negation of reality - Raistlin Majere
|
|
|
|
|
What happens when you try it?
The following will work nicely:
<code>public string Property
{
get { return _property; }
protected set { _property = value; }
}</code>
The early bird who catches the worm works for someone who comes in late and owns the worm farm. -- Travis McGee
|
|
|
|
|
Oh, I see. My code didn't compile whereas yours actually did. Thanks a lot!
Regards.
Hope is the negation of reality - Raistlin Majere
|
|
|
|
|
No problem
The one thing to remember is that the accessibility of the property must be greater than or equal to the accessibility of the most accessible getter or setter - that's probably the compile error you were getting.
Without an access modifier, properties by default are protected, but you were trying to make the getter public. Since the property itself was protected, a public getter isn't allowed.
The early bird who catches the worm works for someone who comes in late and owns the worm farm. -- Travis McGee
|
|
|
|
|
I had no idea you could do this, but have wanted this feature since I started using C#. Good find!
Jeff
|
|
|
|
|
Thanks
The early bird who catches the worm works for someone who comes in late and owns the worm farm. -- Travis McGee
|
|
|
|
|
This was introduced with .Net 2 and I love it.
Robert
|
|
|
|
|
I am getting an ArgumentNullException when I call ToolStripManager.LoadSettings(this) from a form on load event within the application. My scenario is as follows...
public class Panel1 : UserControl {
// This class contains a ToolStripContainer with a unique name, and some toolstrips
}
public class Form1 : Form {
private ToolStripContainer myToolStripContainer;
public Form1() {
Panel1 myPanel = new Panel1();
ToolStripContainer tsc = null;
// Get the ToolStripContainer from myPanel
foreach (Control c in myPanel.Controls) {
if (c is ToolStripContainer) {
tsc = (ToolStripContainer) c;
break;
}
}
// Sets up the default layout
if (tsc != null) {
/* Take all the ToolStrips from myPanel and add them to
* myToolStripContainer in a single row
*/
}
}
protected override void OnLoad(EventArgs e) {
base.OnLoad(e);
// Get the saved layout if it exists (throws unexpected exception)
ToolStripManager.LoadSettings(this);
}
protected override void OnFormClosing(FormClosingEventArgs e) {
base.OnFormClosing(e);
ToolStripManager.SaveSettings(this);
}
}
Does anyone have any idea as to how I can save and reload these settings? I have copied the exception below. Thanks,
ArgumentNullException
"value cannot be null"
at System.Windows.Forms.ToolStripItemCollection.CheckCanAddOrInsertItem(ToolStripItem value)
at System.Windows.Forms.ToolStripItemCollection.Insert(Int32 index, ToolStripItem value)
at System.Windows.Forms.ToolStripSettingsManager.ApplyToolStripSettings(ToolStrip toolStrip, SettingsStub settings, Dictionary`2 itemLocationHash)
at System.Windows.Forms.ToolStripSettingsManager.ApplySettings(ArrayList toolStripSettingsToApply)
at System.Windows.Forms.ToolStripSettingsManager.Load()
at System.Windows.Forms.ToolStripManager.LoadSettings(Form targetForm, String key)
at System.Windows.Forms.ToolStripManager.LoadSettings(Form targetForm)
at Form1_Load(Object sender, EventArgs e) in ...
Jeff
|
|
|
|
|
Try calling ToolStripManager.LoadSettings in the OnShown method instead. Without starting up Visual Studio and trying it out, I suspect that you are hitting a problem where this hasn't been initialised fully because of the sequence of events when loading the form.
Deja View - the feeling that you've seen this post before.
|
|
|
|