|
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!
|
|
|
|
|
ferdna wrote: this works... but... is the right way to do this!??
or is it a better way to do this!??
Well, if form1 (and you really need to find better names than that. The readability and maintainability of code with class names like Form1 and Form2 is terrible.
Anyway, if form1 is your login form then why is there no condition to stop form2 from being loaded in the event that the login fails?
|
|
|
|
|
no need to... i just needed the logic...
i thank you so much for your time...
It Is Not That I'm Different!
... I'm Only Making The Difference!
|
|
|
|
|
Another method is to never show your "main form", but have all of your UI in secondary forms that you load and unload as you please. Have your UI forms notify your main form when they close, and when all UI forms close, have your main form close.
|
|
|
|
|
don't take me wrong or anything... but, i feel safer not creating my window until login has been clear... thats why i prefer the other method...
thanks!
It Is Not That I'm Different!
... I'm Only Making The Difference!
|
|
|
|
|
how to do this using .NET 3.0(WPF)!??
thanks!
It Is Not That I'm Different!
... I'm Only Making The Difference!
|
|
|
|
|
I don't know how to check that some registry key exists.
Exp:
RegistryKey key = Registry.CurrentUser.OpenSubKey("Software",true).CreateSubKey("Program");
key.SetValue("Key", "0");
So, if the key does not exists the program will fall.
How to fix this.
Vasildb
|
|
|
|
|
If the key doesn't exist the OpenSubKey method will return null . So assign the return value to a local variable, test whether it is a null reference and in case it's not call the CreateSubKey method on the local variable.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|