|
ok. here is the source:
Process openSource = new Process();<br />
openSource.StartInfo.FileName = @"C:\WINDOWS\system32\notepad.exe";<br />
openSource.StartInfo.Arguments = webBrowsing.DocumentText;<br />
openSource.StartInfo.UseShellExecute = true;<br />
openSource.Start();
when i click the button a window pops up saying what i said about the Win32Exception and it hightlights the "openSource.Start();" part of the code.
thanks for the info and help.
|
|
|
|
|
OK, I suggest you make your program show the value and some content of
webBrowsing.DocumentText right before you create the new Process(),
something like:
string fileSpec=webBrowsing.DocumentText;
log("fileSpec="+fileSpec);
try {
using (StreamReader sr=File.OpenText(fileSpec)) {
for (int i=0; i<3; i++) {
string s=sr.ReadLine();
log(s);
}
}
} catch (Exception exc) {
log(exc.Message);
throw;
}
Process openSource=...
in the above replace log() by whatever function can show you a string;
this could be Console.WriteLine()
this will tell us:
- whether the file spec is a valid windows file spec
- whether the file exists
- whether it is really readable
Good luck !
Luc Pattyn
|
|
|
|
|
I'm coming up against cases where the order of events - or even whether events ever fire - depends on whether my app is running "in debugger" (ie, F5 in Visual Studio), or running in it's release version.
So, some of my code needs to be aware of which environment I'm in. Does .NET / VS offer a nice structured way of doing this, or do I need to start messing with process names, etc?
Thanks!
|
|
|
|
|
the #if DEBUG precompiler statement will tell you?
On two occasions I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question. - Charles Babbage
|
|
|
|
|
Not quite, as far as I can tell, you get:
- no VSHOST when running under .NET 1.1
- no VSHOST when running under .NET 2.0 but outside Visual Studio 2005
- VSHOST when running under .NET 2.0 inside Visual Studio 2005, whether Debug or Release
So I would check the exe's fullname, available as the first string from
Environment.GetCommandLineArgs().
Luc Pattyn
|
|
|
|
|
Thanks, Luc. It seems sad that I have to do this. I thought the Project Properties, Build Page "Define DEBUG" checkbox would do the right thing, but apparently it does not...
|
|
|
|
|
Do I detect a little sarcasm, there?
Perhaps you could explain how to use it. It doesn't seem to get set automatically when under the VS host.
When I open the Project Properties dialog and click the "Define DEBUG" checkbox on the BUILD page, then DEBUG is defined as true for both RELEASE and when running under VS. But if I turn that checkbox off, then it's not defined in either.
A little help, perhaps?
|
|
|
|
|
I'm building application with multi document interface through use of standard tab control (so it's not MDI).
It's only for learning purpose anyway. I want to build kind of modern web browser so I use built in WebBrowser control.
Question is how to access certain controls in each tab through common interface on top of screen, basically to have same functionality like in FireFox when it comes to tabs (Commands apply only to selected tab and his controls, most of them anyway).
I had hard time (I'm still learning so this is probably trivial) to add controls to newly created tab. I figured I'll just add controls in same event but now I have problem once that is done how to access them since event repeat on each button click all controls have same name, only difference is they sit in different tab.
So how to access say WebBrowser Control in current tab... or do I need to do something difernet??
It's C# Express 2005 BTW...
|
|
|
|
|
TrooperIronMan wrote: So how to access say WebBrowser Control in current tab
MyTabControl.SelectedTab.Controls["MyControlName"].Text = "Blah Blah";
Same goes for any control in the currently selected tab. This is one way. Another is to make a custom TabPage with known controls collection, and instantiate this TabPage and add it to the TabControl each time the user opens a new Browsing tab.
Regards
|
|
|
|
|
OK 1st idea work nice with TextBox control, but it doesn't give me to use Navigate method of WebBrowser control at all.
I like second idea also, (sure it's better if it can be done in designer since I can set property much easier than in editor, but I would like some more help about practical realization.
Keep in mind I'm not very experienced with this, so sorry if some question look trivial
|
|
|
|
|
OK I figured out workaround for 1st method, for now (create new WebB. control then assign it control with right index)
But I still need explanation on other questions.
Thanks
|
|
|
|
|
If you need to access certain methods/properties of the control you can cast it:
((WebBrowser)MyTabControl.SelectedPage.Controls["MyControlName"]).Navigate("http://Google.com");
TrooperIronMan wrote: But I still need explanation on other questions.
What other question? Sorry if I missed them.
Regards
|
|
|
|
|
Question was how to instantiate some tab.
So I have one that is like template and I want all others to be copy "but with different data in their controls... so for example if there is WebBrowser each one will have different web page etc.
|
|
|
|
|
You'd have to create a UserControl project, inherit it from TabPage control, and put all the controls you'd want programatically. Sorry you can't use the designer to make that template TabPage.
Another way is to make the template TabPage as the first in the TabControl, but hidden. You can use this code snippet to copy your template page into a new one:
TabPage NewPage = new TabPage();
Control[] TempArray = new Control[MyTemplateTabPage.Controls.Count];
MyTemplateTabPage.Controls.CopyTo(TempArray, 0);
MyNewTabPage.Controls.AddRange(TempArray);
((WebBrowser)MyNewTabPage.Controls["MyBrowser"]).Navigate(SomeUrl);
I hope this helps.
Regards
|
|
|
|
|
Hi, i'm developing an app where i want to detect internet connection status.
I have a linked label on a statusbar (where i show if i'm connected or not). On the click event of the label, i have this code:
try
{
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.FileName = "cmd";
proc.StartInfo.Arguments = "rundll32.exe shell32.dll,Control_RunDLL ncpa.cpl,,0";
proc.Start();
//proc.WaitForExit();
}
catch { }
As you can tell, the idea is to show the Network Connections avaible on the target system.
I searched a while for it, and since C# doesn't support Shell, this is supossed to be the way.
I'm just getting the cmd "poped up". It doesn't call the arguments. When I copy/paste the arguments string on cmd, i get the Network Connections window opened, but cmd remains open as well.
Is there any other way to call the control panel applets in c#? If not, is there any way that to emulate the "Run..." from Start menu with c#?
Thanks for your time fellas.
daniel sovino
|
|
|
|
|
kiweed wrote: since C# doesn't support Shell
Ummm. Are you sure?
ProcessStartInfo NetworkConnections = new ProcessStartInfo("rundll32.exe", "shell32.dll,Control_RunDLL ncpa.cpl");
Process.Start(NetworkConnections);
Regards
|
|
|
|
|
simple as that.
thanx a lot
daniel
|
|
|
|
|
Hello People ,
I whan't to ask you something i wor on a pascal editor in c# , with Stream writers and readers.But when i whan't to compile it(.PAS to .EXE) (i save it like a document.pas) VS 2005 sais :
The system cannot find the file specified;
Can anybody help me?
Or show me the other idea to do that ?
Thanks ...
nemanja
|
|
|
|
|
How do you hope to make your C# editor compile PASCAL ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Pray
|
|
|
|
|
when creating a new project you get form1 which is your default main form...
so when you add a new form, and run your project and close form1 your application
terminates... this is because Form1 is MAIN FORM... is there anyway to change MAIN FORM to from2 since i no longer need form1!??
thank you...
It Is Not That I'm Different!
... I'm Only Making The Difference!
|
|
|
|
|
In your project you will have somewhere a method called static void Main (If you are running VS2005 it is in a class called Program which is automatically added to your project). This method runs the application and the form. You can alter this method to run a new form as the application's main form.
|
|
|
|
|
yes...
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
ok... so, what if i don't want Fom1 anymore!??
lets say that i want to dispose Form1 and make Form2 my main form...
if i close Form1 and Form2 is not the main form then the application will exit...
all, i want to do... is a password dialog...
if password dialog = correct login details then
destroy form1 and load form2 as main form...
It Is Not That I'm Different!
... I'm Only Making The Difference!
|
|
|
|
|
ferdna wrote: ok... so, what if i don't want Fom1 anymore!??
lets say that i want to dispose Form1 and make Form2 my main form...
if i close Form1 and Form2 is not the main form then the application will exit...
all, i want to do... is a password dialog...
if password dialog = correct login details then
destroy form1 and load form2 as main form...
Well, I would put the login form as a dialog that is opened when the main form is loaded. But I guess you could also do it this way:
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
LoginForm loginForm = new LoginForm();
Application.Run(loginForm);
if ()
{
MainForm mainForm = new MainForm();
Application.Run(mainForm);
}
}
|
|
|
|
|
this works... but... is the right way to do this!??
or is it a better way to do this!??
static void Main()<br />
{<br />
Application.EnableVisualStyles();<br />
Application.SetCompatibleTextRenderingDefault(false);<br />
<br />
Form1 form1 = new Form1();<br />
Application.Run(form1);<br />
<br />
Form2 form2 = new Form2();<br />
Application.Run(form2);<br />
}
It Is Not That I'm Different!
... I'm Only Making The Difference!
|
|
|
|