|
Hi Experts,
How to get the parent form name in custom control.
For ex: If the custom control is placed within tab control in mytest form, then my expected result in custom control shall be mytest.
I tried using following options available with custom control
1) this.parent.Findform() : returning null value (this works if the custom control is placed in form directly) fails if the custom control is placed in container i.e in tabcontrol,groupbox etc.
2) this.FindForm() : returning null value
3) this.Parent.Parent: not expected result
Note: In usercontrol there is option available as this.parentform which returns form name. same is not available in custom control
Appreciate to get help in this regard.
Regards
Kartheesh M
|
|
|
|
|
Control parent = Parent;
while(parent.Parent != null)
parent = parent.Parent;
Or
Application.OpenForms["formName"];
Or
ParentForm
|
|
|
|
|
Thanks Enis ur code worked
Control parent = this.Parent;
while (parent.Parent != null)
parent = parent.Parent;
Note:
1) when the page is loaded first parent returns the container.
2) When the control is edited then parent returns the form name, accordingly we need to code. For instance we can use the below code
if(this.FindForm !=null)
{
//code goes here
}
Anyways i got the expected result.
Thanks
Kartheesh
modified on Friday, July 9, 2010 5:04 AM
|
|
|
|
|
userControl1.TopLevelControl.Name
|
|
|
|
|
I think this may work for you:
if (this.FindForm() != null)
{
Form MyForm = this.FindForm();
string MyName = MyForm.Name;
MyForm.Dispose();
}
Alternatively, and I haven't tried this:
if (this.FindForm() != null)
{
string MyName = this.FindForm().Name;
}
The first works fine; the second builds okay, but I haven't tried executing it.
"A Journey of a Thousand Rest Stops Begins with a Single Movement"
|
|
|
|
|
Hi Guy,
I need to open exe through C#. I am able to open exe by writing code
System.Diagnostics.Process.Start("C:\Program Files\abc\xyz.exe");
but now I need to check if it is already open then no need to run this code because it will reopen.
basically need to check whether its open or not, open only if not open....
Thanks&Regards
Shafiq...
|
|
|
|
|
Hi,
check this[^]
Hope it helps
Bye
|
|
|
|
|
Try following code...
using System.Diagnostics;
public bool IsProcessOpen(string name)
{
foreach (Process clsProcess in Process.GetProcesses()) {
if (clsProcess.ProcessName.Contains(name))
{
return true;
}
}
return false;
}
Jinal Desai - LIVE
Experience is mother of sage....
|
|
|
|
|
Hey Jinal Desai
Where i need to give the path of my exe file which i need to open
and can check that particular process running or not instead of checking all running process on the computer.
|
|
|
|
|
You did not want to give path of your exe file, just give the name of it.
Jinal Desai - LIVE
Experience is mother of sage....
|
|
|
|
|
na.. Its not working for me.
|
|
|
|
|
The process name is case sensitive in some case, so
try with case sensitive and check in
"Window Task Manager" whether your exe is
running or not.
If running then give the name as shown in it.
HTH
Jinal Desai - LIVE
Experience is mother of sage....
|
|
|
|
|
Have a look at this snippet. Just change "notepad" (which I used here) to your process name (xyz?).
List<Process> pList = new List<Process>(Process.GetProcesses());
Process pSearch = pList.Find( delegate(Process p)
{ return p.ProcessName.ToLower() == "notepad";
} );
If pSerach is null Notepad is not running, otherwise you retrieve the Process object for Notepad.
[EDIT]
Nah, just look at Process.GetProcessesByName(string) . No need to make it more complicated than that I suppose..
|
|
|
|
|
Hi,
Kindly let me know, How may I remove character from string value?
Example:
string strValue = "AP.P.LE"; // "APPLE"
I want to remove dots only
Thank you
(Riaz)
|
|
|
|
|
strValue.Replace(".", string.Empty);
is one way.
"If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." Red Adair.
nils illegitimus carborundum
me, me, me
|
|
|
|
|
Try Replace method, and replace your dots (.) with string.Empty ("").
|
|
|
|
|
If someone has already answered why post exactly the same answer???
"If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." Red Adair.
nils illegitimus carborundum
me, me, me
|
|
|
|
|
Why write a rude reply to someone who also tries to help out just because the answer is almost the same?
Obviously I had not seen your reply when I wrote mine.. and really, what is your problem?
|
|
|
|
|
Calla wrote: Obviously I had not seen your reply when I wrote mine
You would say that, wouldn't you?
Calla wrote: and really, what is your problem?
You!
Okay, okay, sorry - bit pissed because it happen more than it used to: seems like people just trying to get rep points for no good reason.
"If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." Red Adair.
nils illegitimus carborundum
me, me, me
|
|
|
|
|
digital man wrote: You would say that, wouldn't you?
Like J4amieC wrote: They were 3 minutes apart dude...
digital man wrote: Okay, okay, sorry - bit pissed because it happen more than it used to: seems like people just trying to get rep points for no good reason.
Yes.. getting rep points is really what life is all about, isn't it?
|
|
|
|
|
Calla wrote:
Like J4amieC wrote: They were 3 minutes apart dude...
That's a lifetime.
Calla wrote: Yes.. getting rep points is really what life is all about, isn't it?
For me, no, for you... I think there are people here who see them as important though I can't see why.
"If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." Red Adair.
nils illegitimus carborundum
me, me, me
|
|
|
|
|
They were 3 minutes apart dude... I ofen have a page open for that sort of time without a refresh to see if other posts have been made.
Your comment would have been fine if there was 3 hrs, but 3 minutes... give a little grace.
|
|
|
|
|
I've occassionally done this when I've come to one of the forums, got distracted by a task (having possibly started an answer off), and not refreshed the browser. It has nothing to do with attempting to gain rep points (I don't really need to boost mine), and more to do with timing.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
I often take a long time writing a response, doing research to ensure my answer is correct, many people can post while I'm still writing.
|
|
|
|
|
Try something like string s=Regex.Replace(<input string>,"[^\\w\\.@-]",""); .
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
|
|
|
|